Skip to content

Conversation

@paula-stacho
Copy link
Collaborator

@paula-stacho paula-stacho commented Aug 28, 2025

Description

This is the last functional part (e2e tests and clean up to follow).

Open questions:

  • I'm not sure if we need to store the old field schema, keeping it here because it didn't occur to me to question this in tech design before, Rhys is not here atm, and it's usually easier to ignore than deal with missing data.
  • We're doing a cleanup of parts of schema when the new types no longer support them, but we're not warning the user of it. That means if the user wants to undo a change, it's better to do it with an actual undo, not just change the types back (this won't bring back the types). While some are visible on the diagram (nested fields disappear), others are not (we don't visualise array types, or required fields). I wouldn't skip the cleanup, as we could end up with weird messy schemas, but this might be something to keep an eye for or explicitly ask for feedback.

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 feat label Aug 28, 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 Aug 29, 2025
@paula-stacho paula-stacho marked this pull request as ready for review August 29, 2025 10:57
Copilot AI review requested due to automatic review settings August 29, 2025 10:57
@paula-stacho paula-stacho requested a review from a team as a code owner August 29, 2025 10:57
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 pull request implements field type change functionality for the data modeling component. Users can now modify field types through the UI, with proper validation and schema handling.

Key changes:

  • Added getSchemaWithNewTypes() function to handle complex schema transformations when field types change
  • Implemented changeFieldType action creator and ChangeFieldType edit operation
  • Enhanced the field drawer UI to allow type editing with validation

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/compass-data-modeling/test/fixtures/data-model-with-relationships.json Updated field name from id to _id in test fixture
packages/compass-data-modeling/src/utils/schema-traversal.tsx Added getSchemaWithNewTypes() function and schema transformation logic
packages/compass-data-modeling/src/utils/schema-traversal.spec.tsx Added comprehensive tests for the new schema transformation functionality
packages/compass-data-modeling/src/store/diagram.ts Implemented changeFieldType action creator
packages/compass-data-modeling/src/store/apply-edit.ts Added handling for ChangeFieldType edit operation
packages/compass-data-modeling/src/components/drawer/field-drawer-content.tsx Enhanced UI with type change functionality and validation
packages/compass-data-modeling/src/components/drawer/diagram-editor-side-panel.spec.tsx Added tests for field type change functionality and readonly behavior

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

@paula-stacho paula-stacho force-pushed the COMPASS-9659-change-type branch from ebf0647 to 7f6b5d2 Compare September 1, 2025 11:43
Comment on lines +700 to +705
if (!collectionSchema) throw new Error('Collection not found in model');
const field = getFieldFromSchema({
jsonSchema: collectionSchema,
fieldPath: fieldPath,
});
if (!field) throw new Error('Field not found in schema');
Copy link
Collaborator

Choose a reason for hiding this comment

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

For other edits like relationships we do validations like this in the applyEdit method, why are we breaking this pattern here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually for the name we do validation in the component and display the error next to the field. But this is a good question, we have these editErrors that are not displayed anywhere anymore. They must've fallen through the cracks when we were moving away from the placeholder editor. But I don't see the store validating relationships specifically, just checking the edit against the zod schema? Which is superfluous now, this was needed for the original editor where you'd submit a json edit so we couldn't depend on types. Or am I looking at something else than you found?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I'm not talking about form field validation here, keeping it near form UI makes sense. Specifically for apply edit we're checking whether or not the model or relationship is missing in the applyEdit method that generates the schema itself, not in the corresponding apply methods, so let's just figure out where we want it, otherwise we are ending up in a weird situation where similar types of errors in edits will have different effects on the application because validation is happening in different places 🙂 Right now the pattern seems to be to validate these in applyEdit and not when the action for adding the edit is dispached

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, sorry, I didn't notice which line you were commenting on :D
The problem here is, we're storing the Edit with the new field jsonSchema - so these failures happen already when we're prepping the Edit to be stored.
To change that, and to move the failure to applyEdit (which gets repeated when you move around in the history or open the diagram), we'd have to change the approach and not store the jsonSchema in the Edit. Instead we'd just store the new types and recalc the field schema each time the Edit is applied.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmm, wouldn't we want to do that in the first place? This apply method is the source of truth for calculating the final schema, I don't think we want to spread this logic around too much

Copy link
Collaborator

Choose a reason for hiding this comment

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

(we can leave this for a follow-up, but should figure out and agree on a consistent way of handling this)

Copy link
Collaborator

Choose a reason for hiding this comment

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

My concern also is that if we're not keeping the edits as source of truth for final state and modify them like that it would make generating migrations harder as we're losing information about the actual edit replacing it with the final state of the edit instead

Copy link
Collaborator

@gribnoysup gribnoysup left a comment

Choose a reason for hiding this comment

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

The behavior itself right now looks good to me, but let's have a ticket for later to look at the edit shape and logic again

@paula-stacho paula-stacho merged commit 04daaa9 into main Sep 2, 2025
100 of 106 checks passed
@paula-stacho paula-stacho deleted the COMPASS-9659-change-type branch September 2, 2025 15:29
addaleax added a commit that referenced this pull request Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants