Skip to content

Commit 09ef6f1

Browse files
committed
implement PR suggestions
1 parent eb716a9 commit 09ef6f1

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

packages/compass-data-modeling/src/components/drawer/field-drawer-content.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,16 @@ export function getIsFieldNameValid(
8181
const siblingFields = existingFields
8282
.filter(
8383
(fieldPath) =>
84+
// same level
8485
fieldPath.length === currentFieldPath.length &&
86+
// same path to that level
8587
areFieldPathsEqual(
8688
fieldPath.slice(0, fieldPath.length - 1),
8789
currentFieldPath.slice(0, fieldPath.length - 1)
8890
) &&
89-
!areFieldPathsEqual(fieldPath, currentFieldPath)
91+
// not the same field
92+
fieldPath[fieldPath.length - 1] !==
93+
currentFieldPath[currentFieldPath.length - 1]
9094
)
9195
.map((fieldPath) => fieldPath[fieldPath.length - 1]);
9296

packages/compass-data-modeling/src/utils/schema-traversal.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,20 +166,20 @@ export const getFieldFromSchema = ({
166166
});
167167
};
168168

169-
type MutationParameters = {
169+
type UpdateOperationParameters = {
170170
update: 'removeField' | 'renameField';
171171
newFieldName?: string;
172172
};
173173

174-
const getMutatedSchema = ({
174+
const applySchemaUpdate = ({
175175
schema,
176176
fieldName,
177177
newFieldName,
178178
update,
179179
}: {
180180
schema: MongoDBJSONSchema;
181181
fieldName: string;
182-
} & MutationParameters): MongoDBJSONSchema => {
182+
} & UpdateOperationParameters): MongoDBJSONSchema => {
183183
switch (update) {
184184
case 'removeField': {
185185
if (!schema.properties || !schema.properties[fieldName])
@@ -221,7 +221,7 @@ export const updateSchema = ({
221221
}: {
222222
jsonSchema: MongoDBJSONSchema;
223223
fieldPath: FieldPath;
224-
} & MutationParameters): MongoDBJSONSchema => {
224+
} & UpdateOperationParameters): MongoDBJSONSchema => {
225225
const newSchema = {
226226
...jsonSchema,
227227
};
@@ -231,7 +231,7 @@ export const updateSchema = ({
231231
if (newSchema.properties && newSchema.properties[nextInPath]) {
232232
if (targetReached) {
233233
// reached the field to remove
234-
return getMutatedSchema({
234+
return applySchemaUpdate({
235235
schema: newSchema,
236236
fieldName: nextInPath,
237237
update,

packages/compass-data-modeling/src/utils/utils.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,7 @@ export function isSameFieldOrAncestor(
1414
ancestor: FieldPath,
1515
child: FieldPath
1616
): boolean {
17-
if (ancestor.length === child.length)
18-
return areFieldPathsEqual(ancestor, child);
19-
if (ancestor.length > child.length) return false;
20-
// ignore the last character - closing bracket
21-
const ancestorPath = JSON.stringify(ancestor).slice(0, -1);
22-
const beginningOfChildPath = JSON.stringify(child).slice(
23-
0,
24-
ancestorPath.length
25-
);
26-
return ancestorPath === beginningOfChildPath;
17+
return ancestor.every((pathPart, index) => pathPart === child[index]);
2718
}
2819

2920
export function isRelationshipOfAField(

0 commit comments

Comments
 (0)