@@ -13,6 +13,7 @@ import { BSONType } from 'mongodb';
1313import {
1414 createNewRelationship ,
1515 deleteRelationship ,
16+ extractFieldsFromSchema ,
1617 renameField ,
1718 selectCurrentModelFromState ,
1819 selectRelationship ,
@@ -74,7 +75,15 @@ export function getIsFieldNameValid(
7475 }
7576
7677 const fieldsNamesWithoutCurrent = existingFields
77- . filter ( ( fieldPath ) => ! areFieldPathsEqual ( fieldPath , currentFieldPath ) )
78+ . filter (
79+ ( fieldPath ) =>
80+ fieldPath . length === currentFieldPath . length &&
81+ areFieldPathsEqual (
82+ fieldPath . slice ( 0 , fieldPath . length - 1 ) ,
83+ currentFieldPath . slice ( 0 , fieldPath . length - 1 )
84+ ) &&
85+ ! areFieldPathsEqual ( fieldPath , currentFieldPath )
86+ )
7887 . map ( ( fieldPath ) => fieldPath [ fieldPath . length - 1 ] ) ;
7988
8089 const isDuplicate = fieldsNamesWithoutCurrent . some (
@@ -179,16 +188,19 @@ export default connect(
179188 ownProps : { namespace : string ; fieldPath : FieldPath }
180189 ) => {
181190 const model = selectCurrentModelFromState ( state ) ;
191+ const collectionSchema = model . collections . find (
192+ ( collection ) => collection . ns === ownProps . namespace
193+ ) ?. jsonSchema ;
194+ if ( ! collectionSchema ) {
195+ throw new Error ( 'Collection not found' ) ;
196+ }
182197 return {
183198 types :
184199 getFieldFromSchema ( {
185- jsonSchema :
186- model . collections . find (
187- ( collection ) => collection . ns === ownProps . namespace
188- ) ?. jsonSchema ?? { } ,
200+ jsonSchema : collectionSchema ,
189201 fieldPath : ownProps . fieldPath ,
190202 } ) ?. fieldTypes ?? [ ] ,
191- fieldPaths : [ ] , // TODO(COMPASS-9659): get existing field paths
203+ fieldPaths : extractFieldsFromSchema ( collectionSchema ) ,
192204 relationships : model . relationships . filter ( ( { relationship } ) =>
193205 isRelationshipOfAField (
194206 relationship ,
0 commit comments