Skip to content

Conversation

@paula-stacho
Copy link
Collaborator

@paula-stacho paula-stacho commented Oct 16, 2025

Description

Identified several problems related to https://jira.mongodb.org/browse/COMPASS-9945.
One of the problems is that we never try to actually build the model with the new edit before saving it to storage.
Also the APPLY_EDIT_FAILED was a dead end (this was a leftover from the temporary editor and got forgotten since). Instead, we're now showing a toast.
Side change: I realised that we silently ignore non existing collections, added checks.

Will come in separate PRs:

  • fixing the "addField" logic pull#7463
  • making sure the list of diagrams is still accessible even if some of the diagrams are corrupted pull#7471
Screen.Recording.2025-10-17.at.12.31.55.mov

Checklist

  • New tests and/or benchmarks are included
  • Documentation is changed or added
  • If this change updates the UI, screenshots/videos are added and a design review is requested
  • I have signed the MongoDB Contributor License Agreement (https://www.mongodb.com/legal/contributor-agreement)

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@github-actions github-actions bot added the fix label Oct 16, 2025
@paula-stacho paula-stacho added the feature flagged PRs labeled with this label will not be included in the release notes of the next release label Oct 16, 2025
@paula-stacho paula-stacho force-pushed the COMPASS-9945-error-handling branch from 2cc1194 to 2d0acb1 Compare October 17, 2025 10:27
@paula-stacho paula-stacho marked this pull request as ready for review October 17, 2025 10:33
Copilot AI review requested due to automatic review settings October 17, 2025 10:33
@paula-stacho paula-stacho requested a review from a team as a code owner October 17, 2025 10:33
@paula-stacho paula-stacho requested a review from ivandevp October 17, 2025 10:33
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 addresses issues with error handling when applying invalid edits to data modeling diagrams (COMPASS-9945). The key improvements include: (1) validating edits by attempting to build the model before saving, (2) replacing the ineffective APPLY_EDIT_FAILED action with user-facing toast notifications, and (3) adding collection existence checks for edit operations.

Key Changes:

  • Introduced toast notifications for edit validation failures instead of storing errors in state
  • Added model building validation after applying edits with automatic revert on failure
  • Added collection existence checks in ensureCollectionExists to catch invalid operations early

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/compass-data-modeling/test/setup-store.tsx Added openToast parameter to test store setup for dependency injection
packages/compass-data-modeling/src/store/reducer.ts Added openToast to DataModelingExtraArgs type definition
packages/compass-data-modeling/src/store/index.ts Modified store options to include openToast function with default implementation
packages/compass-data-modeling/src/store/diagram.ts Replaced APPLY_EDIT_FAILED action with REVERT_FAILED_EDIT, added model validation after applying edits, and integrated toast notifications
packages/compass-data-modeling/src/store/diagram.spec.ts Updated tests to use spy for openToast and verify toast calls instead of checking editErrors
packages/compass-data-modeling/src/store/apply-edit.ts Added ensureCollectionExists helper function and validation checks for collection operations
packages/compass-data-modeling/src/components/diagram-editor.tsx Removed unused editErrors prop from diagram component

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Collaborator

@ivandevp ivandevp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


// try to build the model with the latest edit
try {
selectCurrentModelFromState(getState());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am trying to understand why we are calling this function. I don't see how it directly impacts saving of model. Maybe I am missing something.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to prevent saving a model that is corrupted (the edits cannot be build together).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're only validating the edit on it's own, so if an edit is formatted well we save it. But it can be that the edit doesn't work with the rest (for example we try to rename a collection that doesn't exist, or make an unexpected change in the schema).

Copy link
Collaborator Author

@paula-stacho paula-stacho Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the impact - there is none, but the function might throw an error, and that's when we start the recovery process (revert & show toast)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks!

@paula-stacho paula-stacho merged commit 9aab429 into main Oct 17, 2025
57 of 59 checks passed
@paula-stacho paula-stacho deleted the COMPASS-9945-error-handling branch October 17, 2025 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature flagged PRs labeled with this label will not be included in the release notes of the next release fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants