Skip to content

Commit c1dfed9

Browse files
authored
Merge pull request #375 from CodeForPhilly/issue-256-new-screen-table
Support Overview
2 parents 6f7095f + da49dd1 commit c1dfed9

File tree

4 files changed

+132
-6
lines changed

4 files changed

+132
-6
lines changed

src/client/src/pages/DataView360/View/View360.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import moment from 'moment';
1717
import Adoptions from './components/Adoptions';
1818
import ContactInfo from './components/ContactInfo';
1919
import Donations from './components/Donations';
20+
// import AnimalInfo from './components/AnimalInfo';
21+
import SupportOverview from './components/SupportOverview';
2022
// import Fosters from './components/Fosters';
2123
import VolunteerActivity from './components/VolunteerActivity';
2224
import VolunteerHistory from './components/VolunteerHistory';
@@ -87,13 +89,17 @@ class View360 extends Component {
8789
return e["Type"] && e["Type"].toLowerCase().includes("foster");
8890
});
8991
}
92+
93+
let supportOverviewData = await fetch(`/api/person/${this.state.matchId}/support`);
94+
supportOverviewData = await supportOverviewData.json()
9095

9196
this.setState({
9297
participantData: {...response.result, "shelterluvShortId" : shelterluvShortId},
9398
animalData: animalInfo,
9499
adoptionEvents: adoptionEvents,
95100
fosterEvents: fosterEvents,
96-
isDataBusy: false
101+
isDataBusy: false,
102+
supportOverviewData: supportOverviewData
97103
});
98104

