-
Notifications
You must be signed in to change notification settings - Fork 13
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
add sort by name to assigned page #459
Conversation
Co-authored-by: Vincent Shuali <[email protected]>
32b82ce
to
55e8c39
Compare
rebased on main to get around linting issue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just had a couple of comments, code wise.
For testing the front end functionality, did you somehow swap to a "para" role?
src/pages/benchmarks/index.tsx
Outdated
const [sortProperty, setSortProperty] = useState<SortProperty>("first_name"); | ||
const [sortDirection, setSortDirection] = useState<SortDirection>("asc"); | ||
|
||
const { data: tasksData, isLoading, error } = trpc.para.getMyTasks.useQuery(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "error" within data going to be accessed, or is this for troubleshooting of some sort?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove it for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good
src/pages/benchmarks/index.tsx
Outdated
if (!tasksData) return []; | ||
return [...tasksData].sort((a, b) => { | ||
if (a[sortProperty] < b[sortProperty]) | ||
return sortDirection === "asc" ? -1 : 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a bit of trouble following why you want to return 1 or -1. Could you please explain? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JavaScript decides whether two items in a sort are in the correct order relative to another depending on whether the sorting callback you give it returns +1 or -1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ty!
Yes, until we add admin functionality to impersonate users, we have to go into the database and flip our role to "para" |
src/pages/benchmarks/index.tsx
Outdated
const getSortedTasks = () => { | ||
if (!tasksData) return []; | ||
|
||
return [...tasksData].sort((a, b) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorting a copy of the array bypasses reactivity for tasksData, is this intentional?
src/pages/benchmarks/index.tsx
Outdated
} | ||
}; | ||
|
||
const displayedTasks = getSortedTasks(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe just sort and display tasksData? no need for displayedTasks?
This PR adds sorting functionality on the front end for the Assigned page. It does so by adding a new button (simple stand-in for current placeholder) that toggles between name ascending and descending sort. It partly addresses #424.
Note that each interaction currently forces a rerender, so we will want to revisit in future to improve perf (through either
useEffect()
and/or server-side sorting). This is good enough for POC, however.Also note that we will likely need to replace the button with a sorting dropdown to incorporate other sort properties.