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

add sort by name to assigned page #459

Merged
merged 6 commits into from
Nov 14, 2024
Merged

Conversation

nickvisut
Copy link
Contributor

@nickvisut nickvisut commented Oct 31, 2024

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.

Co-authored-by: Vincent Shuali <[email protected]>
@nickvisut nickvisut force-pushed the feature/add-sort-to-assigned branch from 32b82ce to 55e8c39 Compare November 1, 2024 23:31
@nickvisut
Copy link
Contributor Author

rebased on main to get around linting issue

@nickvisut nickvisut requested a review from a team November 2, 2024 00:57
Copy link
Contributor

@katconnors katconnors left a 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?

const [sortProperty, setSortProperty] = useState<SortProperty>("first_name");
const [sortDirection, setSortDirection] = useState<SortDirection>("asc");

const { data: tasksData, isLoading, error } = trpc.para.getMyTasks.useQuery();
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good

if (!tasksData) return [];
return [...tasksData].sort((a, b) => {
if (a[sortProperty] < b[sortProperty])
return sortDirection === "asc" ? -1 : 1;
Copy link
Contributor

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!

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

ty!

@canjalal canjalal linked an issue Nov 4, 2024 that may be closed by this pull request
3 tasks
@canjalal
Copy link
Contributor

canjalal commented Nov 5, 2024

Just had a couple of comments, code wise. For testing the front end functionality, did you somehow swap to a "para" role?

Yes, until we add admin functionality to impersonate users, we have to go into the database and flip our role to "para"

@canjalal canjalal removed a link to an issue Nov 5, 2024
3 tasks
@nickvisut nickvisut linked an issue Nov 6, 2024 that may be closed by this pull request
3 tasks
const getSortedTasks = () => {
if (!tasksData) return [];

return [...tasksData].sort((a, b) => {
Copy link
Contributor

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?

}
};

const displayedTasks = getSortedTasks();
Copy link
Contributor

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?

@francisli francisli merged commit 31057b2 into main Nov 14, 2024
3 checks passed
@francisli francisli deleted the feature/add-sort-to-assigned branch November 14, 2024 22:31
@francisli francisli restored the feature/add-sort-to-assigned branch November 14, 2024 22:53
@francisli francisli deleted the feature/add-sort-to-assigned branch January 24, 2025 00:31
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.

[Para] Assigned Page - Sort
5 participants