Skip to content
Merged
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
92 changes: 70 additions & 22 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"@leafygreen-ui/marketing-modal": "^5.0.2",
"@leafygreen-ui/typography": "^20.0.2",
"@leafygreen-ui/icon": "^13.1.2",
"@leafygreen-ui/inline-definition": "^9.0.5",
"@leafygreen-ui/popover": "^13.0.11",
"@leafygreen-ui/badge": "^9.0.2",
"@leafygreen-ui/banner": "^10.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-data-modeling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@mongodb-js/compass-user-data": "^0.10.2",
"@mongodb-js/compass-utils": "^0.9.17",
"@mongodb-js/compass-workspaces": "^0.59.1",
"@mongodb-js/diagramming": "^1.5.1",
"@mongodb-js/diagramming": "^1.8.0",
"bson": "^6.10.4",
"compass-preferences-model": "^2.57.1",
"html-to-image": "1.11.11",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,11 @@ const DiagramContent: React.FunctionComponent<{
selectedItems?.type === 'field' && selectedItems.namespace === coll.ns
? selectedItems.fieldPath
: undefined,
onClickAddNewFieldToCollection: () =>
onAddNewFieldToCollection(coll.ns),
selected,
isInRelationshipDrawingMode,
});
});
}, [
onAddNewFieldToCollection,
model?.collections,
model?.relationships,
selectedItems,
Expand Down Expand Up @@ -319,6 +316,14 @@ const DiagramContent: React.FunctionComponent<{
[handleNodesConnect]
);

const onClickAddFieldToCollection = useCallback(
(event: React.MouseEvent<Element>, ns: string) => {
event.stopPropagation();
onAddNewFieldToCollection(ns);
},
[onAddNewFieldToCollection]
);

return (
<div
ref={setDiagramContainerRef}
Expand Down Expand Up @@ -355,6 +360,7 @@ const DiagramContent: React.FunctionComponent<{
fitViewOptions={ZOOM_OPTIONS}
onNodeDragStop={onNodeDragStop}
onConnect={onConnect}
onAddFieldToNodeClick={onClickAddFieldToCollection}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
import React from 'react';
import { expect } from 'chai';
import {
screen,
waitFor,
render,
userEvent,
} from '@mongodb-js/testing-library-compass';
import { getFieldsFromSchema } from './nodes-and-edges';

describe('getFieldsFromSchema', function () {
const validateMixedType = async (
type: React.ReactNode,
expectedTooltip: RegExp
) => {
render(<>{type}</>);
const mixed = screen.getByText('(mixed)');
expect(mixed).to.be.visible;
expect(screen.queryByText(expectedTooltip)).to.not.exist;
userEvent.hover(mixed);
await waitFor(() => {
expect(screen.getByText(expectedTooltip)).to.be.visible;
});
};

describe('flat schema', function () {
it('return empty array for empty schema', function () {
const result = getFieldsFromSchema({ jsonSchema: {} });
Expand Down Expand Up @@ -63,7 +42,7 @@ describe('getFieldsFromSchema', function () {
]);
});

it('returns mixed fields with tooltip on hover', async function () {
it('returns mixed fields', function () {
const result = getFieldsFromSchema({
jsonSchema: {
bsonType: 'object',
Expand All @@ -72,16 +51,16 @@ describe('getFieldsFromSchema', function () {
},
},
});
expect(result[0]).to.deep.include({
expect(result[0]).to.deep.equal({
name: 'age',
id: ['age'],
depth: 0,
glyphs: [],
selectable: true,
selected: false,
type: ['int', 'string'],
variant: undefined,
});
await validateMixedType(result[0].type, /int, string/);
});

it('highlights the correct field', function () {
Expand Down Expand Up @@ -445,32 +424,6 @@ describe('getFieldsFromSchema', function () {
]);
});

it('returns [] for array', function () {
const result = getFieldsFromSchema({
jsonSchema: {
bsonType: 'object',
properties: {
tags: {
bsonType: 'array',
items: { bsonType: 'string' },
},
},
},
});
expect(result).to.deep.equal([
{
name: 'tags',
id: ['tags'],
type: '[]',
depth: 0,
glyphs: [],
selectable: true,
selected: false,
variant: undefined,
},
]);
});

it('returns fields for an array of objects', function () {
const result = getFieldsFromSchema({
jsonSchema: {
Expand All @@ -493,7 +446,7 @@ describe('getFieldsFromSchema', function () {
{
name: 'todos',
id: ['todos'],
type: '[]',
type: 'array',
depth: 0,
glyphs: [],
selectable: true,
Expand Down Expand Up @@ -523,7 +476,7 @@ describe('getFieldsFromSchema', function () {
]);
});

it('returns fields for a mixed schema with objects', async function () {
it('returns fields for a mixed schema with objects', function () {
const result = getFieldsFromSchema({
jsonSchema: {
bsonType: 'object',
Expand All @@ -544,16 +497,16 @@ describe('getFieldsFromSchema', function () {
},
});
expect(result).to.have.lengthOf(3);
expect(result[0]).to.deep.include({
expect(result[0]).to.deep.equal({
name: 'name',
id: ['name'],
depth: 0,
type: ['string', 'object'],
glyphs: [],
selectable: true,
selected: false,
variant: undefined,
});
await validateMixedType(result[0].type, /string, object/);
expect(result[1]).to.deep.equal({
name: 'first',
id: ['name', 'first'],
Expand Down Expand Up @@ -603,7 +556,7 @@ describe('getFieldsFromSchema', function () {
{
name: 'todos',
id: ['todos'],
type: '[]',
type: 'array',
depth: 0,
glyphs: [],
selectable: true,
Expand Down
Loading
Loading