Skip to content

Commit 9476583

Browse files
authored
chore(data-modeling): refactor data modeling to calculate layout as part of the analysis COMPASS-9487 (#7145)
* chore(data-modeling): refactor data modeling to layout as part of the analysis * chore(data-modeling): fix _diagram setter
1 parent 50fa2d6 commit 9476583

File tree

8 files changed

+353
-415
lines changed

8 files changed

+353
-415
lines changed

packages/compass-components/src/components/drawer-portal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,10 @@ export { DrawerDisplayMode };
296296
export function useDrawerActions() {
297297
const actions = useContext(DrawerActionsContext);
298298
const stableActions = useRef({
299-
openDrawer(id: string) {
299+
openDrawer: (id: string) => {
300300
actions.current.openDrawer(id);
301301
},
302-
closeDrawer() {
302+
closeDrawer: () => {
303303
actions.current.closeDrawer();
304304
},
305305
});

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

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
render,
88
userEvent,
99
} from '@mongodb-js/testing-library-compass';
10-
import DiagramEditor, { getFieldsFromSchema } from './diagram-editor';
10+
import DiagramEditor from './diagram-editor';
1111
import type { DataModelingStore } from '../../test/setup-store';
1212
import type {
1313
Edit,
@@ -18,6 +18,7 @@ import sinon from 'sinon';
1818
import { DiagramProvider } from '@mongodb-js/diagramming';
1919
import { DataModelingWorkspaceTab } from '..';
2020
import { openDiagram } from '../store/diagram';
21+
import { getFieldsFromSchema } from '../utils/nodes-and-edges';
2122

2223
const storageItems: MongoDBDataModelDescription[] = [
2324
{
@@ -68,14 +69,14 @@ const storageItems: MongoDBDataModelDescription[] = [
6869
{
6970
ns: 'db1.collection1',
7071
indexes: [],
71-
displayPosition: [NaN, NaN],
72+
displayPosition: [0, 0],
7273
shardKey: {},
7374
jsonSchema: { bsonType: 'object' },
7475
},
7576
{
7677
ns: 'db1.collection2',
7778
indexes: [],
78-
displayPosition: [NaN, NaN],
79+
displayPosition: [0, 0],
7980
shardKey: {},
8081
jsonSchema: { bsonType: 'object' },
8182
},
@@ -165,37 +166,6 @@ describe('DiagramEditor', function () {
165166
.callsFake(mockDiagramming.applyLayout as any);
166167
});
167168

168-
context('with initial diagram', function () {
169-
beforeEach(async function () {
170-
const result = renderDiagramEditor({
171-
renderedItem: storageItems[1],
172-
});
173-
store = result.store;
174-
175-
// wait till the editor is loaded
176-
await waitFor(() => {
177-
expect(screen.getByTestId('model-preview')).to.be.visible;
178-
});
179-
});
180-
181-
it('applies the initial layout to unpositioned nodes', function () {
182-
const state = store.getState();
183-
184-
expect(state.diagram?.edits.current).to.have.lengthOf(1);
185-
expect(state.diagram?.edits.current[0].type).to.equal('SetModel');
186-
const initialEdit = state.diagram?.edits.current[0] as Extract<
187-
Edit,
188-
{ type: 'SetModel' }
189-
>;
190-
expect(initialEdit.model?.collections[0].displayPosition).to.deep.equal([
191-
100, 100,
192-
]);
193-
expect(initialEdit.model?.collections[1].displayPosition).to.deep.equal([
194-
200, 200,
195-
]);
196-
});
197-
});
198-
199169
context('with existing diagram', function () {
200170
beforeEach(async function () {
201171
const result = renderDiagramEditor({

0 commit comments

Comments
 (0)