Skip to content

Fix validation bug when converting Someday events to Grid/Calendar events#1003

Merged
victor-enogwe merged 4 commits intomainfrom
copilot/fix-f7f93547-17dd-479f-b835-a595d3c460f3
Sep 26, 2025
Merged

Fix validation bug when converting Someday events to Grid/Calendar events#1003
victor-enogwe merged 4 commits intomainfrom
copilot/fix-f7f93547-17dd-479f-b835-a595d3c460f3

Conversation

Copy link
Contributor

Copilot AI commented Sep 26, 2025

Problem

When converting a Someday event to a Grid/Calendar event (e.g., by dragging from sidebar to calendar), the conversion failed with a validation error:

ZodError: [
  {
    "code": "invalid_type",
    "expected": "object", 
    "received": "undefined",
    "path": ["position"],
    "message": "Required"
  }
]

This prevented users from seamlessly moving events between the Someday list and calendar grid view.

Root Cause

The _assembleGridEvent function in saga.util.ts was:

  1. Merging a Someday event (which lacks a position field) with updatedFields
  2. Directly validating the merged object with validateGridEvent
  3. Failing because GridEventSchema requires a position field that Someday events don't have

Solution

Modified _assembleGridEvent to use the existing assembleGridEvent utility function, which properly sets default values for all required Grid event fields including the position field:

// Before: Direct validation without ensuring required fields
const _gridEvent = { ...currEvent, ...updatedFields };
const gridEvent = validateGridEvent(_gridEvent);

// After: Use utility to ensure all required fields are set
const eventWithUpdates = { ...currEvent, ...updatedFields };
const gridEventWithDefaults = assembleGridEvent(eventWithUpdates);
const gridEvent = validateGridEvent(gridEventWithDefaults);

Testing

Added comprehensive unit tests that verify:

  • Someday events can be successfully converted to Grid events
  • The position field is properly populated with default values
  • Validation no longer fails during conversion

All existing tests continue to pass (419/419), ensuring no regression.

Impact

Users can now successfully convert Someday events to calendar events by dragging them to the grid without encountering validation errors.

Original prompt

This section details on the original issue you should resolve

<issue_title>Validation Bug When Converting Someday Event to Grid/Calendar Event</issue_title>
<issue_description>### Where did this happen?

local code with up-to-date main and hosted

Expected Behavior

When converting a Someday event to a Grid/Calendar event, the event should pass validation using GridEventSchema.

All required fields for a grid event, including the position object, should be correctly populated or handled.

The conversion should not result in runtime errors or failed schema validation.

Current Behavior

Converting a Someday event to a Grid/Calendar event fails validation. The position field required by GridEventSchema is missing or not properly constructed during conversion.

This causes runtime errors or prevents the event from being coverted to a grid and displayed in the calendar/grid view.

Steps to Reproduce

  • Go to the Sidebar
  • Create a Someday event if none exists by clicking on the "+" button.
  • Attempt to convert or move the Someday event to a calendar/grid event by dragging the event to the calendar grid.
  • Observe that the conversion fails due to schema validation errors related to the position field.

Image

Possible Solution

We can make the GridEventSchema position field optional, or for a more robust solution dtermine the grid position and update the new draft event with the DND position value before validating and saving the new event.

Context

The position field in GridEventSchema is currently required and expects a specific structure - see the DND library in use. Someday events do not have a position on the calendar grid, therefore their position fields are undefined at the time of dropping them into the calendar grid, leading to validation issues when converting between event types.

This bug affects the user experience by preventing seamless movement of events between the Someday and calendar/grid views.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #1002

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: victor-enogwe <23452630+victor-enogwe@users.noreply.github.com>
Copilot AI changed the title [WIP] Validation Bug When Converting Someday Event to Grid/Calendar Event Fix validation bug when converting Someday events to Grid/Calendar events Sep 26, 2025
Copilot AI requested a review from victor-enogwe September 26, 2025 10:37
@victor-enogwe victor-enogwe marked this pull request as ready for review September 26, 2025 11:43
Copilot AI review requested due to automatic review settings September 26, 2025 11:43
Copy link
Contributor

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 fixes a validation bug that prevented users from converting Someday events to Grid/Calendar events by dragging them from the sidebar to the calendar. The core issue was that Someday events lack the required position field that Grid events need, causing validation to fail during conversion.

Key Changes

  • Modified _assembleGridEvent to use the existing assembleGridEvent utility which properly sets default values for all required Grid event fields
  • Updated type signatures throughout the codebase to use more appropriate web event types
  • Added comprehensive unit tests to verify the fix works correctly

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/web/src/ducks/events/sagas/saga.util.ts Updated _assembleGridEvent to use assembleGridEvent utility and improved type annotations
packages/web/src/common/validators/grid.event.validator.ts Updated import structure and function signature to use Schema_WebEvent
packages/web/src/common/utils/event.util.ts Exported gridEventDefaultPosition, updated type signatures, and improved type handling
packages/web/src/common/utils/event.util.test.ts Added unit tests to verify Someday-to-Grid event conversion works properly
packages/web/src/common/types/web.event.types.ts Made _id field optional in WebCoreEventSchema
packages/core/src/util/test/ccal.event.factory.ts Updated MongoDB import and event utility import paths
packages/core/src/util/event/compass.event.rrule.ts Replaced WithId type with WithMongoId throughout
packages/core/src/util/event/compass.event.rrule.test.ts Updated import and type usage to use WithMongoId
packages/core/src/types/sync.types.ts Changed import to use type-only import
packages/core/src/types/mongo.types.ts Updated ObjectId import to use bson instead of mongodb
packages/core/src/mappers/map.event.ts Updated type signatures to use WithMongoId instead of WithId
packages/core/src/mocks/v1/events/events.22mar.ts Updated imports and type usage to use WithMongoId

@victor-enogwe victor-enogwe merged commit 01dbf16 into main Sep 26, 2025
4 checks passed
@victor-enogwe victor-enogwe deleted the copilot/fix-f7f93547-17dd-479f-b835-a595d3c460f3 branch September 26, 2025 11:54
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.

Validation Bug When Converting Someday Event to Grid/Calendar Event

3 participants