Skip to content

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

Merged
merged 1 commit into from
Mar 14, 2025

Conversation

vhpx
Copy link
Member

@vhpx vhpx commented Mar 14, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced event handling now supports processing and validating multiple events simultaneously.
    • The calendar event creation modal has been updated to allow users to preview, navigate, and save multiple AI-generated events, streamlining the event management experience.

@vhpx vhpx requested a review from Copilot March 14, 2025 16:56
@vhpx vhpx self-assigned this Mar 14, 2025
Copy link

graphite-app bot commented Mar 14, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

Copy link
Contributor

coderabbitai bot commented Mar 14, 2025

Walkthrough

This pull request introduces a new schema export, calendarEventsSchema, defined as an array of calendarEventSchema, in the AI package. The POST endpoint is updated to use this new export for validating arrays of calendar events. Additionally, the UnifiedEventModal UI component is modified to handle multiple AI-generated events instead of a single event, adding state to track the current event and navigation controls to cycle through events.

Changes

File(s) Summary of Change
packages/ai/src/calendar/{events.ts, route.ts} Added new export calendarEventsSchema (an array of calendarEventSchema) in events.ts; updated the import and usage in route.ts to validate multiple calendar events in the POST function.
packages/ui/src/components/ui/legacy/calendar/UnifiedEventModal.tsx Modified the component to support multiple generated events by replacing single event state with an array (generatedEvents), adding currentEventIndex, and updating navigation and saving logic.

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
Loading
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
Loading

Possibly related PRs

Poem

Hoppin' through the code with glee,
I’m a little bunny, wild and free.
Arrays of events now line my path,
Navigating changes with a joyful laugh.
Carrots and code in a merry spree,
Cheers to these updates from yours truly! 🐰

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

Scope: all 3 workspace projects
 ERR_PNPM_OPTIONAL_DEPS_REQUIRE_PROD_DEPS  Optional dependencies cannot be installed without production dependencies

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@Copilot Copilot AI left a 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];

@vhpx vhpx merged commit b29620f into main Mar 14, 2025
12 of 13 checks passed
@vhpx vhpx deleted the fix/Calendar-prompts branch March 14, 2025 17:08
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 or prevEvent 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9cc1310 and 6b1d400.

📒 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 of calendarEventSchema 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 of calendarEventSchema.


84-84: Schema parameter updated for multiple events validation.

The streamObject function now uses calendarEventsSchema instead of calendarEventSchema, 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:

  1. Checking if object is an array and falling back to a single-item array if not
  2. Mapping each event to ensure color is properly formatted
  3. Filtering out null values
  4. Resetting the current index when new events arrive
  5. 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:

  1. Checks if there are any events to save
  2. Iterates through all generated events
  3. Maps each event to the expected format
  4. 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:

  1. Checks boundary conditions to prevent going out of range
  2. Updates the current index state
  3. 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.

@Luan220703 Luan220703 restored the fix/Calendar-prompts branch March 15, 2025 04:32
@Luan220703 Luan220703 deleted the fix/Calendar-prompts branch March 15, 2025 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant