Skip to content

Commit e6f612e

Browse files
committed
cleanup
1 parent 090b0b6 commit e6f612e

File tree

3 files changed

+14
-76
lines changed

3 files changed

+14
-76
lines changed

packages/compass-data-modeling/src/components/diagram-editor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ const DiagramContent: React.FunctionComponent<{
269269
openDrawer(DATA_MODELING_DRAWER_ID);
270270
}}
271271
onFieldClick={(_evt, { id: fieldPath, nodeId: namespace }) => {
272-
_evt.stopPropagation(); // TODO: should this be handled by the diagramming package?
273-
if (!Array.isArray(fieldPath)) return; // TODO: could be avoided with generics in the diagramming package
272+
_evt.stopPropagation(); // TODO(COMPASS-9659): should this be handled by the diagramming package?
273+
if (!Array.isArray(fieldPath)) return; // TODO(COMPASS-9659): could be avoided with generics in the diagramming package
274274
onFieldSelect(namespace, fieldPath);
275275
openDrawer(DATA_MODELING_DRAWER_ID);
276276
}}

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { BSONType } from 'mongodb';
1414
import {
1515
createNewRelationship,
1616
deleteRelationship,
17-
renameField,
1817
selectCurrentModelFromState,
1918
selectRelationship,
2019
} from '../../store/diagram';
@@ -26,7 +25,6 @@ import {
2625
import { useChangeOnBlur } from './use-change-on-blur';
2726
import { RelationshipsSection } from './relationships-section';
2827
import { getFieldFromSchema } from '../../utils/schema-traversal';
29-
import { lowerFirst } from 'lodash';
3028

3129
type FieldDrawerContentProps = {
3230
namespace: string;
@@ -51,8 +49,8 @@ type FieldDrawerContentProps = {
5149
onChangeFieldType: (
5250
namespace: string,
5351
fieldPath: FieldPath,
54-
fromBsonType: string,
55-
toBsonType: string
52+
fromBsonType: string | string[],
53+
toBsonType: string | string[]
5654
) => void;
5755
};
5856

@@ -126,6 +124,10 @@ const FieldDrawerContent: React.FunctionComponent<FieldDrawerContentProps> = ({
126124
[fieldPath, fieldPaths, fieldName]
127125
);
128126

127+
const handleTypeChange = (newTypes: string | string[]) => {
128+
onChangeFieldType(namespace, fieldPath, types, newTypes);
129+
};
130+
129131
return (
130132
<>
131133
<DMDrawerSection label="Field properties">
@@ -147,18 +149,15 @@ const FieldDrawerContent: React.FunctionComponent<FieldDrawerContentProps> = ({
147149
data-testid="lg-combobox-datatype"
148150
label="Datatype"
149151
aria-label="Datatype"
150-
disabled={true} // TODO: enable when field type change is implemented
152+
disabled={true} // TODO(COMPASS-9659): enable when field type change is implemented
151153
value={types}
152154
size="small"
153155
multiselect={true}
154156
clearable={false}
157+
onChange={handleTypeChange}
155158
>
156159
{BSON_TYPES.map((type) => (
157-
<ComboboxOption
158-
key={type}
159-
value={lowerFirst(type)}
160-
displayName={type}
161-
/>
160+
<ComboboxOption key={type} value={type} />
162161
))}
163162
</Combobox>
164163
</DMFormFieldContainer>
@@ -206,7 +205,7 @@ export default connect(
206205
)?.jsonSchema ?? {},
207206
fieldPath: ownProps.fieldPath,
208207
})?.fieldTypes ?? [],
209-
fieldPaths: [], // TODO get existing field paths
208+
fieldPaths: [], // TODO(COMPASS-9659): get existing field paths
210209
relationships: model.relationships.filter((r) => {
211210
const [local, foreign] = r.relationship;
212211
return (
@@ -224,7 +223,7 @@ export default connect(
224223
onCreateNewRelationshipClick: createNewRelationship,
225224
onEditRelationshipClick: selectRelationship,
226225
onDeleteRelationshipClick: deleteRelationship,
227-
onRenameField: renameField,
228-
onChangeFieldType: () => {}, // TODO: updateFieldSchema,
226+
onRenameField: () => {}, // TODO(COMPASS-9659): renameField,
227+
onChangeFieldType: () => {}, // TODO(COMPASS-9659): updateFieldSchema,
229228
}
230229
)(FieldDrawerContent);

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

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -510,29 +510,6 @@ export function renameCollection(
510510
};
511511
}
512512

513-
export function renameField(
514-
ns: string,
515-
from: FieldPath,
516-
to: FieldPath
517-
): DataModelingThunkAction<
518-
void,
519-
ApplyEditAction | ApplyEditFailedAction | CollectionSelectedAction
520-
> {
521-
return (dispatch) => {
522-
const edit: Omit<
523-
Extract<Edit, { type: 'RenameField' }>,
524-
'id' | 'timestamp'
525-
> = {
526-
type: 'RenameField',
527-
ns,
528-
from,
529-
to,
530-
};
531-
532-
dispatch(applyEdit(edit));
533-
};
534-
}
535-
536513
export function applyEdit(
537514
rawEdit: EditAction
538515
): DataModelingThunkAction<boolean, ApplyEditAction | ApplyEditFailedAction> {
@@ -859,44 +836,6 @@ function _applyEdit(edit: Edit, model?: StaticModel): StaticModel {
859836
})),
860837
};
861838
}
862-
case 'RenameField': {
863-
return {
864-
...model,
865-
// Update relationships to point to the renamed field.
866-
relationships: model.relationships.map((relationship) => {
867-
const [local, foreign] = relationship.relationship;
868-
869-
return {
870-
...relationship,
871-
relationship: [
872-
{
873-
...local,
874-
fields:
875-
local.ns === edit.ns &&
876-
JSON.stringify(local.fields) === JSON.stringify(edit.from)
877-
? edit.to
878-
: local.fields,
879-
},
880-
{
881-
...foreign,
882-
fields:
883-
local.ns === edit.ns &&
884-
JSON.stringify(local.fields) === JSON.stringify(edit.from)
885-
? edit.to
886-
: local.fields,
887-
},
888-
],
889-
};
890-
}),
891-
collections: model.collections.map((collection) => ({
892-
...collection,
893-
// TODO: Rename the field.
894-
// jsonSchema: collection.ns !== edit.ns
895-
// ? collection.jsonSchema
896-
// : renameFieldInSchema(collection.jsonSchema, edit.from, edit.to)
897-
})),
898-
};
899-
}
900839
case 'UpdateCollectionNote': {
901840
return {
902841
...model,

0 commit comments

Comments
 (0)