-
Notifications
You must be signed in to change notification settings - Fork 244
feat(compass-data-modeling): delete and rename field COMPASS-9659 #7237
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 11 commits
060e63b
ce70661
54e086a
7694648
7e6c4ba
850b54f
cc5a7ff
343f0c5
a854267
1ec4e54
c5b4f14
eb716a9
09ef6f1
307a26c
48cc245
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 | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,8 @@ import { BSONType } from 'mongodb'; | |||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||
| createNewRelationship, | ||||||||||||||||||||||||||
| deleteRelationship, | ||||||||||||||||||||||||||
| extractFieldsFromSchema, | ||||||||||||||||||||||||||
| renameField, | ||||||||||||||||||||||||||
| selectCurrentModelFromState, | ||||||||||||||||||||||||||
| selectRelationship, | ||||||||||||||||||||||||||
| } from '../../store/diagram'; | ||||||||||||||||||||||||||
|
|
@@ -24,7 +26,7 @@ import { | |||||||||||||||||||||||||
| import { useChangeOnBlur } from './use-change-on-blur'; | ||||||||||||||||||||||||||
| import { RelationshipsSection } from './relationships-section'; | ||||||||||||||||||||||||||
| import { getFieldFromSchema } from '../../utils/schema-traversal'; | ||||||||||||||||||||||||||
| import { areFieldPathsEqual } from '../../utils/utils'; | ||||||||||||||||||||||||||
| import { areFieldPathsEqual, isRelationshipOfAField } from '../../utils/utils'; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| type FieldDrawerContentProps = { | ||||||||||||||||||||||||||
| namespace: string; | ||||||||||||||||||||||||||
|
|
@@ -44,7 +46,7 @@ type FieldDrawerContentProps = { | |||||||||||||||||||||||||
| onRenameField: ( | ||||||||||||||||||||||||||
| namespace: string, | ||||||||||||||||||||||||||
| fromFieldPath: FieldPath, | ||||||||||||||||||||||||||
| toFieldPath: FieldPath | ||||||||||||||||||||||||||
| newName: string | ||||||||||||||||||||||||||
| ) => void; | ||||||||||||||||||||||||||
| onChangeFieldType: ( | ||||||||||||||||||||||||||
| namespace: string, | ||||||||||||||||||||||||||
|
|
@@ -72,11 +74,19 @@ export function getIsFieldNameValid( | |||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const fieldsNamesWithoutCurrent = existingFields | ||||||||||||||||||||||||||
| .filter((fieldPath) => !areFieldPathsEqual(fieldPath, currentFieldPath)) | ||||||||||||||||||||||||||
| const siblingFields = existingFields | ||||||||||||||||||||||||||
| .filter( | ||||||||||||||||||||||||||
| (fieldPath) => | ||||||||||||||||||||||||||
| fieldPath.length === currentFieldPath.length && | ||||||||||||||||||||||||||
| areFieldPathsEqual( | ||||||||||||||||||||||||||
| fieldPath.slice(0, fieldPath.length - 1), | ||||||||||||||||||||||||||
| currentFieldPath.slice(0, fieldPath.length - 1) | ||||||||||||||||||||||||||
| ) && | ||||||||||||||||||||||||||
| !areFieldPathsEqual(fieldPath, currentFieldPath) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| fieldPath.length === currentFieldPath.length && | |
| areFieldPathsEqual( | |
| fieldPath.slice(0, fieldPath.length - 1), | |
| currentFieldPath.slice(0, fieldPath.length - 1) | |
| ) && | |
| !areFieldPathsEqual(fieldPath, currentFieldPath) | |
| fieldPath.length === currentFieldPath.length && | |
| fieldPath[fieldPath.length - 1] !== currentFieldPath[currentFieldPath.length - 1] && | |
| areFieldPathsEqual( | |
| fieldPath.slice(0, fieldPath.length - 1), | |
| currentFieldPath.slice(0, currentFieldPath.length - 1) | |
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! The slice check is indeed better, but I'm not sure if the order needs to change. The 3rd check only eliminates fields with the same name, so unless there is a lot of field name repetition, both checks would be executed most of the time. The other check eliminates non-siblings, so it has a higher chance of reducing the number of checks.. even if it does get more expensive with a long path and high number of close relatives
paula-stacho marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to make the interface of your component tighther here and only accept the actual data that you need inside the component and pick field paths for the parent of the field you're rendering this for, roughly something like:
| fieldPaths: extractFieldsFromSchema(collectionSchema), | |
| fieldPaths: Object.keys(getFieldFromSchema({jsonSchema: collectionSchema, fieldPath: ownProps.fieldPath.slice(0, ownProps.fieldPath - 1)}).properties), |
You're only using these to validate whether or not the field is duplicated with another field, so precalculating this array of fields here makes the interface of the component clearer.
Just generally, from the perspective of how to think about component interfaces, I would strongly suggest to limit it to the absolute minimum of what the component needs. Start from component itself, define the bare minimum of what you need without connecting it to state first, then proceed to map state to required properties. This usually leads to way cleaner component inteface, usually more composable, and as a side-effect usually means that your connect functions actually have a chance of avoiding unnecessary re-renders (that's almost impossible when non primitive values are passed, so we're not going to get it here, but you'd generally get more simple values if that's how you approach this)
Uh oh!
There was an error while loading. Please reload this page.