Skip to content

Commit

Permalink
Merge pull request #397 from protofire/sortable-date-column
Browse files Browse the repository at this point in the history
Make date column sortable in Voter History
  • Loading branch information
leolower authored Apr 28, 2020
2 parents 285b1ee + d15fc80 commit 37cfb6f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/components/List/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ export const VoterHistoryColumns = () => {
id: 'date',
separator: true,
disableFilters: true,
sortType: 'datetime',
accessor: 'lastParticipation.timestamp',
sortType: (a, b) => {
return a.original.lastParticipation.timestamp - b.original.lastParticipation.timestamp
},
Cell: ({ row }) => {
if (!row.original.lastParticipation) {
return <Loading />
Expand Down
3 changes: 2 additions & 1 deletion src/containers/VoterHistory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const getHomeVariables = data => {
}

const descendantTimestampSort = (a, b) => (a.timestamp > b.timestamp ? 1 : -1)
const defaultSort = [{ desc: true, id: 'date' }]

function VoterHistory(props: Props) {
const { match, history } = props
Expand Down Expand Up @@ -134,7 +135,7 @@ function VoterHistory(props: Props) {
return (
<>
<PageTitle>{`Voter History - ${voterId}`}</PageTitle>
<List handleRow={getItem} data={[...executives, ...polls]} columns={historyColumns} />
<List handleRow={getItem} data={[...executives, ...polls]} columns={historyColumns} sortBy={defaultSort} />
</>
)
}
Expand Down

0 comments on commit 37cfb6f

Please sign in to comment.