UsersList.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (C) 2015 - present Instructure, Inc.
  3. *
  4. * This file is part of Canvas.
  5. *
  6. * Canvas is free software: you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License as published by the Free
  8. * Software Foundation, version 3 of the License.
  9. *
  10. * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. * details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. import preventDefault from 'compiled/fn/preventDefault'
  19. import IconMiniArrowUpSolid from 'instructure-icons/lib/Solid/IconMiniArrowUpSolid'
  20. import IconMiniArrowDownSolid from 'instructure-icons/lib/Solid/IconMiniArrowDownSolid'
  21. import Typography from 'instructure-ui/lib/components/Typography'
  22. import Tooltip from 'instructure-ui/lib/components/Tooltip'
  23. import Link from 'instructure-ui/lib/components/Link'
  24. import React from 'react'
  25. import PropTypes from 'prop-types'
  26. import I18n from 'i18n!account_course_user_search'
  27. import UsersListRow from './UsersListRow'
  28. const { string, object, func } = PropTypes
  29. export default class UsersList extends React.Component {
  30. static propTypes = {
  31. accountId: string.isRequired,
  32. users: PropTypes.arrayOf(object).isRequired,
  33. timezones: object.isRequired,
  34. permissions: object.isRequired,
  35. handlers: object.isRequired,
  36. userList: object.isRequired,
  37. onUpdateFilters: func.isRequired,
  38. onApplyFilters: func.isRequired,
  39. }
  40. updateOrder = (column) => {
  41. let newOrder = 'asc'
  42. const sort = this.props.userList.searchFilter.sort
  43. const order = this.props.userList.searchFilter.order
  44. if ((column === sort && order === 'asc') || (!sort && column === 'username')) {
  45. newOrder = 'desc'
  46. }
  47. this.props.onUpdateFilters({
  48. search_term: this.props.userList.searchFilter.search_term,
  49. sort: column,
  50. order: newOrder,
  51. role_filter_id: this.props.userList.searchFilter.role_filter_id
  52. })
  53. }
  54. renderHeader ({id, label, tipDesc, tipAsc}) {
  55. const {sort, order} = this.props.userList.searchFilter
  56. return (
  57. <Tooltip
  58. as={Link}
  59. tip={(sort === id && order === 'asc') ? tipAsc : tipDesc}
  60. onClick={preventDefault(() => this.updateOrder(id))}
  61. >
  62. {label}
  63. {sort === id ?
  64. (order === 'asc' ? <IconMiniArrowDownSolid /> : <IconMiniArrowUpSolid />) :
  65. ''
  66. }
  67. </Tooltip>
  68. )
  69. }
  70. render () {
  71. const { users, timezones, accountId } = this.props
  72. return (
  73. <div className="content-box" role="grid">
  74. <div role="row" className="grid-row border border-b pad-box-mini">
  75. <div role="columnheader" className="col-xs-3">
  76. {this.renderHeader({
  77. id: 'username',
  78. label: I18n.t('Name'),
  79. tipDesc: I18n.t('Click to sort by name ascending'),
  80. tipAsc: I18n.t('Click to sort by name descending')
  81. })}
  82. </div>
  83. <div role="columnheader" className="col-xs-3">
  84. {this.renderHeader({
  85. id: 'email',
  86. label: I18n.t('Email'),
  87. tipDesc: I18n.t('Click to sort by email ascending'),
  88. tipAsc: I18n.t('Click to sort by email descending')
  89. })}
  90. </div>
  91. <div role="columnheader" className="col-xs-1">
  92. {this.renderHeader({
  93. id: 'sis_id',
  94. label: I18n.t('SIS ID'),
  95. tipDesc: I18n.t('Click to sort by SIS ID ascending'),
  96. tipAsc: I18n.t('Click to sort by SIS ID descending')
  97. })}
  98. </div>
  99. <div role="columnheader" className="col-xs-2">
  100. {this.renderHeader({
  101. id: 'last_login',
  102. label: I18n.t('Last Login'),
  103. tipDesc: I18n.t('Click to sort by last login ascending'),
  104. tipAsc: I18n.t('Click to sort by last login descending')
  105. })}
  106. </div>
  107. <div role="columnheader" className="col-xs-2">
  108. <span className="screenreader-only">{I18n.t('User option links')}</span>
  109. </div>
  110. </div>
  111. <div className="users-list" role="rowgroup">
  112. {users.map(user =>
  113. <UsersListRow
  114. handlers={this.props.handlers}
  115. key={user.id}
  116. timezones={timezones}
  117. accountId={accountId}
  118. user={user}
  119. permissions={this.props.permissions}
  120. />
  121. )}
  122. </div>
  123. </div>
  124. )
  125. }
  126. }