From 26953a4e1eb92539af7c795d37779d01a572f573 Mon Sep 17 00:00:00 2001 From: Rohit Date: Thu, 30 Jan 2025 11:25:27 +0530 Subject: [PATCH 1/2] feat: sort robot table in desc order of creation --- src/components/robot/RecordingsTable.tsx | 38 +++++++++++++++++------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/components/robot/RecordingsTable.tsx b/src/components/robot/RecordingsTable.tsx index 484b1667..8b4143a2 100644 --- a/src/components/robot/RecordingsTable.tsx +++ b/src/components/robot/RecordingsTable.tsx @@ -189,23 +189,39 @@ export const RecordingsTable = ({ setPage(0); }, []); + const parseDateString = (dateStr: string): Date => { + try { + if (dateStr.includes('PM') || dateStr.includes('AM')) { + return new Date(dateStr); + } + + return new Date(dateStr.replace(/(\d+)\/(\d+)\//, '$2/$1/')) + } catch { + return new Date(0); + } + }; + const fetchRecordings = useCallback(async () => { setIsLoading(true); try { const recordings = await getStoredRecordings(); if (recordings) { const parsedRows = recordings - .map((recording: any, index: number) => { - if (recording?.recording_meta) { - return { - id: index, - ...recording.recording_meta, - content: recording.recording - }; - } - return null; - }) - .filter(Boolean); + .map((recording: any, index: number) => { + if (recording?.recording_meta) { + const parsedDate = parseDateString(recording.recording_meta.createdAt); + + return { + id: index, + ...recording.recording_meta, + content: recording.recording, + parsedDate + }; + } + return null; + }) + .filter(Boolean) + .sort((a, b) => b.parsedDate.getTime() - a.parsedDate.getTime()); setRecordings(parsedRows.map((recording) => recording.name)); setRows(parsedRows); From 752a2d12d879cc0bb5df0f80d31c13792435b0f3 Mon Sep 17 00:00:00 2001 From: Rohit Date: Thu, 30 Jan 2025 11:52:12 +0530 Subject: [PATCH 2/2] feat: sort rows based on latest run --- src/components/run/RunsTable.tsx | 41 ++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/src/components/run/RunsTable.tsx b/src/components/run/RunsTable.tsx index 92233214..563fd55c 100644 --- a/src/components/run/RunsTable.tsx +++ b/src/components/run/RunsTable.tsx @@ -194,18 +194,6 @@ export const RunsTable: React.FC = ({ 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), - [filteredRows] - ); - const parseDateString = (dateStr: string): Date => { try { if (dateStr.includes('PM') || dateStr.includes('AM')) { @@ -218,6 +206,35 @@ export const RunsTable: React.FC = ({ } }; + 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); + + 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); + }, [filteredRows]); + const renderTableRows = useCallback((data: Data[], robotMetaId: string) => { const start = page * rowsPerPage; const end = start + rowsPerPage;