Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Full grants table #52

Merged
merged 8 commits into from
Mar 30, 2021
Merged

[WIP] Full grants table #52

merged 8 commits into from
Mar 30, 2021

Conversation

jessicamcinchak
Copy link
Member

@jessicamcinchak jessicamcinchak commented Mar 21, 2021

Fetching all grantsFunded and grantsReceived for an Organization so we render accurate totals in the yearly bar charts and show all grants in the table.

Main updates:

  • Defined cache & default pagination methods for ApolloClient
  • Moved grantsFunded & grantsReceived query to its own container GrantsTableWrapper. Even though fetchMore can execute it's own query, I'm figuring a separate container gives us a much nicer loading experience for orgs with a lot of grants (see CFSEM for example)

Minor styling tweaks:

  • Yearly sum bar charts have a bit more space and are money-green
  • Long grant descriptions are clipped off so they roughly stay on one line in the GrantTable

Future improvements outlined here #55


if (!data.organization) return `Failed to load org data!`;

if (data.organization.grantsFunded.length < props.countGrantsFrom || data.organization.grantsReceived.length < props.countGrantsTo) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this get a short comment explaining what it's for? Or breaking the conditionals out into variables could serve the same function, something like:

const moreGrantsFundedToLoad = data.organization.grantsFunded.length < props.countGrantsFrom
const moreGrantsReceivedToLoad = data.organization.grantsReceived.length < props.countGrantsTo

if (moreGrantsFundedToLoad || moreGrantsReceivedToLoad) { 
  ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, good call - updated 👍

and ${data.organization.grantsReceived.length}/${props.countGrantsTo} grants received.`
);

const {
Copy link
Member

@hampelm hampelm Mar 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving this block up around line 55 could shorten some of the code above, if I'm reading it correctly

Copy link
Member Author

@jessicamcinchak jessicamcinchak Mar 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah so this is a bit tricky -- we need the orginal length of the grantsFunded/grantsReceived response pre-cleanse in order to properly set offset. Because the cleanse will create and insert the "org header rows" directly into the array, we'd be trying to fetch something like 182/171 possible grants if this is defined upfront.

Maybe a phase 2 refactor though, would be nice to have shorter variable names here.


const cleanse = (organization) => {
// Sort lists by org
const flattenedGrantsReceived = sortBy(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a total personal preference, but I would advocate splitting this into two steps for clarity. First the map to generate the list, then a second step for the sortBy.

The reason I suggest that is the sortBy call is ~20 lines away from the sort logic, so I was originally confused as to what was happening here. I thought it was super complicated sort logic! Then I realized it's lodash and not Array.prototype.sort()

const allYears = Object.keys({
...fundedYearlySums,
...receivedYearlySums,
}).reduce((acc, cur) => ({ ...acc, [cur]: 0 }), {});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this get longer variable names?

);
};

const cleanse = (organization) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this get a short comment about its role?

@hampelm hampelm merged commit bc8c10f into master Mar 30, 2021
@hampelm hampelm deleted the jm-grants-table branch March 30, 2021 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants