feat: add pagination for nested runs
This commit is contained in:
@@ -70,6 +70,13 @@ interface RunsTableProps {
|
|||||||
runningRecordingName: string;
|
runningRecordingName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface PaginationState {
|
||||||
|
[robotMetaId: string]: {
|
||||||
|
page: number;
|
||||||
|
rowsPerPage: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export const RunsTable: React.FC<RunsTableProps> = ({
|
export const RunsTable: React.FC<RunsTableProps> = ({
|
||||||
currentInterpretationLog,
|
currentInterpretationLog,
|
||||||
abortRunHandler,
|
abortRunHandler,
|
||||||
@@ -107,27 +114,55 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
[t]
|
[t]
|
||||||
);
|
);
|
||||||
|
|
||||||
const [page, setPage] = useState(0);
|
// const [page, setPage] = useState(0);
|
||||||
const [rowsPerPage, setRowsPerPage] = useState(10);
|
// const [rowsPerPage, setRowsPerPage] = useState(10);
|
||||||
const [rows, setRows] = useState<Data[]>([]);
|
const [rows, setRows] = useState<Data[]>([]);
|
||||||
const [searchTerm, setSearchTerm] = useState('');
|
const [searchTerm, setSearchTerm] = useState('');
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|
||||||
|
const [paginationStates, setPaginationStates] = useState<PaginationState>({});
|
||||||
|
|
||||||
const { notify, rerenderRuns, setRerenderRuns } = useGlobalInfoStore();
|
const { notify, rerenderRuns, setRerenderRuns } = useGlobalInfoStore();
|
||||||
|
|
||||||
const handleAccordionChange = useCallback((robotMetaId: string, isExpanded: boolean) => {
|
const handleAccordionChange = useCallback((robotMetaId: string, isExpanded: boolean) => {
|
||||||
navigate(isExpanded ? `/runs/${robotMetaId}` : '/runs');
|
navigate(isExpanded ? `/runs/${robotMetaId}` : '/runs');
|
||||||
}, [navigate]);
|
}, [navigate]);
|
||||||
|
|
||||||
const handleChangePage = useCallback((event: unknown, newPage: number) => {
|
const handleChangePage = useCallback((robotMetaId: string, newPage: number) => {
|
||||||
setPage(newPage);
|
setPaginationStates(prev => ({
|
||||||
|
...prev,
|
||||||
|
[robotMetaId]: {
|
||||||
|
...prev[robotMetaId],
|
||||||
|
page: newPage
|
||||||
|
}
|
||||||
|
}));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleChangeRowsPerPage = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChangeRowsPerPage = useCallback((robotMetaId: string, newRowsPerPage: number) => {
|
||||||
setRowsPerPage(+event.target.value);
|
setPaginationStates(prev => ({
|
||||||
setPage(0);
|
...prev,
|
||||||
|
[robotMetaId]: {
|
||||||
|
page: 0, // Reset to first page when changing rows per page
|
||||||
|
rowsPerPage: newRowsPerPage
|
||||||
|
}
|
||||||
|
}));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const getPaginationState = useCallback((robotMetaId: string) => {
|
||||||
|
const defaultState = { page: 0, rowsPerPage: 10 };
|
||||||
|
|
||||||
|
if (!paginationStates[robotMetaId]) {
|
||||||
|
setTimeout(() => {
|
||||||
|
setPaginationStates(prev => ({
|
||||||
|
...prev,
|
||||||
|
[robotMetaId]: defaultState
|
||||||
|
}));
|
||||||
|
}, 0);
|
||||||
|
return defaultState;
|
||||||
|
}
|
||||||
|
return paginationStates[robotMetaId];
|
||||||
|
}, [paginationStates]);
|
||||||
|
|
||||||
const debouncedSearch = useCallback((fn: Function, delay: number) => {
|
const debouncedSearch = useCallback((fn: Function, delay: number) => {
|
||||||
let timeoutId: NodeJS.Timeout;
|
let timeoutId: NodeJS.Timeout;
|
||||||
return (...args: any[]) => {
|
return (...args: any[]) => {
|
||||||
@@ -139,7 +174,13 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
const handleSearchChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleSearchChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const debouncedSetSearch = debouncedSearch((value: string) => {
|
const debouncedSetSearch = debouncedSearch((value: string) => {
|
||||||
setSearchTerm(value);
|
setSearchTerm(value);
|
||||||
setPage(0);
|
setPaginationStates(prev => {
|
||||||
|
const reset = Object.keys(prev).reduce((acc, robotId) => ({
|
||||||
|
...acc,
|
||||||
|
[robotId]: { ...prev[robotId], page: 0 }
|
||||||
|
}), {});
|
||||||
|
return reset;
|
||||||
|
});
|
||||||
}, 300);
|
}, 300);
|
||||||
debouncedSetSearch(event.target.value);
|
debouncedSetSearch(event.target.value);
|
||||||
}, [debouncedSearch]);
|
}, [debouncedSearch]);
|
||||||
@@ -219,6 +260,7 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const renderTableRows = useCallback((data: Data[], robotMetaId: string) => {
|
const renderTableRows = useCallback((data: Data[], robotMetaId: string) => {
|
||||||
|
const { page, rowsPerPage } = getPaginationState(robotMetaId);
|
||||||
const start = page * rowsPerPage;
|
const start = page * rowsPerPage;
|
||||||
const end = start + rowsPerPage;
|
const end = start + rowsPerPage;
|
||||||
|
|
||||||
@@ -251,7 +293,7 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
runningRecordingName={runningRecordingName}
|
runningRecordingName={runningRecordingName}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
}, [page, rowsPerPage, runId, runningRecordingName, currentInterpretationLog, abortRunHandler, handleDelete, accordionSortConfigs]);
|
}, [paginationStates, runId, runningRecordingName, currentInterpretationLog, abortRunHandler, handleDelete, accordionSortConfigs]);
|
||||||
|
|
||||||
const renderSortIcon = useCallback((column: Column, robotMetaId: string) => {
|
const renderSortIcon = useCallback((column: Column, robotMetaId: string) => {
|
||||||
const sortConfig = accordionSortConfigs[robotMetaId];
|
const sortConfig = accordionSortConfigs[robotMetaId];
|
||||||
@@ -369,20 +411,22 @@ export const RunsTable: React.FC<RunsTableProps> = ({
|
|||||||
{renderTableRows(data, robotMetaId)}
|
{renderTableRows(data, robotMetaId)}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
|
|
||||||
|
<TablePagination
|
||||||
|
component="div"
|
||||||
|
count={data.length}
|
||||||
|
rowsPerPage={getPaginationState(robotMetaId).rowsPerPage}
|
||||||
|
page={getPaginationState(robotMetaId).page}
|
||||||
|
onPageChange={(_, newPage) => handleChangePage(robotMetaId, newPage)}
|
||||||
|
onRowsPerPageChange={(event) =>
|
||||||
|
handleChangeRowsPerPage(robotMetaId, +event.target.value)
|
||||||
|
}
|
||||||
|
rowsPerPageOptions={[10, 25, 50, 100]}
|
||||||
|
/>
|
||||||
</AccordionDetails>
|
</AccordionDetails>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
))}
|
))}
|
||||||
</TableContainer>
|
</TableContainer>
|
||||||
|
|
||||||
<TablePagination
|
|
||||||
component="div"
|
|
||||||
count={filteredRows.length}
|
|
||||||
rowsPerPage={rowsPerPage}
|
|
||||||
page={page}
|
|
||||||
onPageChange={handleChangePage}
|
|
||||||
onRowsPerPageChange={handleChangeRowsPerPage}
|
|
||||||
rowsPerPageOptions={[10, 25, 50, 100]}
|
|
||||||
/>
|
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user