-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: sort robots and runs table #419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe pull request introduces improvements to date handling and sorting in two key components: Changes
Assessment against linked issues
Possibly related issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
src/components/run/RunsTable.tsx (1)
Line range hint
192-202: Enhance date parsing robustness.The current implementation has several potential issues:
- Silent error handling could mask date parsing issues
- No validation of date components
- Assumes specific date formats without explicit validation
const parseDateString = (dateStr: string): Date => { + if (!dateStr) { + console.warn('Empty date string provided'); + return new Date(0); + } + try { if (dateStr.includes('PM') || dateStr.includes('AM')) { - return new Date(dateStr); + const parsed = new Date(dateStr); + if (isNaN(parsed.getTime())) { + throw new Error('Invalid AM/PM date format'); + } + return parsed; } - return new Date(dateStr.replace(/(\d+)\/(\d+)\//, '$2/$1/')) + const [month, day, ...rest] = dateStr.split('/'); + if (!month || !day || rest.length === 0) { + throw new Error('Invalid date format, expected MM/DD/YYYY'); + } + const parsed = new Date(dateStr.replace(/(\d+)\/(\d+)\//, '$2/$1/')); + if (isNaN(parsed.getTime())) { + throw new Error('Invalid date components'); + } + return parsed; } catch (error) { + console.warn(`Failed to parse date: ${dateStr}`, error); return new Date(0); } };
🧹 Nitpick comments (2)
src/components/run/RunsTable.tsx (1)
209-236: Consider optimizing date parsing operations.The current implementation parses dates multiple times for the same records during sorting operations. Consider parsing dates once and storing the timestamp.
const groupedRows = useMemo(() => { const groupedData = filteredRows.reduce((acc, row) => { + const parsedStartedAt = parseDateString(row.startedAt).getTime(); if (!acc[row.robotMetaId]) { acc[row.robotMetaId] = []; } - acc[row.robotMetaId].push(row); + acc[row.robotMetaId].push({ ...row, parsedStartedAt }); return acc; }, {} as Record<string, Data[]>); Object.keys(groupedData).forEach(robotId => { groupedData[robotId].sort((a, b) => - parseDateString(b.startedAt).getTime() - parseDateString(a.startedAt).getTime() + b.parsedStartedAt - a.parsedStartedAt ); }); const robotEntries = Object.entries(groupedData).map(([robotId, runs]) => ({ robotId, runs, - latestRunDate: parseDateString(runs[0].startedAt).getTime() + latestRunDate: runs[0].parsedStartedAt })); robotEntries.sort((a, b) => b.latestRunDate - a.latestRunDate); return robotEntries.reduce((acc, { robotId, runs }) => { - acc[robotId] = runs; + acc[robotId] = runs.map(({ parsedStartedAt, ...rest }) => rest); return acc; }, {} as Record<string, Data[]>); }, [filteredRows]);src/components/robot/RecordingsTable.tsx (1)
210-224: Improve type safety in recordings mapping.The current implementation lacks proper type definitions for the recording data structure and uses implicit null checks.
+interface RecordingMeta { + createdAt: string; + name: string; + // add other required fields +} + +interface Recording { + recording_meta: RecordingMeta; + recording: WorkflowFile; +} + const parsedRows = recordings - .map((recording: any, index: number) => { - if (recording?.recording_meta) { + .map((recording: Recording, index: number) => { + const { recording_meta } = recording; + if (!recording_meta?.createdAt) { + console.warn(`Invalid recording meta at index ${index}`); + return null; + } + try { const parsedDate = parseDateString(recording.recording_meta.createdAt); return { id: index, - ...recording.recording_meta, + ...recording_meta, content: recording.recording, parsedDate }; - } + } catch (error) { + console.error(`Failed to process recording at index ${index}:`, error); + return null; + } return null; }) .filter(Boolean) .sort((a, b) => b.parsedDate.getTime() - a.parsedDate.getTime());
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/components/robot/RecordingsTable.tsx(1 hunks)src/components/run/RunsTable.tsx(1 hunks)
| 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); | ||
| } | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Extract date parsing logic to a shared utility.
The parseDateString function is duplicated between RunsTable.tsx and RecordingsTable.tsx. Consider extracting it to a shared utility file.
Create a new file src/utils/dateUtils.ts:
export const parseDateString = (dateStr: string): Date => {
if (!dateStr) {
console.warn('Empty date string provided');
return new Date(0);
}
try {
if (dateStr.includes('PM') || dateStr.includes('AM')) {
const parsed = new Date(dateStr);
if (isNaN(parsed.getTime())) {
throw new Error('Invalid AM/PM date format');
}
return parsed;
}
const [month, day, ...rest] = dateStr.split('/');
if (!month || !day || rest.length === 0) {
throw new Error('Invalid date format, expected MM/DD/YYYY');
}
const parsed = new Date(dateStr.replace(/(\d+)\/(\d+)\//, '$2/$1/'));
if (isNaN(parsed.getTime())) {
throw new Error('Invalid date components');
}
return parsed;
} catch (error) {
console.warn(`Failed to parse date: ${dateStr}`, error);
return new Date(0);
}
};Then import and use it in both components:
+import { parseDateString } from '../../utils/dateUtils';
Closes: #418
Summary by CodeRabbit
New Features
Bug Fixes