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

[FS-236]: Add Pagination To The Household List Table #128

Merged
merged 18 commits into from
Sep 19, 2023

Conversation

AmirabbasJ
Copy link
Member

This PR adds pagination to the household list table.

@vercel
Copy link

vercel bot commented Sep 7, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
the-charity ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 19, 2023 8:29am

@AmirabbasJ AmirabbasJ self-assigned this Sep 7, 2023
@stackblitz
Copy link

stackblitz bot commented Sep 7, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@linear
Copy link

linear bot commented Sep 7, 2023

FS-236 Add Pagination to the Household List Table

Family/List/NotEmpty - Web App (Figma)

<DataTable
        table={table}
        loading={loading}
        onNext={onNext}
        onPrev={onPrev}
        fallback={<Table.Skeleton cols={columns.length} rows={4} />}
        emptyState={
          <Table.Cell colSpan={columns.length} className="h-24 text-center">
            No results.
          </Table.Cell>
        }
/>
interface DataTableProps<T> {
  table: TableType<T>;
  fallback: JSX.Element;
  emptyState: JSX.Element;
  loading?: boolean;
  onNext?: VoidFunction;
  onPrev?: VoidFunction;
}

export const DataTable = <T,>({
  table,
  loading,
  emptyState,
  fallback,
  onNext,
  onPrev,
}: DataTableProps<T>) => {
  return (
    <>
      <Table>
        <Table.Header>
          {table.getHeaderGroups().map(headerGroup => (
            <Table.Row key={headerGroup.id}>
              {headerGroup.headers.map(header => {
                return (
                  <Table.Head
                    onClick={header.column.getToggleSortingHandler()}
                    isSortable={header.column.getCanSort()}
                    order={header.column.getIsSorted()}
                    key={header.id}
                  >
                    {header.isPlaceholder
                      ? null
                      : flexRender(
                          header.column.columnDef.header,
                          header.getContext(),
                        )}
                  </Table.Head>
                );
              })}
            </Table.Row>
          ))}
        </Table.Header>
        <Table.Body>
          {loading
            ? fallback
            : isEmpty(table.getRowModel().rows)
            ? emptyState
            : table.getRowModel().rows.map(row => (
                <Table.Row key={row.id}>
                  {row.getVisibleCells().map(cell => (
                    <Table.Cell key={cell.id}>
                      {flexRender(
                        cell.column.columnDef.cell,
                        cell.getContext(),
                      )}
                    </Table.Cell>
                  ))}
                </Table.Row>
              ))}
        </Table.Body>
      </Table>
      <Table.Pagination
        currentPage={table.getState().pagination.pageIndex + 1}
        pageCount={table.getPageCount()}
        canNextPage={table.getCanNextPage()}
        canPreviousPage={table.getCanPreviousPage()}
        onPrev={callAll(table.previousPage, onPrev)}
        onNext={callAll(table.nextPage, onNext)}
      />
    </>
  );
};
export const TablePagination = ({
  currentPage,
  pageCount,
  canNextPage,
  canPreviousPage,
  onPrev,
  onNext,
}: Props) => {
  return (
    <div
      role="navigation"
      aria-label="pagination navigation"
      className="flex items-center justify-end space-x-2 p-4"
    >
      <span>
        Page{' '}
        <strong aria-label="page">
          {currentPage} of {Math.max(pageCount, 1)}
        </strong>
      </span>
      <div className="space-x-2">
        <Button
          aria-label="go to previous page"
          variant="outline"
          size="sm"
          onClick={onPrev}
          disabled={!canPreviousPage}
        >
          Previous
        </Button>
        <Button
          aria-label="go to next page"
          variant="outline"
          size="sm"
          onClick={onNext}
          disabled={!canNextPage}
        >
          Next
        </Button>
      </div>
    </div>
  );
};

@erfan-goodarzi
Copy link
Member

What's the first commit?

@AmirabbasJ AmirabbasJ force-pushed the fs-236-add-pagination-to-the-household-list-table branch from dcb1426 to 7a936a1 Compare September 18, 2023 07:12
@AmirabbasJ AmirabbasJ temporarily deployed to Chromatic September 18, 2023 07:12 — with GitHub Actions Inactive
@AmirabbasJ AmirabbasJ temporarily deployed to Chromatic September 19, 2023 08:28 — with GitHub Actions Inactive
@ASafaeirad ASafaeirad merged commit c58110e into dev Sep 19, 2023
5 checks passed
@ASafaeirad ASafaeirad deleted the fs-236-add-pagination-to-the-household-list-table branch September 19, 2023 08:42
ASafaeirad added a commit that referenced this pull request Sep 19, 2023
This PR adds pagination to the household list table.

---------

Co-authored-by: Alireza Safaierad <frontendmonster@gmail.com>
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.

3 participants