Skip to content

Conversation

@paula-stacho
Copy link
Collaborator

@paula-stacho paula-stacho commented Dec 12, 2025

Description

Saving multiple connections move.
Steps to Reproduce

  • Create a diagram with multiple collections
  • Select one collection
  • Without unselecting, press down CMD button (on macos) and now try dragging another collection

These steps are a bit inconvenient, I think we might add proper support multi-item selections (the relational migrator has it), but that's for another day. This just fixes the issue that the users were able to drag multiple collections, but we weren't saving it.

Screen.Recording.2025-12-12.at.19.52.29.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
  • If this change could impact the load on the MongoDB cluster, please describe the expected and worst case impact
  • 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)

@paula-stacho paula-stacho requested a review from a team as a code owner December 12, 2025 18:55
@paula-stacho paula-stacho requested review from Copilot and nbbeeken and removed request for Copilot December 12, 2025 18:55
@github-actions github-actions bot added the fix label Dec 12, 2025
@paula-stacho paula-stacho added feature flagged PRs labeled with this label will not be included in the release notes of the next release release notes and removed feature flagged PRs labeled with this label will not be included in the release notes of the next release labels Dec 12, 2025
Copilot AI review requested due to automatic review settings December 12, 2025 19:41
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 bug where moving multiple collections simultaneously in the diagram editor was not being saved. The fix adds support for a new MoveMultipleCollections edit type that can handle batch position updates when users drag multiple selected collections.

Key Changes:

  • Introduces a new MoveMultipleCollections edit type to handle batch collection moves
  • Updates the diagram editor to detect multi-node drags and dispatch the appropriate edit action
  • Adds schema validation and test coverage for the new edit type

Reviewed changes

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

Show a summary per file
File Description
packages/compass-data-modeling/src/store/diagram.ts Adds moveMultipleCollections action creator for the new edit type
packages/compass-data-modeling/src/store/diagram.spec.ts Adds test coverage for the MoveMultipleCollections edit functionality
packages/compass-data-modeling/src/store/apply-edit.ts Implements the logic to apply MoveMultipleCollections edits to the model
packages/compass-data-modeling/src/services/data-model-storage.ts Adds Zod schema validation for the new edit type
packages/compass-data-modeling/src/components/diagram-editor.tsx Updates UI component to handle multi-node drag events and dispatch appropriate actions

Comment on lines +115 to +118
const movedCollections = Object.keys(edit.newPositions);
for (const ns of movedCollections) {
assertCollectionExists(model.collections, ns);
}
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

Use a for-of loop over Object.keys() for better readability and consistency with modern JavaScript patterns. Consider: for (const ns of Object.keys(edit.newPositions)) to eliminate the intermediate variable.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +116 to +122
for (const ns of movedCollections) {
assertCollectionExists(model.collections, ns);
}
return {
...model,
collections: model.collections.map((collection) => {
if (movedCollections.includes(collection.ns)) {
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

Using includes() inside a map() results in O(n*m) complexity. Convert movedCollections to a Set before the map operation for O(1) lookup performance when dealing with multiple collections.

Suggested change
for (const ns of movedCollections) {
assertCollectionExists(model.collections, ns);
}
return {
...model,
collections: model.collections.map((collection) => {
if (movedCollections.includes(collection.ns)) {
const movedCollectionsSet = new Set(movedCollections);
for (const ns of movedCollections) {
assertCollectionExists(model.collections, ns);
}
return {
...model,
collections: model.collections.map((collection) => {
if (movedCollectionsSet.has(collection.ns)) {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants