Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

# This Node.js version matches the one required in
# the "engines" in the package.json.
nodejs 22.21.1
nodejs 22.21.1
201 changes: 156 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/compass-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"@lg-chat/leafygreen-chat-provider": "^5.0.2",
"@lg-chat/message": "^8.2.0",
"@mongodb-js/compass-context-menu": "^0.3.1",
"@mongodb-js/diagramming": "^2.2.1",
"@mongodb-js/diagramming": "^2.3.0",
"@react-aria/interactions": "^3.9.1",
"@react-aria/utils": "^3.13.1",
"@react-aria/visually-hidden": "^3.3.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ const DiagramContent: React.FunctionComponent<{
!!selectedItems &&
selectedItems.type === 'relationship' &&
selectedItems.id === relationship.id;
return relationshipToDiagramEdge(relationship, selected, nodes);
return relationshipToDiagramEdge(relationship, selected);
});
}, [model?.relationships, selectedItems, nodes]);
}, [model?.relationships, selectedItems]);

// Fit to view on initial mount
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ async function getInitialLayout({
});
return await applyLayout({
nodes,
edges: relations.map((rel) => relationshipToDiagramEdge(rel, false, [])), // nodes are not important here
edges: relations.map((rel) => relationshipToDiagramEdge(rel, false)),
direction: hasRelations ? 'STAR' : 'RECTANGLE',
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
relationshipToDiagramEdge,
} from './nodes-and-edges';
import { type Relationship } from '../services/data-model-storage';
import { type NodeProps } from '@mongodb-js/compass-components';

describe('getFieldsFromSchema', function () {
describe('flat schema', function () {
Expand Down Expand Up @@ -699,77 +698,24 @@ describe('relationshipToDiagramEdge', function () {
note: 'Test relationship',
};

const node: NodeProps = {
id: relationship.relationship[0].ns!,
title: 'Collection A',
type: 'collection',
position: { x: 0, y: 0 },
fields: [],
};

it('should forward basic properties', function () {
const isSelected = true;
const edge = relationshipToDiagramEdge(relationship, isSelected, []);
const edge = relationshipToDiagramEdge(relationship, isSelected);
expect(edge.id).to.equal(relationship.id);
expect(edge.source).to.equal(relationship.relationship[0].ns);
expect(edge.target).to.equal(relationship.relationship[1].ns);
expect(edge.selected).to.equal(isSelected);
});

it('should map cardinality to markers', function () {
const edge = relationshipToDiagramEdge(relationship, false, []);
const edge = relationshipToDiagramEdge(relationship, false);
expect(edge.markerStart).to.equal('one');
expect(edge.markerEnd).to.equal('many');
});

it('should find field indices', function () {
const nodes: NodeProps[] = [
{
...node,
id: relationship.relationship[0].ns!,
fields: [
{
id: ['otherPath'],
name: 'fieldA', // same name but different path
type: 'string',
},
{
id: ['parent', 'otherField'], // same parent but different field
name: 'otherField',
type: 'string',
},
{
id: relationship.relationship[0].fields as string[],
name: 'fieldA',
type: 'string',
},
],
},
{
...node,
id: relationship.relationship[1].ns!,
fields: [
{
id: ['otherPath'],
name: 'fieldB', // same name but different path
type: 'string',
},
{
id: relationship.relationship[1].fields as string[],
name: 'fieldB',
type: 'string',
},
{
id: ['otherParent', 'otherField'], // same parent but different field
name: 'otherField',
type: 'string',
},
],
},
];

const edge = relationshipToDiagramEdge(relationship, false, nodes);
expect(edge.sourceFieldIndex).to.equal(2);
expect(edge.targetFieldIndex).to.equal(1);
it('should map field ids', function () {
const edge = relationshipToDiagramEdge(relationship, false);
expect(edge.sourceFieldId).to.equal(relationship.relationship[0].fields);
expect(edge.targetFieldId).to.equal(relationship.relationship[1].fields);
});
});
Loading
Loading