Skip to content

Commit c2b5cb3

Browse files
committed
wip
1 parent 7774beb commit c2b5cb3

File tree

3 files changed

+2
-73
lines changed

3 files changed

+2
-73
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,10 @@ const FieldDrawerContent: React.FunctionComponent<FieldDrawerContentProps> = ({
9999
fieldPath[fieldPath.length - 1],
100100
(fieldName) => {
101101
const trimmedName = fieldName.trim();
102-
console.log(
103-
`[Rename] ${fieldPath[fieldPath.length - 1]} -> ${trimmedName}`
104-
);
105102
if (trimmedName === fieldPath[fieldPath.length - 1]) {
106-
console.log('[Rename] No change in field name, skipping');
107103
return;
108104
}
109105
if (!isFieldNameValid) {
110-
console.log('[Rename] Invalid field name, skipping');
111106
return;
112107
}
113108
onRenameField(namespace, fieldPath, [

packages/compass-data-modeling/src/store/diagram.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
getDiagramName,
2626
} from '../services/open-and-download-diagram';
2727
import type { MongoDBJSONSchema } from 'mongodb-schema';
28-
import { traverseSchema } from '../utils/nodes-and-edges';
28+
import { traverseSchema } from '../utils/schema-traversal';
2929

3030
function isNonEmptyArray<T>(arr: T[]): arr is [T, ...T[]] {
3131
return Array.isArray(arr) && arr.length > 0;

packages/compass-data-modeling/src/utils/nodes-and-edges.tsx

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
FieldPath,
1010
Relationship,
1111
} from '../services/data-model-storage';
12+
import { traverseSchema } from './schema-traversal';
1213

1314
function getBsonTypeName(bsonType: string) {
1415
switch (bsonType) {
@@ -72,73 +73,6 @@ export const getHighlightedFields = (
7273
return selection;
7374
};
7475

75-
// TODO: add support for update
76-
// renaming fields, deleting fields, adding fields...
77-
// or maybe we can have two traverses? one for parsing, one for updating?
78-
export const traverseSchema = ({
79-
jsonSchema,
80-
parentFieldPath = [],
81-
visitor,
82-
}: {
83-
jsonSchema: MongoDBJSONSchema;
84-
visitor: ({
85-
fieldPath,
86-
fieldTypes,
87-
}: {
88-
fieldPath: FieldPath;
89-
fieldTypes: string[];
90-
}) => void;
91-
parentFieldPath?: FieldPath;
92-
}): void => {
93-
if (!jsonSchema || !jsonSchema.properties) {
94-
return;
95-
}
96-
for (const [name, field] of Object.entries(jsonSchema.properties)) {
97-
// field has types, properties and (optional) children
98-
// types are either direct, or from anyof
99-
// children are either direct (properties), from anyOf, items or items.anyOf
100-
const types: (string | string[])[] = [];
101-
const children: (MongoDBJSONSchema | MongoDBJSONSchema[])[] = [];
102-
if (field.bsonType) {
103-
types.push(field.bsonType);
104-
}
105-
if (field.properties) {
106-
children.push(field);
107-
}
108-
if (field.items) {
109-
children.push((field.items as MongoDBJSONSchema).anyOf || field.items);
110-
}
111-
if (field.anyOf) {
112-
for (const variant of field.anyOf) {
113-
if (variant.bsonType) {
114-
types.push(variant.bsonType);
115-
}
116-
if (variant.properties) {
117-
children.push(variant);
118-
}
119-
if (variant.items) {
120-
children.push(variant.items);
121-
}
122-
}
123-
}
124-
125-
const newFieldPath = [...parentFieldPath, name];
126-
127-
visitor({
128-
fieldPath: newFieldPath,
129-
fieldTypes: types.flat(),
130-
});
131-
132-
children.flat().forEach((child) =>
133-
traverseSchema({
134-
jsonSchema: child,
135-
visitor,
136-
parentFieldPath: newFieldPath,
137-
})
138-
);
139-
}
140-
};
141-
14276
export const getFieldsFromSchema = ({
14377
jsonSchema,
14478
highlightedFields = [],

0 commit comments

Comments
 (0)