Skip to content

Commit 0021612

Browse files
committed
cleanup
1 parent cd89210 commit 0021612

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
@@ -235,8 +235,8 @@ const DiagramContent: React.FunctionComponent<{
235235
openDrawer(DATA_MODELING_DRAWER_ID);
236236
}}
237237
onFieldClick={(_evt, { id: fieldPath, nodeId: namespace }) => {
238-
_evt.stopPropagation(); // TODO: should this be handled by the diagramming package?
239-
if (!Array.isArray(fieldPath)) return; // TODO: could be avoided with generics in the diagramming package
238+
_evt.stopPropagation(); // TODO(COMPASS-9659): should this be handled by the diagramming package?
239+
if (!Array.isArray(fieldPath)) return; // TODO(COMPASS-9659): could be avoided with generics in the diagramming package
240240
onFieldSelect(namespace, fieldPath);
241241
openDrawer(DATA_MODELING_DRAWER_ID);
242242
}}

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
@@ -440,29 +440,6 @@ export function renameCollection(
440440
};
441441
}
442442

443-
export function renameField(
444-
ns: string,
445-
from: FieldPath,
446-
to: FieldPath
447-
): DataModelingThunkAction<
448-
void,
449-
ApplyEditAction | ApplyEditFailedAction | CollectionSelectedAction
450-
> {
451-
return (dispatch) => {
452-
const edit: Omit<
453-
Extract<Edit, { type: 'RenameField' }>,
454-
'id' | 'timestamp'
455-
> = {
456-
type: 'RenameField',
457-
ns,
458-
from,
459-
to,
460-
};
461-
462-
dispatch(applyEdit(edit));
463-
};
464-
}
465-
466443
export function applyEdit(
467444
rawEdit: EditAction
468445
): DataModelingThunkAction<boolean, ApplyEditAction | ApplyEditFailedAction> {
@@ -703,44 +680,6 @@ function _applyEdit(edit: Edit, model?: StaticModel): StaticModel {
703680
})),
704681
};
705682
}
706-
case 'RenameField': {
707-
return {
708-
...model,
709-
// Update relationships to point to the renamed field.
710-
relationships: model.relationships.map((relationship) => {
711-
const [local, foreign] = relationship.relationship;
712-
713-
return {
714-
...relationship,
715-
relationship: [
716-
{
717-
...local,
718-
fields:
719-
local.ns === edit.ns &&
720-
JSON.stringify(local.fields) === JSON.stringify(edit.from)
721-
? edit.to
722-
: local.fields,
723-
},
724-
{
725-
...foreign,
726-
fields:
727-
local.ns === edit.ns &&
728-
JSON.stringify(local.fields) === JSON.stringify(edit.from)
729-
? edit.to
730-
: local.fields,
731-
},
732-
],
733-
};
734-
}),
735-
collections: model.collections.map((collection) => ({
736-
...collection,
737-
// TODO: Rename the field.
738-
// jsonSchema: collection.ns !== edit.ns
739-
// ? collection.jsonSchema
740-
// : renameFieldInSchema(collection.jsonSchema, edit.from, edit.to)
741-
})),
742-
};
743-
}
744683
case 'UpdateCollectionNote': {
745684
return {
746685
...model,

0 commit comments

Comments
 (0)