-
Couldn't load subscription status.
- Fork 239
feat(compass-data-modeling): update field type COMPASS-9659 #7248
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
Changes from 7 commits
4ef8b3a
5708a0b
c8af473
49d2e94
2a050c4
fffa78a
7f6b5d2
8d8f7a8
02ccc54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,11 @@ import type { MongoDBJSONSchema } from 'mongodb-schema'; | |
| import { getCoordinatesForNewNode } from '@mongodb-js/diagramming'; | ||
| import { collectionToDiagramNode } from '../utils/nodes-and-edges'; | ||
| import toNS from 'mongodb-ns'; | ||
| import { traverseSchema } from '../utils/schema-traversal'; | ||
| import { | ||
| getFieldFromSchema, | ||
| getSchemaWithNewTypes, | ||
| traverseSchema, | ||
| } from '../utils/schema-traversal'; | ||
| import { applyEdit as _applyEdit } from './apply-edit'; | ||
|
|
||
| function isNonEmptyArray<T>(arr: T[]): arr is [T, ...T[]] { | ||
|
|
@@ -684,6 +688,34 @@ export function renameField( | |
| return applyEdit({ type: 'RenameField', ns, field, newName }); | ||
| } | ||
|
|
||
| export function changeFieldType( | ||
| ns: string, | ||
| fieldPath: FieldPath, | ||
| newTypes: string[] | ||
| ): DataModelingThunkAction<void, ApplyEditAction | ApplyEditFailedAction> { | ||
| return (dispatch, getState) => { | ||
| const collectionSchema = selectCurrentModelFromState( | ||
| getState() | ||
| ).collections.find((collection) => collection.ns === ns)?.jsonSchema; | ||
| 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'); | ||
|
Comment on lines
+700
to
+705
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For other edits like relationships we do validations like this in the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| const to = getSchemaWithNewTypes(field.jsonSchema, newTypes); | ||
| dispatch( | ||
| applyEdit({ | ||
| type: 'ChangeFieldType', | ||
| ns, | ||
| field: fieldPath, | ||
| from: field.jsonSchema, | ||
| to, | ||
| }) | ||
| ); | ||
| }; | ||
| } | ||
|
|
||
| function getPositionForNewCollection( | ||
| existingCollections: DataModelCollection[], | ||
| newCollection: Omit<DataModelCollection, 'displayPosition'> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.