Skip to content

Commit

Permalink
add date column
Browse files Browse the repository at this point in the history
  • Loading branch information
ramirotw committed Apr 15, 2020
1 parent e908d6e commit 916a404
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/components/List/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,14 @@ export const VoterHistoryColumns = () => {
<Loading />
),
},
{
Header: 'Date',
id: 'date',
separator: true,
disableFilters: true,
sortType: 'datetime',
Cell: ({ row }) => format(fromUnixTime(row.original.lastParticipation.timestamp), 'dd MMM yy'),
width: 100,
},
]
}
21 changes: 13 additions & 8 deletions src/containers/VoterHistory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const getHomeVariables = data => {
}
}

const descendantTimestampSort = (a, b) => (a.timestamp > b.timestamp ? 1 : -1)

function VoterHistory(props: Props) {
const { match, history } = props
const voterId = match.params.id
Expand Down Expand Up @@ -102,17 +104,20 @@ function VoterHistory(props: Props) {
const getData = () => {
if (!historyData || !historyData.data) return
const executives = historyData.data.executives
.map(vote => {
const participation = vote.timeLine
.filter(tl => (tl.type === VOTING_ACTION_ADD || tl.type === VOTING_ACTION_LOCK) && tl.sender === voterId)
.sort(descendantTimestampSort)

.map(vote =>
vote.timeLine.filter(
tl => (tl.type === VOTING_ACTION_ADD || tl.type === VOTING_ACTION_LOCK) && tl.sender === voterId,
).length > 0
? { ...vote }
: undefined,
)
return participation.length > 0 ? { ...vote, lastParticipation: participation[0] } : undefined
})
.filter(Boolean)
const polls = historyData.data.polls
.map(poll => (poll.votes.filter(vote => vote.voter === voterId).length > 0 ? { ...poll } : undefined))
.map(poll => {
const participation = poll.votes.filter(vote => vote.voter === voterId).sort(descendantTimestampSort)

return participation.length > 0 ? { ...poll, lastParticipation: participation[0] } : undefined
})
.filter(Boolean)
setExecutives(executives)
setPolls(polls)
Expand Down

0 comments on commit 916a404

Please sign in to comment.