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

[Good First Front End Issue] Add sorting to the Team members table #52

Open
reecexlm opened this issue Nov 27, 2023 · 1 comment
Open
Labels
good first issue Good for newcomers

Comments

@reecexlm
Copy link
Collaborator

Add sorting to columns Email and Status using the following field IDs: email (string) and is_active (boolean).

Instructions

Update useUsers query (/apiQueries/useUsers.ts) to handle sorting.

URL Query Parameters:

  • sort string
    Possible values: [email, is_active]
    Default value: email
    Field used to sort users

  • direction string
    Possible values: [asc, desc]
    Default value: asc
    Direction for sorting users.

example: ?sort=email&direction=asc

Table component has built-in functionality to handle sorting. To enable that functionality, do the following:

  1. Use useSort hook (in /hooks/useSort) to get/set sortBy, sortDir, and handleSort by passing in the method that handles the sorting (update state parameter in TanStack Query in this case).
  2. Add the following to the Table.HeaderCell component:
    a. sortDirection property is used to set the sorting direction.
    b. onSort method triggers the sorting using handleSort method from the useSort hook (passing in the field ID to sort by).

Example:

// Keep track of sortBy field and direction in component state

const onSort = () => {
  // Set/reset sortBy field and direction
}

const { sortBy, sortDir, handleSort } = useSort(onSort);

<Table.HeaderCell
  sortDirection={sortBy === "name" ? sortDir : "default"}
  onSort={() => handleSort("name")}
>
  Column name
</Table.HeaderCell>

Working implementation in /components/DisbursementsTable.tsx.

Testing

If sorting is enabled on a table column, up and down arrows will be displayed next to the column name. Clicking once on the column will sort in ascending order (the up arrow will be highlighted). Clicking a second time on the same column will sort in descending order (the down arrow will be highlighted). Clicking the third time will clear the sorting. API call should be called every time the sorting field or order is changed, as all the sorting is done on the server. Frontend only displays the data.

Please make sure the sorting works as expected and try clicking different columns if sorting is enabled on multiple fields.

@Oyase-shinobi
Copy link

Hello team
did you fix this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants