Skip to content

Commit

Permalink
fix: ensure default sorting persists in overview table
Browse files Browse the repository at this point in the history
  • Loading branch information
atrincas authored and agnlez committed Jan 14, 2025
1 parent 4b68a25 commit d181f8e
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions client/src/containers/overview/table/view/overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
SortingState,
useReactTable,
TableState,
Updater,
} from "@tanstack/react-table";
import { useAtom } from "jotai";
import { ChevronsUpDownIcon } from "lucide-react";
Expand Down Expand Up @@ -62,17 +63,23 @@ export interface TableStateWithMaximums extends TableState {
};
}

const DEFAULT_SORTING: SortingState = [
{
id: "projectName",
desc: true,
},
];

export function OverviewTable() {
const [tableView] = useTableView();
const [filters] = useProjectOverviewFilters();
const [, setProjectDetails] = useAtom(projectDetailsAtom);
const [sorting, setSorting] = useState<SortingState>([
{
id: "projectName",
desc: true,
},
]);

const [sorting, setSorting] = useState<SortingState>(DEFAULT_SORTING);
const handleSortingChange = (updater: Updater<SortingState>) => {
const newSorting =
typeof updater === "function" ? updater(sorting) : updater;
setSorting(newSorting.length === 0 ? DEFAULT_SORTING : newSorting);
};
const [pagination, setPagination] = useState<PaginationState>({
pageIndex: 0,
pageSize: Number.parseInt(PAGINATION_SIZE_OPTIONS[0]),
Expand Down Expand Up @@ -149,7 +156,7 @@ export function OverviewTable() {
pagination,
maximums,
} as TableStateWithMaximums,
onSortingChange: setSorting,
onSortingChange: handleSortingChange,
onPaginationChange: setPagination,
});

Expand Down

0 comments on commit d181f8e

Please sign in to comment.