Skip to content

Commit

Permalink
Merge pull request metabase#7574 from metabase/sort-users-list
Browse files Browse the repository at this point in the history
Sort the /admin/people list by last_name & first_name
  • Loading branch information
salsakran authored May 9, 2018
2 parents c488057 + 92e7974 commit 36bf50e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import { Link } from "react-router";
import _ from "underscore";
import { connect } from "react-redux";

import LoadingAndErrorWrapper from "metabase/components/LoadingAndErrorWrapper.jsx";
Expand Down Expand Up @@ -30,7 +29,7 @@ export const MODAL_RESET_PASSWORD_EMAIL = "MODAL_RESET_PASSWORD_EMAIL";
export const MODAL_USER_ADDED_WITH_INVITE = "MODAL_USER_ADDED_WITH_INVITE";
export const MODAL_USER_ADDED_WITH_PASSWORD = "MODAL_USER_ADDED_WITH_PASSWORD";

import { getUsers, getModal, getGroups } from "../selectors";
import { getSortedUsers, getModal, getGroups } from "../selectors";
import {
createUser,
deleteUser,
Expand All @@ -48,7 +47,7 @@ import {

const mapStateToProps = (state, props) => {
return {
users: getUsers(state, props),
users: getSortedUsers(state, props),
modal: getModal(state, props),
user: state.currentUser,
groups: getGroups(state, props),
Expand Down Expand Up @@ -402,8 +401,6 @@ export default class PeopleListingApp extends Component {
let { modal, users, groups } = this.props;
let { error } = this.state;

users = _.values(users).sort((a, b) => b.date_joined - a.date_joined);

return (
<LoadingAndErrorWrapper loading={!users} error={error}>
{() => (
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/metabase/admin/people/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,19 @@ export const getUsers = createSelector(
.value(),
})),
);

// sort the users list by last_name, ignore case or diacritical marks. If last names are the same then compare by first
// name
const compareNames = (a, b) =>
a.localeCompare(b, undefined, { sensitivty: "base" });

export const getSortedUsers = createSelector(
[getUsers],
users =>
users &&
_.values(users).sort(
(a, b) =>
compareNames(a.last_name, b.last_name) ||
compareNames(a.first_name, b.first_name),
),
);
4 changes: 3 additions & 1 deletion src/metabase/api/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"Fetch a list of all active `Users` for the admin People page."
[]
(db/select [User :id :first_name :last_name :email :is_superuser :google_auth :ldap_auth :last_login]
:is_active true))
:is_active true
{:order-by [[:%lower.last_name :asc]
[:%lower.first_name :asc]]}))

(defn- reactivate-user! [existing-user first-name last-name]
(when-not (:is_active existing-user)
Expand Down

0 comments on commit 36bf50e

Please sign in to comment.