Skip to content

Commit

Permalink
Merge pull request #333 from CodeForPhilly/327/360-view-enhancements
Browse files Browse the repository at this point in the history
Issue #327: VolunteerHistory and Donations show most recent 3
  • Loading branch information
c-simpson authored Jun 1, 2021
2 parents 53d9f90 + 53ea852 commit 5baf060
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/client/src/pages/DataView360/View/components/Donations.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const customStyles = theme => ({
}
});

const ROWS_TO_SHOW = 5
const ROWS_TO_SHOW = 3

class Donations extends Component {
constructor(props) {
Expand Down Expand Up @@ -57,7 +57,7 @@ class Donations extends Component {

render() {
const {classes} = this.props;

const headerText = `Financial Support Activity (Most Recent ${ROWS_TO_SHOW})`
return (
<Container component={Paper} style={{"marginTop": "1em"}}>
<Typography variant='h5'>
Expand All @@ -66,7 +66,7 @@ class Donations extends Component {
<AttachMoneyIcon color='primary' fontSize='inherit'/>
</Grid>
<Grid item>
Financial Support Activity (Top 5)
{headerText}
</Grid>
</Grid>
</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@ const customStyles = theme => ({
},
});

const SHIFTS_TO_SHOW = 5;
const SHIFTS_TO_SHOW = 3;

class VolunteerHistory extends Component {

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

const lastShifts = shiftsSorted.slice(shiftsSorted.length - SHIFTS_TO_SHOW, shiftsSorted.length)

const lastShifts = shiftsSorted.slice(0, SHIFTS_TO_SHOW)
const result = _.map(lastShifts, (shift, index) => {
shift.from = moment(shift.from).format("YYYY-MM-DD")
return(<TableRow key={index}>
<TableCell>{moment(shift.from).format("MM-DD-YYYY")}</TableCell>
<TableCell>{shift.from}</TableCell>
<TableCell>{shift.assignment}</TableCell>
</TableRow>);

Expand All @@ -53,7 +55,7 @@ class VolunteerHistory extends Component {
return (
<React.Fragment>
<Container component={Paper} style={{"marginTop": "1em"}}>
<DataTableHeader headerText={"Volunteer History (Top 5)"}
<DataTableHeader headerText={`Volunteer History (Most Recent ${SHIFTS_TO_SHOW})`}
emojiIcon={<TimelineIcon color='primary' fontSize='inherit'/>}
/>
<TableContainer component={Paper} style={{"marginBottom":"1em"}} variant='outlined'>
Expand Down
9 changes: 6 additions & 3 deletions src/server/api/common_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ def get_360(matching_id):
for r in volgistics_shifts_query_result:
shifts = dict(r)
# normalize date string
parsed_date_from = dateutil.parser.parse(shifts["from"], ignoretz=True)
normalized_date_from = parsed_date_from.strftime("%Y-%m-%d")
shifts["from"] = normalized_date_from
if shifts["from"]:
parsed_date_from = dateutil.parser.parse(shifts["from"], ignoretz=True)
normalized_date_from = parsed_date_from.strftime("%Y-%m-%d")
shifts["from"] = normalized_date_from
else:
shifts["from"] = "Invalid date"
volgisticsshifts_results.append(shifts)

result['shifts'] = volgisticsshifts_results
Expand Down

0 comments on commit 5baf060

Please sign in to comment.