Uh oh!
There was an error while loading. Please reload this page.
Normalize API assignment objects before storing in state - #52
Normalize API assignment objects before storing in state#52Jose-Gael-Cruz-Lopez wants to merge 1 commit into
Conversation
…mes" This reverts commit 1ba4f7549504c64ff6358504fc9fdf38f1620888.
Deploying web with |
| Latest commit: | c4ecd02 |
| Status: | ✅ Deploy successful! |
| Preview URL: | https://579f6223.web-75h.pages.dev |
| Branch Preview URL: | https://codex-fix-cloudflare-build-i.web-75h.pages.dev |
📝 WalkthroughWalkthroughA Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@frontend/src/app/calendar/page.tsx`:
- Around line 325-335: normalizeAssignments currently sets id to an empty string
when a.id is falsy which can cause duplicate keys; change normalizeAssignments
to produce a deterministic per-item fallback id (e.g., use the map index or
compose a stable string like `missing-id-${index}` or
`missing-id-${a.course_name}-${index}`) by using .map((a, index) => ({ id: a.id
?? `missing-id-${index}`, ... })) so each returned Assignment has a unique,
predictable id for list keying and downstream uses.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 0a2b2bd8-35fb-4bb9-90f1-e80b2714484e
📒 Files selected for processing (1)
frontend/src/app/calendar/page.tsx
| function normalizeAssignments(items: any[]): Assignment[] { | ||
| return (items ?? []).map((a: any) => ({ | ||
| id: a.id ?? '', | ||
| title: a.title ?? '', | ||
| course_name: a.course_name ?? '', | ||
| due_date: a.due_date ?? '', | ||
| assignment_type: a.assignment_type ?? 'other', | ||
| notes: a.notes ?? null, | ||
| google_event_id: a.google_event_id ?? null, | ||
| })); | ||
| } |
There was a problem hiding this comment.
Avoid empty-string fallback for id; it can create duplicate item identity
At Line 327, defaulting id to '' means multiple malformed rows collapse to the same identity, which breaks keyed list stability where a.id is used (e.g., Line 204/249/270). Use a deterministic per-item fallback instead.
💡 Proposed fix
-function normalizeAssignments(items: any[]): Assignment[] {- return (items ?? []).map((a: any) => ({- id: a.id ?? '',- title: a.title ?? '',- course_name: a.course_name ?? '',- due_date: a.due_date ?? '',- assignment_type: a.assignment_type ?? 'other',- notes: a.notes ?? null,- google_event_id: a.google_event_id ?? null,- }));+function normalizeAssignments(items: any[]): Assignment[] {+ return (items ?? []).map((a: any, i: number) => ({+ id: typeof a?.id === 'string' && a.id.trim() ? a.id : `missing_id_${i}`,+ title: typeof a?.title === 'string' ? a.title : '',+ course_name: typeof a?.course_name === 'string' ? a.course_name : '',+ due_date: typeof a?.due_date === 'string' ? a.due_date : '',+ assignment_type: typeof a?.assignment_type === 'string' && a.assignment_type ? a.assignment_type : 'other',+ notes: typeof a?.notes === 'string' ? a.notes : null,+ google_event_id: typeof a?.google_event_id === 'string' ? a.google_event_id : null,+ }));
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| functionnormalizeAssignments(items: any[]): Assignment[]{ | |
| return(items??[]).map((a: any)=>({ | |
| id: a.id??'', | |
| title: a.title??'', | |
| course_name: a.course_name??'', | |
| due_date: a.due_date??'', | |
| assignment_type: a.assignment_type??'other', | |
| notes: a.notes??null, | |
| google_event_id: a.google_event_id??null, | |
| })); | |
| } | |
| functionnormalizeAssignments(items: any[]): Assignment[]{ | |
| return(items??[]).map((a: any,i: number)=>({ | |
| id: typeofa?.id==='string'&&a.id.trim() ? a.id : `missing_id_${i}`, | |
| title: typeofa?.title==='string' ? a.title :'', | |
| course_name: typeofa?.course_name==='string' ? a.course_name :'', | |
| due_date: typeofa?.due_date==='string' ? a.due_date :'', | |
| assignment_type: typeofa?.assignment_type==='string'&&a.assignment_type ? a.assignment_type :'other', | |
| notes: typeofa?.notes==='string' ? a.notes :null, | |
| google_event_id: typeofa?.google_event_id==='string' ? a.google_event_id :null, | |
| })); | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@frontend/src/app/calendar/page.tsx` around lines 325 - 335,
normalizeAssignments currently sets id to an empty string when a.id is falsy
which can cause duplicate keys; change normalizeAssignments to produce a
deterministic per-item fallback id (e.g., use the map index or compose a stable
string like `missing-id-${index}` or `missing-id-${a.course_name}-${index}`) by
using .map((a, index) => ({ id: a.id ?? `missing-id-${index}`, ... })) so each
returned Assignment has a unique, predictable id for list keying and downstream
uses.
Jose-Gael-Cruz-Lopez
commented
Apr 14, 2026
Superseded by combined PR #53 (course_id migration + calendar normalization). Calendar normalizeAssignments + course_id/course_code passthrough included there. |
Motivation
Description
normalizeAssignments(items: any[]): Assignment[]to map/normalize incoming assignment objects with defaults and use it when handlinggetAllAssignmentsresponses during initial load, aftersaveAssignments, and aftersyncToGoogleCalendarrefresh.Testing
tsc) andyarn build/yarn lint, and they completed without errors.Codex Task
Summary by CodeRabbit