Skip to content

Commit 5baf060

Browse files
authored
Merge pull request #333 from CodeForPhilly/327/360-view-enhancements
Issue #327: VolunteerHistory and Donations show most recent 3
2 parents 53d9f90 + 53ea852 commit 5baf060

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

src/client/src/pages/DataView360/View/components/Donations.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const customStyles = theme => ({
2626
}
2727
});
2828

29-
const ROWS_TO_SHOW = 5
29+
const ROWS_TO_SHOW = 3
3030

3131
class Donations extends Component {
3232
constructor(props) {
@@ -57,7 +57,7 @@ class Donations extends Component {
5757

5858
render() {
5959
const {classes} = this.props;
60-
60+
const headerText = `Financial Support Activity (Most Recent ${ROWS_TO_SHOW})`
6161
return (
6262
<Container component={Paper} style={{"marginTop": "1em"}}>
6363
<Typography variant='h5'>
@@ -66,7 +66,7 @@ class Donations extends Component {
6666
<AttachMoneyIcon color='primary' fontSize='inherit'/>
6767
</Grid>
6868
<Grid item>
69-
Financial Support Activity (Top 5)
69+
{headerText}
7070
</Grid>
7171
</Grid>
7272
</Typography>

src/client/src/pages/DataView360/View/components/VolunteerHistory.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,22 @@ const customStyles = theme => ({
2525
},
2626
});
2727

28-
const SHIFTS_TO_SHOW = 5;
28+
const SHIFTS_TO_SHOW = 3;
2929

3030
class VolunteerHistory extends Component {
3131

3232
createShiftRows(shifts) {
33-
const shiftsSorted = _.sortBy(shifts, shift => {
34-
return new moment(shift.from);
33+
const shiftsFiltered = _.filter(shifts, function(s) { return s.from !== "Invalid date"});
34+
const shiftsSorted = _.sortBy(shiftsFiltered, shift => {
35+
return new moment(shift.from).format("YYYY-MM-DD");
3536
}).reverse();
3637

37-
const lastShifts = shiftsSorted.slice(shiftsSorted.length - SHIFTS_TO_SHOW, shiftsSorted.length)
38-
38+
const lastShifts = shiftsSorted.slice(0, SHIFTS_TO_SHOW)
39+
3940
const result = _.map(lastShifts, (shift, index) => {
41+
shift.from = moment(shift.from).format("YYYY-MM-DD")
4042
return(<TableRow key={index}>
41-
<TableCell>{moment(shift.from).format("MM-DD-YYYY")}</TableCell>
43+
<TableCell>{shift.from}</TableCell>
4244
<TableCell>{shift.assignment}</TableCell>
4345
</TableRow>);
4446

@@ -53,7 +55,7 @@ class VolunteerHistory extends Component {
5355
return (
5456
<React.Fragment>
5557
<Container component={Paper} style={{"marginTop": "1em"}}>
56-
<DataTableHeader headerText={"Volunteer History (Top 5)"}
58+
<DataTableHeader headerText={`Volunteer History (Most Recent ${SHIFTS_TO_SHOW})`}
5759
emojiIcon={<TimelineIcon color='primary' fontSize='inherit'/>}
5860
/>
5961
<TableContainer component={Paper} style={{"marginBottom":"1em"}} variant='outlined'>

src/server/api/common_api.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@ def get_360(matching_id):
9292
for r in volgistics_shifts_query_result:
9393
shifts = dict(r)
9494
# normalize date string
95-
parsed_date_from = dateutil.parser.parse(shifts["from"], ignoretz=True)
96-
normalized_date_from = parsed_date_from.strftime("%Y-%m-%d")
97-
shifts["from"] = normalized_date_from
95+
if shifts["from"]:
96+
parsed_date_from = dateutil.parser.parse(shifts["from"], ignoretz=True)
97+
normalized_date_from = parsed_date_from.strftime("%Y-%m-%d")
98+
shifts["from"] = normalized_date_from
99+
else:
100+
shifts["from"] = "Invalid date"
98101
volgisticsshifts_results.append(shifts)
99102

100103
result['shifts'] = volgisticsshifts_results

0 commit comments

Comments
 (0)