Skip to content

Commit 2040a80

Browse files
committed
feat: MoveCollection COMPASS-9434
1 parent 539c383 commit 2040a80

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { DataModelingState } from '../store/reducer';
1111
import {
1212
applyEdit,
1313
applyInitialLayout,
14+
moveCollection,
1415
getCurrentDiagramFromState,
1516
selectCurrentModel,
1617
} from '../store/diagram';
@@ -153,6 +154,7 @@ const DiagramEditor: React.FunctionComponent<{
153154
onCancelClick: () => void;
154155
onApplyClick: (edit: Omit<Edit, 'id' | 'timestamp'>) => void;
155156
onApplyInitialLayout: (positions: Record<string, [number, number]>) => void;
157+
onMoveCollection: (ns: string, newPosition: [number, number]) => void;
156158
}> = ({
157159
diagramLabel,
158160
step,
@@ -162,6 +164,7 @@ const DiagramEditor: React.FunctionComponent<{
162164
onCancelClick,
163165
onApplyClick,
164166
onApplyInitialLayout,
167+
onMoveCollection,
165168
}) => {
166169
const { log, mongoLogId } = useLogger('COMPASS-DATA-MODELING-DIAGRAM-EDITOR');
167170
const isDarkMode = useDarkMode();
@@ -357,6 +360,9 @@ const DiagramEditor: React.FunctionComponent<{
357360
maxZoom: 1,
358361
minZoom: 0.25,
359362
}}
363+
onNodeDragStop={(evt, node) => {
364+
onMoveCollection(node.id, [node.position.x, node.position.y]);
365+
}}
360366
onEdgeClick={(evt, edge) => {
361367
setApplyInput(
362368
JSON.stringify(
@@ -436,5 +442,6 @@ export default connect(
436442
onCancelClick: cancelAnalysis,
437443
onApplyClick: applyEdit,
438444
onApplyInitialLayout: applyInitialLayout,
445+
onMoveCollection: moveCollection,
439446
}
440447
)(DiagramEditor);

packages/compass-data-modeling/src/services/data-model-storage.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ const EditSchemaVariants = z.discriminatedUnion('type', [
5555
type: z.literal('RemoveRelationship'),
5656
relationshipId: z.string().uuid(),
5757
}),
58+
z.object({
59+
type: z.literal('MoveCollection'),
60+
ns: z.string(),
61+
newPosition: z.tuple([z.number(), z.number()]),
62+
}),
5863
]);
5964

6065
export const EditSchema = z.intersection(EditSchemaBase, EditSchemaVariants);

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,23 @@ export function redoEdit(): DataModelingThunkAction<void, RedoEditAction> {
260260
};
261261
}
262262

263+
export function moveCollection(
264+
ns: string,
265+
newPosition: [number, number]
266+
): DataModelingThunkAction<void, ApplyEditAction | ApplyEditFailedAction> {
267+
return (dispatch) => {
268+
const edit: Omit<
269+
Extract<Edit, { type: 'MoveCollection' }>,
270+
'id' | 'timestamp'
271+
> = {
272+
type: 'MoveCollection',
273+
ns,
274+
newPosition,
275+
};
276+
dispatch(applyEdit(edit));
277+
};
278+
}
279+
263280
export function applyEdit(
264281
rawEdit: Omit<Edit, 'id' | 'timestamp'>
265282
): DataModelingThunkAction<void, ApplyEditAction | ApplyEditFailedAction> {
@@ -367,6 +384,20 @@ function _applyEdit(edit: Edit, model?: StaticModel): StaticModel {
367384
),
368385
};
369386
}
387+
case 'MoveCollection': {
388+
return {
389+
...model,
390+
collections: model.collections.map((collection) => {
391+
if (collection.ns === edit.ns) {
392+
return {
393+
...collection,
394+
displayPosition: edit.newPosition,
395+
};
396+
}
397+
return collection;
398+
}),
399+
};
400+
}
370401
default: {
371402
return model;
372403
}

0 commit comments

Comments
 (0)