-
-
Notifications
You must be signed in to change notification settings - Fork 19
feat(calendar): introduce calendarEventsSchema for handling multiple events and update related components #2292
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
…events and update related components
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
WalkthroughThis pull request introduces a new schema export, Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Route as POST Endpoint (route.ts)
participant Schema as calendarEventsSchema
Client->>Route: Send POST request with array of events
Route->>Schema: Validate events data (array)
Schema-->>Route: Return validation result
Route-->>Client: Respond with processed result
sequenceDiagram
participant User
participant Modal as UnifiedEventModal
User->>Modal: Trigger AI event generation
Modal->>Modal: Receive & store generatedEvents array
Modal->>Modal: Render event at currentEventIndex
User->>Modal: Click "next" button
Modal->>Modal: Update currentEventIndex
Modal-->>User: Display next event preview
Possibly related PRs
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 ESLint
Scope: all 3 workspace projects Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 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.
Pull Request Overview
This PR introduces support for multiple calendar events by updating the event schema to handle arrays of events and refactoring the UI component to allow navigation between generated events. Key changes include:
- Importing and using the new calendarEventsSchema in both UI and API routes.
- Refactoring the UnifiedEventModal component to manage and preview multiple AI-generated events.
- Adding navigation buttons to cycle through the generated events.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
packages/ui/src/components/ui/legacy/calendar/UnifiedEventModal.tsx | Updated to use multiple generated events with new state and navigation controls |
packages/ai/src/calendar/events.ts | Introduces calendarEventsSchema as an array of calendar events |
packages/ai/src/calendar/route.ts | Uses calendarEventsSchema for validating generated events |
Comments suppressed due to low confidence (1)
packages/ui/src/components/ui/legacy/calendar/UnifiedEventModal.tsx:124
- [nitpick] Consider renaming 'generatedEvent' to 'currentGeneratedEvent' for clarity, as it represents the currently previewed event from the 'generatedEvents' array.
const generatedEvent = generatedEvents[currentEventIndex];
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: 0
🧹 Nitpick comments (2)
packages/ui/src/components/ui/legacy/calendar/UnifiedEventModal.tsx (2)
186-186
: Use optional chaining to avoid potential null errors.The current code doesn't handle the case where
firstEvent
could be undefined, which could lead to runtime errors.- if (firstEvent && firstEvent.start_at && firstEvent.end_at) { + if (firstEvent?.start_at && firstEvent?.end_at) {🧰 Tools
🪛 Biome (1.9.4)
[error] 186-186: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
555-555
: Use optional chaining to avoid potential null errors.The current code doesn't handle the case where
nextEvent
orprevEvent
could be undefined, which could lead to runtime errors.- if (nextEvent && nextEvent.start_at && nextEvent.end_at) { + if (nextEvent?.start_at && nextEvent?.end_at) { - if (prevEvent && prevEvent.start_at && prevEvent.end_at) { + if (prevEvent?.start_at && prevEvent?.end_at) {Also applies to: 568-568
🧰 Tools
🪛 Biome (1.9.4)
[error] 555-555: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/ai/src/calendar/events.ts
(1 hunks)packages/ai/src/calendar/route.ts
(2 hunks)packages/ui/src/components/ui/legacy/calendar/UnifiedEventModal.tsx
(14 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/ui/src/components/ui/legacy/calendar/UnifiedEventModal.tsx
[error] 186-186: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 555-555: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 568-568: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
🔇 Additional comments (12)
packages/ai/src/calendar/events.ts (1)
81-81
: Well-structured addition for supporting multiple events.The implementation of
calendarEventsSchema
as an array ofcalendarEventSchema
is clean and follows Zod's pattern for defining array schemas. This change enables the validation of multiple calendar events, which is essential for the new multi-event functionality.packages/ai/src/calendar/route.ts (2)
1-1
: Import updated to support multiple events schema.The import has been correctly updated to use
calendarEventsSchema
instead ofcalendarEventSchema
.
84-84
: Schema parameter updated for multiple events validation.The
streamObject
function now usescalendarEventsSchema
instead ofcalendarEventSchema
, which aligns with the changes made in the events.ts file. This enables the POST endpoint to validate arrays of calendar events.packages/ui/src/components/ui/legacy/calendar/UnifiedEventModal.tsx (9)
17-17
: Import updated to use calendarEventsSchema.The import has been correctly updated to match the schema changes in the AI package.
117-118
: State variables updated to support multiple events.The state has been properly refactored from a single event to an array of events, with an additional state variable to track the current event index. This is a necessary change to support the new multi-event functionality.
124-125
: Added accessor for current event.This provides a clean way to access the current event being previewed from the array of generated events.
158-158
: Schema reference updated for multiple events.The schema reference in the useObject hook has been correctly updated to use the new calendarEventsSchema.
161-189
: Handle AI-generated events properly.The effect hook has been refactored to handle arrays of events. The implementation properly handles edge cases:
- Checking if object is an array and falling back to a single-item array if not
- Mapping each event to ensure color is properly formatted
- Filtering out null values
- Resetting the current index when new events arrive
- Checking for overlaps on the first event
🧰 Tools
🪛 Biome (1.9.4)
[error] 186-186: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
346-372
: Event saving logic updated for multiple events.The function has been properly updated to handle saving multiple events instead of just one. The implementation correctly:
- Checks if there are any events to save
- Iterates through all generated events
- Maps each event to the expected format
- Updates the success message to reflect the number of events saved
548-573
: Added navigation functions for multiple events.The implementation for navigating between events is well-structured, with functions to go to the next and previous events. Each function:
- Checks boundary conditions to prevent going out of range
- Updates the current index state
- Checks for overlaps when smart scheduling is enabled
🧰 Tools
🪛 Biome (1.9.4)
[error] 555-555: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
[error] 568-568: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
1101-1124
: Well-implemented UI for navigating multiple events.The navigation UI is clean and intuitive, showing both the current position (index) and providing easy-to-use navigation buttons. The disabled states are handled correctly to prevent navigating beyond the available events.
1198-1203
: Dynamic button label based on number of events.The button text intelligently adapts based on whether there are multiple events or just one, which improves the user experience.
Summary by CodeRabbit