Skip to content

Commit d544de3

Browse files
authored
chore(data-modeling, components): move diagramming package to compass-component to dedupe leafygreen deps (#7449)
* chore(data-modeling, components): move diagramming package to compass-component to dedupe leafygreen deps * chore(components): named exports instead of one namespace export * chore(components): remove namespace export
1 parent 97fe8ce commit d544de3

File tree

13 files changed

+105
-467
lines changed

13 files changed

+105
-467
lines changed

package-lock.json

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

packages/compass-components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"@lg-chat/suggestions": "^0.2.3",
9999
"@lg-chat/title-bar": "^4.0.7",
100100
"@mongodb-js/compass-context-menu": "^0.2.13",
101+
"@mongodb-js/diagramming": "^1.8.0",
101102
"@react-aria/interactions": "^3.9.1",
102103
"@react-aria/utils": "^3.13.1",
103104
"@react-aria/visually-hidden": "^3.3.1",

packages/compass-components/src/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,19 @@ export { ParagraphSkeleton } from '@leafygreen-ui/skeleton-loader';
229229
export { InsightsChip } from './components/insights-chip';
230230
export * from './components/drawer-portal';
231231
export { FileSelector } from './components/file-selector';
232+
export {
233+
DiagramProvider,
234+
Diagram,
235+
useDiagram,
236+
getNodesBounds,
237+
getViewportForBounds,
238+
applyLayout,
239+
getCoordinatesForNewNode,
240+
} from '@mongodb-js/diagramming';
241+
export type {
242+
EdgeProps,
243+
NodeProps,
244+
DiagramInstance,
245+
NodeField,
246+
NodeGlyph,
247+
} from '@mongodb-js/diagramming';

packages/compass-data-modeling/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"@mongodb-js/compass-user-data": "^0.10.4",
6464
"@mongodb-js/compass-utils": "^0.9.19",
6565
"@mongodb-js/compass-workspaces": "^0.61.0",
66-
"@mongodb-js/diagramming": "^1.8.0",
6766
"bson": "^6.10.4",
6867
"compass-preferences-model": "^2.59.0",
6968
"html-to-image": "1.11.11",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import DiagramEditor from './diagram-editor';
44
import SavedDiagramsList from './saved-diagrams-list';
55
import NewDiagramFormModal from './new-diagram-form';
66
import type { DataModelingState } from '../store/reducer';
7-
import { DiagramProvider } from '@mongodb-js/diagramming';
7+
import { DiagramProvider } from '@mongodb-js/compass-components';
88
import DiagramEditorSidePanel from './drawer/diagram-editor-side-panel';
99

1010
type DataModelingProps = {

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ import type {
1414
Edit,
1515
MongoDBDataModelDescription,
1616
} from '../services/data-model-storage';
17-
import diagramming from '@mongodb-js/diagramming';
18-
import sinon from 'sinon';
19-
import { DiagramProvider } from '@mongodb-js/diagramming';
2017
import { DataModelingWorkspaceTab } from '..';
2118
import { openDiagram } from '../store/diagram';
22-
import { DrawerAnchor } from '@mongodb-js/compass-components';
19+
import { DrawerAnchor, DiagramProvider } from '@mongodb-js/compass-components';
2320
import { type AnalysisOptions, startAnalysis } from '../store/analysis-process';
2421
import type { DataService } from '@mongodb-js/compass-connections/provider';
2522

@@ -167,7 +164,11 @@ const renderDiagramEditor = async ({
167164
} = await renderWithActiveConnection(
168165
<DrawerAnchor>
169166
<DiagramProvider fitView>
170-
<DiagramEditor />
167+
<DiagramEditor
168+
// We need to stub the Diagram component because the imported one is
169+
// not bundled for CJS correctly and will throw on render
170+
DiagramComponent={mockDiagramming.Diagram}
171+
/>
171172
</DiagramProvider>
172173
</DrawerAnchor>,
173174
mockConnections[0],
@@ -206,14 +207,6 @@ const renderDiagramEditor = async ({
206207
describe('DiagramEditor', function () {
207208
let store: DataModelingStore;
208209

209-
before(function () {
210-
// We need to tub the Diagram import because it has problems with ESM/CJS interop
211-
sinon.stub(diagramming, 'Diagram').callsFake(mockDiagramming.Diagram);
212-
sinon
213-
.stub(diagramming, 'applyLayout')
214-
.callsFake(mockDiagramming.applyLayout as any);
215-
});
216-
217210
context('with existing diagram', function () {
218211
beforeEach(async function () {
219212
const result = await renderDiagramEditor({

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
addCollection,
2121
selectField,
2222
} from '../store/diagram';
23+
import type { EdgeProps, NodeProps } from '@mongodb-js/compass-components';
2324
import {
2425
Banner,
2526
CancelLoader,
@@ -32,14 +33,10 @@ import {
3233
useDrawerState,
3334
useThrottledProps,
3435
rafraf,
35-
} from '@mongodb-js/compass-components';
36-
import { cancelAnalysis, retryAnalysis } from '../store/analysis-process';
37-
import {
3836
Diagram,
39-
type NodeProps,
40-
type EdgeProps,
4137
useDiagram,
42-
} from '@mongodb-js/diagramming';
38+
} from '@mongodb-js/compass-components';
39+
import { cancelAnalysis, retryAnalysis } from '../store/analysis-process';
4340
import type { FieldPath, StaticModel } from '../services/data-model-storage';
4441
import DiagramEditorToolbar from './diagram-editor-toolbar';
4542
import ExportDiagramModal from './export-diagram-modal';
@@ -149,6 +146,7 @@ const DiagramContent: React.FunctionComponent<{
149146
foreignNamespace: string;
150147
}) => void;
151148
onRelationshipDrawn: () => void;
149+
DiagramComponent?: typeof Diagram;
152150
}> = ({
153151
diagramLabel,
154152
database,
@@ -166,6 +164,7 @@ const DiagramContent: React.FunctionComponent<{
166164
onCreateNewRelationship,
167165
onRelationshipDrawn,
168166
selectedItems,
167+
DiagramComponent = Diagram,
169168
}) => {
170169
const isDarkMode = useDarkMode();
171170
const diagram = useRef(useDiagram());
@@ -389,7 +388,7 @@ const DiagramContent: React.FunctionComponent<{
389388
impact your data
390389
</Banner>
391390
)}
392-
<Diagram
391+
<DiagramComponent
393392
{...throttledDiagramProps}
394393
// With threshold too low clicking sometimes gets confused with
395394
// dragging.
@@ -434,12 +433,14 @@ const DiagramEditor: React.FunctionComponent<{
434433
onRetryClick: () => void;
435434
onCancelClick: () => void;
436435
onAddCollectionClick: () => void;
436+
DiagramComponent?: typeof Diagram;
437437
}> = ({
438438
step,
439439
diagramId,
440440
onRetryClick,
441441
onCancelClick,
442442
onAddCollectionClick,
443+
DiagramComponent = Diagram,
443444
}) => {
444445
const { openDrawer } = useDrawerActions();
445446
let content;
@@ -499,6 +500,7 @@ const DiagramEditor: React.FunctionComponent<{
499500
key={diagramId}
500501
isInRelationshipDrawingMode={isInRelationshipDrawingMode}
501502
onRelationshipDrawn={onRelationshipDrawn}
503+
DiagramComponent={DiagramComponent}
502504
></ConnectedDiagramContent>
503505
);
504506
}

packages/compass-data-modeling/src/components/export-diagram-modal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import type { DiagramInstance } from '@mongodb-js/compass-components';
23
import {
34
Button,
45
css,
@@ -13,6 +14,7 @@ import {
1314
spacing,
1415
SpinLoader,
1516
PngIcon,
17+
useDiagram,
1618
} from '@mongodb-js/compass-components';
1719
import type { ExportDiagramFormat } from '../store/export-diagram';
1820
import {
@@ -22,8 +24,6 @@ import {
2224
} from '../store/export-diagram';
2325
import { connect } from 'react-redux';
2426
import type { DataModelingState } from '../store/reducer';
25-
import { useDiagram } from '@mongodb-js/diagramming';
26-
import type { DiagramInstance } from '@mongodb-js/diagramming';
2727

2828
const modelBodyStyles = css({
2929
paddingTop: spacing[600],

packages/compass-data-modeling/src/services/export-diagram.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import React from 'react';
2-
import {
3-
getNodesBounds,
4-
getViewportForBounds,
5-
DiagramProvider,
6-
Diagram,
7-
} from '@mongodb-js/diagramming';
8-
import type { DiagramInstance } from '@mongodb-js/diagramming';
92
import type { StaticModel } from './data-model-storage';
103
import ReactDOM from 'react-dom';
114
import { toPng } from 'html-to-image';
12-
import { rafraf, spacing } from '@mongodb-js/compass-components';
5+
import type { DiagramInstance } from '@mongodb-js/compass-components';
6+
import {
7+
rafraf,
8+
spacing,
9+
Diagram,
10+
DiagramProvider,
11+
getNodesBounds,
12+
getViewportForBounds,
13+
} from '@mongodb-js/compass-components';
1314
import { raceWithAbort } from '@mongodb-js/compass-utils';
1415

1516
function moveSvgDefsToViewportElement(

packages/compass-data-modeling/src/store/analysis-process.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { analyzeDocuments, type MongoDBJSONSchema } from 'mongodb-schema';
55
import { getCurrentDiagramFromState } from './diagram';
66
import { UUID } from 'bson';
77
import type { Relationship } from '../services/data-model-storage';
8-
import { applyLayout } from '@mongodb-js/diagramming';
8+
import { applyLayout } from '@mongodb-js/compass-components';
99
import { collectionToBaseNodeForLayout } from '../utils/nodes-and-edges';
1010
import { inferForeignToLocalRelationshipsForCollection } from './relationships';
1111
import { mongoLogId } from '@mongodb-js/compass-logging/provider';

0 commit comments

Comments
 (0)