Skip to content

Commit

Permalink
Custom Filter Checkpoint 1
Browse files Browse the repository at this point in the history
  • Loading branch information
enrique-prado committed Oct 4, 2024
1 parent 6e14650 commit de28250
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 31 deletions.
21 changes: 17 additions & 4 deletions src/components/Table/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from "components";
import { Button } from "components/Button";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import type { Column, Row } from "react-table";
import type { Column, Row, TableInstance } from "react-table";
import { useDebouncedCallback } from "use-debounce";
import type { IconNamesType } from "utils";

Expand Down Expand Up @@ -863,22 +863,35 @@ export const CustomBasicTableFilterDrawer = () => {
const closeFilterDrawer = () => {
setOpenColumnsFilterDrawer(false);
};

const [filtersToApply, setFiltersToApply] = useState([]);

const handleApply = () => {
const theFilters = [
{ id: "name", value: "Williams" },
{ id: "other", value: "Lorem" },
];
setFiltersToApply(theFilters);
closeFilterDrawer();
};

return (
<>
<Table
columns={FilledFields.columns}
handleShowColumnsFilter={handleShowColumnsFilter}
allowToggleColumnVisibility
data={[...FilledFields.data]}
allFilters={filtersToApply}
/>
<TableFilterDrawer
title="Custom Table Filter Drawer"
open={openColumnsFilterDrawer}
handleCancel={closeFilterDrawer}
handleApply={handleApply}
>
<p>Custom content goes here</p>
<br />
<p> 'Cancel' and 'Apply' buttons are built-in</p>
<TextInput clearable label="Name" type="text" />
<TextInput clearable label="Goals" type="text" />
</TableFilterDrawer>
</>
);
Expand Down
7 changes: 7 additions & 0 deletions src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const Table = <T extends Record<string, any>>({
handleShowColumnsFilter,
handleRowToggled,
handlePageChange = () => null,
allFilters = [],
readonly = false,
rowHeight = "large",
selectableRows = "none",
Expand Down Expand Up @@ -202,8 +203,14 @@ export const Table = <T extends Record<string, any>>({
prepareRow,
pageCount,
toggleAllRowsSelected,
setAllFilters,
} = instance;

useEffect(() => {
console.log(allFilters);
setAllFilters(allFilters);
}, [allFilters, setAllFilters]);

const handleSearchWrapper = useMemo(() => {
if (handleSearch) {
return (searchString: string, pageSize: number) => {
Expand Down
55 changes: 28 additions & 27 deletions src/components/Table/types/TableTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,31 @@ export type RowHeight = "compact" | "medium" | "large";
export type SortType = "asc" | "desc" | "unsorted";

export type TableProps<T extends AnyRecord> = {
caption?: string;
id?: string;
manualPagination?: boolean;
manualRowCount?: number;
manualColumnFilters?: boolean;
manualSortBy?: boolean;
onManualSortBy?: (columnId: string, sortType: SortType) => void;
showPagination?: boolean;
pushPaginationDown?: boolean;
draggableRows?: boolean;
handlePageChange?: (pageIndex: number, pageSize: number) => void;
itemsPerPageOptions?: number[];
initialStatePageIndex?: number;
initialStatePageSize?: number;
defaultSelectedRowIds?: string[];
showRowSeparator?: boolean;
showRowSelectionHelper?: boolean;
summary?: string;
containerClassName?: string;
translations?: ITableTranslations;
} & ToolbarSharedProps<T> &
TableOptions<T> &
Pick<TableColumnFilterProps, "onApplyFilterValue" | "onCancelFilterValue"> &
Pick<TableBodyProps<T>, "handleRowToggled"> &
Partial<
Pick<IFilterContext, "allowToggleColumnVisibility" | "renderInsetTable">
>;
caption?: string;
id?: string;
manualPagination?: boolean;
manualRowCount?: number;
manualColumnFilters?: boolean;
manualSortBy?: boolean;
onManualSortBy?: (columnId: string, sortType: SortType) => void;
showPagination?: boolean;
pushPaginationDown?: boolean;
draggableRows?: boolean;
handlePageChange?: (pageIndex: number, pageSize: number) => void;
allFilters?: any[];
itemsPerPageOptions?: number[];
initialStatePageIndex?: number;
initialStatePageSize?: number;
defaultSelectedRowIds?: string[];
showRowSeparator?: boolean;
showRowSelectionHelper?: boolean;
summary?: string;
containerClassName?: string;
translations?: ITableTranslations;
} & ToolbarSharedProps<T> &
TableOptions<T> &
Pick<TableColumnFilterProps, "onApplyFilterValue" | "onCancelFilterValue"> &
Pick<TableBodyProps<T>, "handleRowToggled"> &
Partial<
Pick<IFilterContext, "allowToggleColumnVisibility" | "renderInsetTable">
>;

0 comments on commit de28250

Please sign in to comment.