Merge pull request #419 from getmaxun/sort-rows

feat: sort robots and runs table
This commit is contained in:
Karishma Shukla
2025-01-30 17:10:33 +05:30
committed by GitHub
2 changed files with 56 additions and 23 deletions

View File

@@ -245,18 +245,6 @@ export const RunsTable: React.FC<RunsTableProps> = ({
return result;
}, [rows, searchTerm]);
// Group filtered rows by robot meta id
const groupedRows = useMemo(() =>
filteredRows.reduce((acc, row) => {
if (!acc[row.robotMetaId]) {
acc[row.robotMetaId] = [];
}
acc[row.robotMetaId].push(row);
return acc;
}, {} as Record<string, Data[]>),
[filteredRows]
);
const parseDateString = (dateStr: string): Date => {
try {
if (dateStr.includes('PM') || dateStr.includes('AM')) {
@@ -269,6 +257,35 @@ export const RunsTable: React.FC<RunsTableProps> = ({
}
};
const groupedRows = useMemo(() => {
const groupedData = filteredRows.reduce((acc, row) => {
if (!acc[row.robotMetaId]) {
acc[row.robotMetaId] = [];
}
acc[row.robotMetaId].push(row);
return acc;
}, {} as Record<string, Data[]>);
Object.keys(groupedData).forEach(robotId => {
groupedData[robotId].sort((a, b) =>
parseDateString(b.startedAt).getTime() - parseDateString(a.startedAt).getTime()
);
});
const robotEntries = Object.entries(groupedData).map(([robotId, runs]) => ({
robotId,
runs,
latestRunDate: parseDateString(runs[0].startedAt).getTime()
}));
robotEntries.sort((a, b) => b.latestRunDate - a.latestRunDate);
return robotEntries.reduce((acc, { robotId, runs }) => {
acc[robotId] = runs;
return acc;
}, {} as Record<string, Data[]>);
}, [filteredRows]);
const renderTableRows = useCallback((data: Data[], robotMetaId: string) => {
const { page, rowsPerPage } = getPaginationState(robotMetaId);
const start = page * rowsPerPage;