99105
}
@@ -148,6 +154,9 @@ class View360 extends Component {
148154
<ContactInfo
149155
participant={_.get(this.state, 'participantData.contact_details')}/>
150156
</Grid>
157+
<Grid item style={{"marginTop": "1em"}}>
158+
<SupportOverview data={_.get(this.state, 'supportOverviewData')}/>
159+
</Grid>
151160
<Grid item style={{"padding": "1em"}}>
152161
<Button style={{"minWidth": "180"}} elevation={2} variant="contained"
153162
color="primary"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class ContactInfo extends Component {
7676
</Typography>
7777
</Grid>
7878
</Grid>
79-
<Grid container item direction={'column'} alignItems="left">
79+
<Grid container item direction={'column'} alignItems="flex-start">
8080
<Grid container item direction="row" alignItems="center" spacing={1}>
8181
<Grid item>
8282
<HomeIcon color='primary' fontSize='small'/>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import React, { Component } from 'react';
2+
import { Box, Container, Divider, Paper, Typography } from '@material-ui/core';
3+
import { withStyles } from '@material-ui/core/styles';
4+
5+
import Grid from "@material-ui/core/Grid";
6+
7+
const customStyles = theme => ({
8+
spacingRows: {
9+
padding: 2
10+
},
11+
spaceIcon: {
12+
marginTop: 2
13+
}
14+
});
15+
16+
class SupportOverview extends Component {
17+
18+
createRowData(data) {
19+
const isDonor = data.first_donation_date || data.number_of_gifts > 0
20+
if (!isDonor) {
21+
return [{"title": "First Gift Date", "value": "N/A"}]
22+
}
23+
const rows = [
24+
{ "title": "First Gift Date", "value": data.first_donation_date },
25+
{ "title": "First Gift Amount", "value": `$${data.first_gift_amount}`},
26+
{ "title": "Lifetime Giving", "value": `$${data.total_giving}`},
27+
{ "title": "Total # of Gifts", "value": data.number_of_gifts},
28+
{ "title": "Largest Gift", "value": `$${data.largest_gift}`},
29+
{ "title": "Recurring Donor?", "value": data.is_recurring ? "Yes" : "No"},
30+
{ "title": "RFM Score", "value": data.rfm_score },
31+
{ "title": "RFM Category", "value": data.rfm_label,
32+
"rfm_color": data.rfm_color, "rfm_text_color": data.rfm_text_color }
33+
// { "title": "PAWS Legacy Society?", "value": "test" }
34+
]
35+
return rows;
36+
}
37+
38+
createRows(classes, data) {
39+
return data.map((row) => (
40+
<Grid container className={classes.spacingRows} direction={'row'} spacing={2} justify={'space-between'} key={row.title} >
41+
<Grid item>
42+
<Typography variant={'body2'} style={{ "fontWeight": "bold" }}>
43+
{row.title}
44+
</Typography>
45+
</Grid>
46+
<Grid item>
47+
{(row.rfm_color)
48+
? <Typography variant={'body2'} align={"right"} style={{ "background": row.rfm_color, "color": row.rfm_text_color }}>
49+
{row.value}
50+
</Typography>
51+
: <Typography variant={'body2'} align={"right"}>
52+
{row.value}
53+
</Typography>}
54+
</Grid>
55+
</Grid>
56+
));
57+
}
58+
59+
render() {
60+
const { classes, data } = this.props;
61+
const rows = this.createRowData(data);
62+
63+
return (
64+
<Paper elevation={2} style={{ padding: '1em' }}>
65+
<Container className={classes.containerInfo}>
66+
<Grid container direction={'column'}>
67+
<Grid container className={classes.spacingRows} direction={'row'} justify='center'>
68+
<Grid item>
69+
<Typography variant={'subtitle1'}>
70+
<b>Support Overview</b>
71+
</Typography>
72+
</Grid>
73+
</Grid>
74+
<Box pb={2}>
75+
<Divider />
76+
</Box>
77+
{this.createRows(classes, rows)}
78+
</Grid>
79+
</Container>
80+
81+
</Paper>
82+
);
83+
}
84+
}
85+
86+
export default withStyles(customStyles)(SupportOverview);

src/server/api/common_api.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,11 @@ def get_person_animal_events(matching_id, animal_id):
227227
def get_support_oview(matching_id):
228228
"""Return these values for the specified match_id:
229229
largest gift, date for first donation, total giving, number of gifts,
230-
amount of first gift, is recurring donor """
230+
amount of first gift, is recurring donor
231+
232+
If consuming this, check number_of_gifts first. If 0, there's no more data
233+
available, so don't try to read any other fields - they may not exist.
234+
"""
231235

232236
# One complication: a single match_id can map to multiple SF ids, so these queries need to
233237
# run on a list of of contact_ids.
@@ -251,7 +255,8 @@ def get_support_oview(matching_id):
251255
current_app.logger.warn("salesforcecontacts source_id " + row['source_id'] + "has non-alphanumeric characters; will not be used")
252256

253257
if len(id_list) == 0: # No ids to query
254-
return jsonify({})
258+
oview_fields['number_of_gifts'] = 0 # Marker for no support data
259+
return jsonify(oview_fields)
255260

256261

257262
sov1 = text("""SELECT
@@ -332,12 +337,38 @@ def get_support_oview(matching_id):
332337
if sov3_result.rowcount:
333338
oview_fields['is_recurring'] = sov3_result.fetchone()[0]
334339
else:
335-
oview_fields['is_recurring'] = False
340+
oview_fields['is_recurring'] = False
341+
342+
343+
rfm = text("""SELECT
344+
rfm_score, rfm_color, rfm_label, rfm_text_color
345+
FROM
346+
rfm_scores
347+
left join rfm_mapping on rfm_mapping.rfm_value = rfm_score
348+
WHERE
349+
matching_id = :match_id; """)
350+
351+
rfm = rfm.bindparams(match_id = matching_id)
352+
rfm_result = connection.execute(rfm)
353+
354+
if rfm_result.rowcount:
355+
row = rfm_result.fetchone()
356+
oview_fields['rfm_score'] = row[0]
357+
oview_fields['rfm_color'] = row[1]
358+
oview_fields['rfm_label'] = row[2]
359+
oview_fields['rfm_text_color'] = row[3]
360+
361+
else:
362+
oview_fields['rfm_score'] = ''
363+
oview_fields['rfm_color'] = ''
364+
oview_fields['rfm_label'] = ''
365+
oview_fields['rfm_text_color'] = ''
336366

337367

338368
return jsonify(oview_fields)
339369

340370

341371
else: # len(rows) == 0
342372
current_app.logger.debug('No SF contact IDs found for matching_id ' + str(matching_id))
343-
return jsonify({})
373+
oview_fields['number_of_gifts'] = 0 # Marker for no data
374+
return jsonify(oview_fields)

0 commit comments

Comments
 (0)