Skip to content

Commit 3cd9648

Browse files
authored
chore(data-modeling): bump diagramming, pass new options, remove related code (#7387)
1 parent 5afdf80 commit 3cd9648

File tree

6 files changed

+105
-160
lines changed

6 files changed

+105
-160
lines changed

package-lock.json

Lines changed: 70 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
"@leafygreen-ui/marketing-modal": "^5.0.2",
120120
"@leafygreen-ui/typography": "^20.0.2",
121121
"@leafygreen-ui/icon": "^13.1.2",
122+
"@leafygreen-ui/inline-definition": "^9.0.5",
122123
"@leafygreen-ui/popover": "^13.0.11",
123124
"@leafygreen-ui/badge": "^9.0.2",
124125
"@leafygreen-ui/banner": "^10.1.0",

packages/compass-data-modeling/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"@mongodb-js/compass-user-data": "^0.10.2",
6464
"@mongodb-js/compass-utils": "^0.9.17",
6565
"@mongodb-js/compass-workspaces": "^0.59.1",
66-
"@mongodb-js/diagramming": "^1.5.1",
66+
"@mongodb-js/diagramming": "^1.8.0",
6767
"bson": "^6.10.4",
6868
"compass-preferences-model": "^2.57.1",
6969
"html-to-image": "1.11.11",

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,11 @@ const DiagramContent: React.FunctionComponent<{
205205
selectedItems?.type === 'field' && selectedItems.namespace === coll.ns
206206
? selectedItems.fieldPath
207207
: undefined,
208-
onClickAddNewFieldToCollection: () =>
209-
onAddNewFieldToCollection(coll.ns),
210208
selected,
211209
isInRelationshipDrawingMode,
212210
});
213211
});
214212
}, [
215-
onAddNewFieldToCollection,
216213
model?.collections,
217214
model?.relationships,
218215
selectedItems,
@@ -319,6 +316,14 @@ const DiagramContent: React.FunctionComponent<{
319316
[handleNodesConnect]
320317
);
321318

319+
const onClickAddFieldToCollection = useCallback(
320+
(event: React.MouseEvent<Element>, ns: string) => {
321+
event.stopPropagation();
322+
onAddNewFieldToCollection(ns);
323+
},
324+
[onAddNewFieldToCollection]
325+
);
326+
322327
return (
323328
<div
324329
ref={setDiagramContainerRef}
@@ -355,6 +360,7 @@ const DiagramContent: React.FunctionComponent<{
355360
fitViewOptions={ZOOM_OPTIONS}
356361
onNodeDragStop={onNodeDragStop}
357362
onConnect={onConnect}
363+
onAddFieldToNodeClick={onClickAddFieldToCollection}
358364
/>
359365
</div>
360366
</div>

packages/compass-data-modeling/src/utils/nodes-and-edges.spec.tsx renamed to packages/compass-data-modeling/src/utils/nodes-and-edges.spec.ts

Lines changed: 8 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,7 @@
1-
import React from 'react';
21
import { expect } from 'chai';
3-
import {
4-
screen,
5-
waitFor,
6-
render,
7-
userEvent,
8-
} from '@mongodb-js/testing-library-compass';
92
import { getFieldsFromSchema } from './nodes-and-edges';
103

114
describe('getFieldsFromSchema', function () {
12-
const validateMixedType = async (
13-
type: React.ReactNode,
14-
expectedTooltip: RegExp
15-
) => {
16-
render(<>{type}</>);
17-
const mixed = screen.getByText('(mixed)');
18-
expect(mixed).to.be.visible;
19-
expect(screen.queryByText(expectedTooltip)).to.not.exist;
20-
userEvent.hover(mixed);
21-
await waitFor(() => {
22-
expect(screen.getByText(expectedTooltip)).to.be.visible;
23-
});
24-
};
25-
265
describe('flat schema', function () {
276
it('return empty array for empty schema', function () {
287
const result = getFieldsFromSchema({ jsonSchema: {} });
@@ -63,7 +42,7 @@ describe('getFieldsFromSchema', function () {
6342
]);
6443
});
6544

66-
it('returns mixed fields with tooltip on hover', async function () {
45+
it('returns mixed fields', function () {
6746
const result = getFieldsFromSchema({
6847
jsonSchema: {
6948
bsonType: 'object',
@@ -72,16 +51,16 @@ describe('getFieldsFromSchema', function () {
7251
},
7352
},
7453
});
75-
expect(result[0]).to.deep.include({
54+
expect(result[0]).to.deep.equal({
7655
name: 'age',
7756
id: ['age'],
7857
depth: 0,
7958
glyphs: [],
8059
selectable: true,
8160
selected: false,
61+
type: ['int', 'string'],
8262
variant: undefined,
8363
});
84-
await validateMixedType(result[0].type, /int, string/);
8564
});
8665

8766
it('highlights the correct field', function () {
@@ -445,32 +424,6 @@ describe('getFieldsFromSchema', function () {
445424
]);
446425
});
447426

448-
it('returns [] for array', function () {
449-
const result = getFieldsFromSchema({
450-
jsonSchema: {
451-
bsonType: 'object',
452-
properties: {
453-
tags: {
454-
bsonType: 'array',
455-
items: { bsonType: 'string' },
456-
},
457-
},
458-
},
459-
});
460-
expect(result).to.deep.equal([
461-
{
462-
name: 'tags',
463-
id: ['tags'],
464-
type: '[]',
465-
depth: 0,
466-
glyphs: [],
467-
selectable: true,
468-
selected: false,
469-
variant: undefined,
470-
},
471-
]);
472-
});
473-
474427
it('returns fields for an array of objects', function () {
475428
const result = getFieldsFromSchema({
476429
jsonSchema: {
@@ -493,7 +446,7 @@ describe('getFieldsFromSchema', function () {
493446
{
494447
name: 'todos',
495448
id: ['todos'],
496-
type: '[]',
449+
type: 'array',
497450
depth: 0,
498451
glyphs: [],
499452
selectable: true,
@@ -523,7 +476,7 @@ describe('getFieldsFromSchema', function () {
523476
]);
524477
});
525478

526-
it('returns fields for a mixed schema with objects', async function () {
479+
it('returns fields for a mixed schema with objects', function () {
527480
const result = getFieldsFromSchema({
528481
jsonSchema: {
529482
bsonType: 'object',
@@ -544,16 +497,16 @@ describe('getFieldsFromSchema', function () {
544497
},
545498
});
546499
expect(result).to.have.lengthOf(3);
547-
expect(result[0]).to.deep.include({
500+
expect(result[0]).to.deep.equal({
548501
name: 'name',
549502
id: ['name'],
550503
depth: 0,
504+
type: ['string', 'object'],
551505
glyphs: [],
552506
selectable: true,
553507
selected: false,
554508
variant: undefined,
555509
});
556-
await validateMixedType(result[0].type, /string, object/);
557510
expect(result[1]).to.deep.equal({
558511
name: 'first',
559512
id: ['name', 'first'],
@@ -603,7 +556,7 @@ describe('getFieldsFromSchema', function () {
603556
{
604557
name: 'todos',
605558
id: ['todos'],
606-
type: '[]',
559+
type: 'array',
607560
depth: 0,
608561
glyphs: [],
609562
selectable: true,

0 commit comments

Comments
 (0)