Skip to content

Commit 10add95

Browse files
ATLAS-5036: [React UI] Pagination Issue: 'Go to Page' input resets and Incorrect page number Display with font & alignment inconsistencies
1 parent d11f415 commit 10add95

16 files changed

Lines changed: 534 additions & 327 deletions

File tree

dashboard/src/components/Table/TableLayout.tsx

Lines changed: 34 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import {
4343
} from "@tanstack/react-table";
4444
import { FC, useEffect, useMemo, useState } from "react";
4545
import TableFilter from "./TableFilters";
46-
import TablePagination from "./TablePagination";
4746
import ArrowUpwardOutlinedIcon from "@mui/icons-material/ArrowUpwardOutlined";
4847
import ArrowDownwardOutlinedIcon from "@mui/icons-material/ArrowDownwardOutlined";
4948
import SwapVertOutlinedIcon from "@mui/icons-material/SwapVertOutlined";
@@ -75,6 +74,7 @@ import AddOutlinedIcon from "@mui/icons-material/AddOutlined";
7574
import TableRowsLoader from "./TableLoader";
7675
import AddTag from "@views/Classification/AddTag";
7776
import FilterQuery from "@components/FilterQuery";
77+
import TablePagination from "./TablePagination";
7878

7979
interface IndeterminateCheckboxProps extends Omit<CheckboxProps, "ref"> {
8080
indeterminate?: boolean;
@@ -332,6 +332,7 @@ const TableLayout: FC<TableProps> = ({
332332
isFetching,
333333
defaultColumnVisibility,
334334
pageCount,
335+
totalCount,
335336
onClickRow,
336337
emptyText,
337338
defaultColumnParams,
@@ -352,18 +353,23 @@ const TableLayout: FC<TableProps> = ({
352353
showPagination,
353354
setUpdateTable,
354355
isfilterQuery,
355-
isClientSidePagination
356+
isClientSidePagination,
357+
isEmptyData,
358+
setIsEmptyData,
359+
showGoToPage
356360
}) => {
357361
let defaultHideColumns = { ...defaultColumnVisibility };
358362
const location = useLocation();
359363
const memoizedData = useMemo(() => data, [data]);
360364
const memoizedColumns = useMemo(() => columns, [columns]);
361365
const [searchParams] = useSearchParams();
362-
363366
const [pagination, setPagination] = useState<PaginationState>({
364367
pageIndex: 0,
365368
pageSize: 25
366369
});
370+
371+
const [goToPageVal, setGoToPageVal] = useState<any>("");
372+
367373
const [rowSelection, setRowSelection] = useState({});
368374
const [sorting, setSorting] = useState<SortingState>(
369375
!isEmpty(defaultSortCol) ? defaultSortCol : []
@@ -384,16 +390,11 @@ const TableLayout: FC<TableProps> = ({
384390
const {
385391
getHeaderGroups,
386392
getRowModel,
387-
firstPage,
388-
getCanPreviousPage,
389-
previousPage,
390-
nextPage,
391-
getCanNextPage,
392-
lastPage,
393393
setPageIndex,
394394
getPageCount,
395+
nextPage,
396+
previousPage,
395397
setPageSize,
396-
getRowCount,
397398
resetSorting,
398399
resetRowSelection,
399400
getIsAllRowsSelected,
@@ -414,7 +415,9 @@ const TableLayout: FC<TableProps> = ({
414415
onSortingChange: setSorting,
415416
onColumnOrderChange: setColumnOrder,
416417
getSortedRowModel: getSortedRowModel(),
417-
getPaginationRowModel: getPaginationRowModel(),
418+
getPaginationRowModel: isClientSidePagination
419+
? getPaginationRowModel()
420+
: undefined,
418421
onPaginationChange: setPagination,
419422
state: {
420423
columnVisibility: columnVisibilityParams
@@ -432,14 +435,17 @@ const TableLayout: FC<TableProps> = ({
432435
});
433436

434437
useEffect(() => {
435-
if (!isEmpty(fetchData)) {
436-
fetchData({ pagination, sorting });
438+
if (typeof fetchData === "function") {
439+
fetchData({
440+
pagination,
441+
sorting
442+
});
437443
}
438444
}, [
439445
fetchData,
440446
pagination.pageIndex,
441447
pagination.pageSize,
442-
!clientSideSorting && sorting
448+
clientSideSorting ? null : sorting
443449
]);
444450

445451
function handleDragEnd(event: DragEndEvent) {
@@ -459,30 +465,14 @@ const TableLayout: FC<TableProps> = ({
459465
useSensor(KeyboardSensor, {})
460466
);
461467

468+
const [, setSearchParams] = useSearchParams();
469+
462470
useEffect(() => {
463471
resetSorting(true);
464472
resetRowSelection(true);
465473
setRowSelection({});
466474
setSorting(!isEmpty(defaultSortCol) ? defaultSortCol : []);
467-
// setColumnVisibility(defaultHideColumns);
468-
}, [typeParam]);
469-
470-
// if (fetchData != undefined) {
471-
472-
// }
473-
474-
let currentPageOffset = searchParams.get("pageOffset") || 0;
475-
let isFirstPage = currentPageOffset == 0;
476-
477-
// const filteredParams = Array.from(searchParams.entries())
478-
// .filter(([key]) => ["type", "tag", "term"].includes(key))
479-
// .map(([key, value]) => ({
480-
// keyName:
481-
// key === "tag"
482-
// ? "Classification"
483-
// : key.charAt(0).toUpperCase() + key.slice(1),
484-
// value
485-
// }));
475+
}, [typeParam, defaultSortCol, setSearchParams]);
486476

487477
const handleCloseTagModal = () => {
488478
setTagModal(false);
@@ -669,31 +659,27 @@ const TableLayout: FC<TableProps> = ({
669659
</MuiTable>
670660
</DndContext>
671661
</TableContainer>
672-
{/* {noDataFound && (
673-
<Stack my={2} textAlign="center">
674-
{emptyText}
675-
</Stack>
676-
)} */}
677662

678663
{showPagination && (
679664
<TablePagination
680-
firstPage={firstPage}
681-
getCanPreviousPage={getCanPreviousPage}
682-
previousPage={previousPage}
683-
nextPage={nextPage}
684-
getCanNextPage={getCanNextPage}
685-
lastPage={lastPage}
665+
isServerSide={!isClientSidePagination}
686666
getPageCount={getPageCount}
687667
setPageIndex={setPageIndex}
688668
setPageSize={setPageSize}
669+
nextPage={nextPage}
670+
previousPage={previousPage}
689671
getRowModel={getRowModel}
690-
getRowCount={getRowCount}
691672
pagination={pagination}
692-
memoizedData={memoizedData}
693-
isFirstPage={isFirstPage}
694673
setRowSelection={setRowSelection}
695-
isClientSidePagination={isClientSidePagination}
674+
memoizedData={memoizedData}
675+
isFirstPage={pagination.pageIndex === 0}
696676
setPagination={setPagination}
677+
goToPageVal={goToPageVal}
678+
setGoToPageVal={setGoToPageVal}
679+
isEmptyData={isEmptyData}
680+
setIsEmptyData={setIsEmptyData}
681+
showGoToPage={showGoToPage}
682+
totalCount={totalCount}
697683
/>
698684
)}
699685
</Paper>

0 commit comments

Comments
 (0)