Skip to content

Commit

Permalink
Merge branch 'feature/paginated-table' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Feb 14, 2025
2 parents 2abc580 + 73695ec commit 03c52ac
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 14 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@ant-design/plots": "^1.0.9",
"@gisce/fiber-diagram": "2.1.1",
"@gisce/ooui": "2.29.0",
"@gisce/react-formiga-components": "1.10.0-alpha.4",
"@gisce/react-formiga-components": "1.10.0-alpha.5",
"@gisce/react-formiga-table": "1.10.0-alpha.4",
"@monaco-editor/react": "^4.4.5",
"@tabler/icons-react": "^2.11.0",
Expand Down
9 changes: 5 additions & 4 deletions src/widgets/views/Tree/Paginated/SearchTreePaginated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ function SearchTreePaginatedComp(props: SearchTreePaginatedProps, ref: any) {
currentPage,
limit,
order: actionViewSortState,
setOrder: setActionViewSortState,
setTreeFirstVisibleColumn,
onGetFirstVisibleColumn,
onSortChange,
} = usePaginatedSearch({
treeViewFetching: loading,
treeOoui,
Expand Down Expand Up @@ -187,6 +187,7 @@ function SearchTreePaginatedComp(props: SearchTreePaginatedProps, ref: any) {
[availableHeight, visible],
);

console.log({ currentPage });
// Render
return (
<Fragment>
Expand All @@ -204,8 +205,8 @@ function SearchTreePaginatedComp(props: SearchTreePaginatedProps, ref: any) {
<PaginationHeader
total={totalRows || 0}
totalRowsLoading={totalRowsLoading}
initialPage={currentPage || 1}
initialPageSize={limit || DEFAULT_PAGE_SIZE}
page={currentPage || 1}
pageSize={limit || DEFAULT_PAGE_SIZE}
currentPageSelectedCount={selectedRowKeys.length}
onRequestPageChange={onRequestPageChange}
totalSelectedCount={selectedRowKeys.length}
Expand Down Expand Up @@ -238,7 +239,7 @@ function SearchTreePaginatedComp(props: SearchTreePaginatedProps, ref: any) {
onHeaderCheckboxClick={onHeaderCheckboxClick}
refresh={refresh}
actionViewSortState={actionViewSortState}
setActionViewSortState={setActionViewSortState}
onSortChange={onSortChange}
tableRef={tableRef}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ export type PaginatedTableContentProps = {
onHeaderCheckboxClick: () => void;
refresh: () => void;
actionViewSortState: any;
setActionViewSortState: (state: any) => void;
onSortChange: (state: any) => void;
tableRef: RefObject<PaginatedTableRef>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const PaginatedTableComponent = memo(
onHeaderCheckboxClick,
refresh,
actionViewSortState,
setActionViewSortState,
onSortChange,
tableRef,
}: PaginatedTableContentProps) => {
if (!columns || !treeOoui) return null;
Expand Down Expand Up @@ -56,7 +56,7 @@ export const PaginatedTableComponent = memo(
onHeaderCheckboxClick={onHeaderCheckboxClick}
onForceReload={refresh}
initialSortState={actionViewSortState}
onSortChange={setActionViewSortState}
onSortChange={onSortChange}
/>
);
},
Expand Down
26 changes: 24 additions & 2 deletions src/widgets/views/Tree/Paginated/hooks/usePaginatedSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,18 @@ export const usePaginatedSearch = (props: PaginatedSearchProps) => {
const onRequestPageChange = useCallback(
(page: number, pageSize?: number) => {
setTreeFirstVisibleRow(0);
setTreeFirstVisibleColumn(undefined);
setSelectedRowItems([]);
setCurrentPage(page);
pageSize && setLimit(pageSize);
},
[setCurrentPage, setLimit, setSelectedRowItems, setTreeFirstVisibleRow],
[
setCurrentPage,
setLimit,
setSelectedRowItems,
setTreeFirstVisibleColumn,
setTreeFirstVisibleRow,
],
);

const getAllIds = useCallback(async () => {
Expand All @@ -462,7 +469,6 @@ export const usePaginatedSearch = (props: PaginatedSearchProps) => {
const selectAllRecords = useCallback(async () => {
const allIds = await getAllIds();
setSelectedRowItems?.(allIds.map((id: number) => ({ id })));
// onChangeSelectedRowKeys?.(allIds);
}, [getAllIds, setSelectedRowItems]);

const headerCheckboxState: CheckboxState = useMemo(() => {
Expand All @@ -484,6 +490,21 @@ export const usePaginatedSearch = (props: PaginatedSearchProps) => {
}
}, [tableRef, setSelectedRowItems, results, headerCheckboxState]);

const onSortChange = useCallback(
(state: any) => {
setActionViewOrder(state);
setTreeFirstVisibleRow(0);
setTreeFirstVisibleColumn(undefined);
setCurrentPage(1);
},
[
setActionViewOrder,
setCurrentPage,
setTreeFirstVisibleColumn,
setTreeFirstVisibleRow,
],
);

const onRowHasBeenSelected = useCallback(
({ id, selected }: { id: number; selected: boolean }) => {
setSelectedRowItems((prevItems) => {
Expand Down Expand Up @@ -532,5 +553,6 @@ export const usePaginatedSearch = (props: PaginatedSearchProps) => {
setOrder: setActionViewOrder,
setTreeFirstVisibleColumn,
onGetFirstVisibleColumn,
onSortChange,
};
};

0 comments on commit 03c52ac

Please sign in to comment.