Skip to content

Commit ec01660

Browse files
authored
Merge pull request #335 from CodeForPhilly/312-sort-order
312 sort order
2 parents 654a74b + 428333e commit ec01660

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/client/src/pages/DataView360/Search/Search.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
CircularProgress
1919
} from '@material-ui/core';
2020

21-
import _ from 'lodash';
21+
import _, { lowerCase } from 'lodash';
2222
import SearchBar from './components/SearchBar';
2323
import {formatPhoneNumber} from "../../../utils/utils";
2424
import Grid from "@material-ui/core/Grid";
@@ -104,14 +104,24 @@ class Search360 extends Component {
104104
})
105105
}
106106

107+
namesToLowerCase(participant) {
108+
let first_name = participant.first_name
109+
let last_name = participant.last_name
110+
111+
return {
112+
...participant,
113+
lower_first_name: lowerCase(first_name),
114+
lower_last_name: lowerCase(last_name)
115+
}
116+
}
117+
107118
renderParticipantsTable() {
108119
const {classes} = this.props;
109120
const tableRowColors = [classes.tableRowEven, classes.tableRowOdd]
110121

111-
let participantListGrouped = _.groupBy(this.state.participantList, "matching_id");
112-
participantListGrouped = _.reverse(_.sortBy(participantListGrouped, matching_group => {
113-
return _.size(matching_group);
114-
}));
122+
let participantListGrouped = _.map(this.state.participantList, this.namesToLowerCase)
123+
participantListGrouped = _.groupBy(participantListGrouped, "matching_id");
124+
participantListGrouped = _.orderBy(participantListGrouped, ['0.lower_last_name', '0.lower_first_name']);
115125

116126
return (
117127
<Grid container direction={"column"} justify={"center"}>

src/server/api/common_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ def get_contacts(search_text):
4848
if len(names) == 2:
4949
query = text("select * from pdp_contacts where archived_date is null AND ( \
5050
(lower(first_name) like lower(:name1) and lower(last_name) like lower(:name2)) \
51-
OR (lower(first_name) like lower(:name2) and lower(last_name) like lower(:name1)) )")
51+
OR (lower(first_name) like lower(:name2) and lower(last_name) like lower(:name1)) )\
52+
order by lower(last_name), lower(first_name)")
5253
query_result = connection.execute(query, name1='{}%'.format(names[0]), name2='{}%'.format(names[1]))
5354
elif len(names) == 1:
5455
query = text("select * from pdp_contacts \
5556
WHERE lower(first_name) like lower(:search_text) \
56-
OR lower(last_name) like lower(:search_text)")
57+
OR lower(last_name) like lower(:search_text) order by lower(last_name), lower(first_name)")
5758
query_result = connection.execute(query, search_text='{}%'.format(search_text))
5859

5960
query_result_json = [dict(row) for row in query_result]

0 commit comments

Comments
 (0)