Northeastern-Electric-Racing / PM-Dashboard-v2

Northeastern Electric Racing Project Management Dashboard - version 2
https://nerpm.netlify.app
GNU Affero General Public License v3.0
15 stars 2 forks source link

#729 timeline status home #740

Closed jamescd18 closed 2 years ago

jamescd18 commented 2 years ago

Changes

Expanded the existing work packages get all endpoint to support optional filtering by status and/or timeline status, not via Prisma implementation. Expanded get all work packages hook to support this filtering. Use this filtering to add a "Work Packages by Timeline Status" component to the home page which not only displays all "VERY_BEHIND" work packages by default, but also allows users to select to see work packages with a different timeline status. Uses the same horizontal scroll card format as the upcoming deadlines component.

Notes

Okay so this one was interestingly tough. I first filtered client-side until I realized that messes up the loading and isn't so proper, then considered a whole new endpoint, but decided not to. I experiment and researched and built out a flexible addition to the get all work packages endpoint that filters by status or timeline status or both. Considered doing a Prisma AND NOT implementation as suggested by their example, but decided that such an implementation would be way more lines of code and would probably only provide slight performance benefits and so I stuck with js .filter().

Then when trying to get the select dropdown to work properly, I discovered that setState() is async but doesn't provide a callback parameter like the React docs seem to indicate. Weird. Instead I had to use a useEffect with suppressing exhaustive dependencies to have the component re-fetch data and re-render consistently when the dropdown is changed. Seems strange that this is what's required for that to work but I guess the optimizations avoid re-render so this is what's needed.

I kinda randomly decided to remove duplication by switching the get single work package endpoint to use findFirst instead of findUnique, allowing us to search via the work package model instead of the wbsElement model while achieving the exact same results.

Not for this PR but considering also doing:

Test Cases

pretty basic, just tried to maintain test coverage.

Screenshots (if applicable)

Screen Shot 2022-06-19 at 12 56 40 AM Screen Shot 2022-06-19 at 12 57 09 AM

Checklist

It can be helpful to check the Checks and Files changed tabs. Please review the contributor guide and reach out to your squad if anything is unclear. Please request reviewers and ping on slack only after you've gone through this whole checklist.

Closes #729