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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
deleteCollection,
deleteRelationship,
removeField,
renameField,
} from '../store/diagram';
import type {
EdgeProps,
Expand Down Expand Up @@ -143,6 +144,11 @@ const DiagramContent: React.FunctionComponent<{
onCollectionSelect: (namespace: string) => void;
onRelationshipSelect: (rId: string) => void;
onFieldSelect: (namespace: string, fieldPath: FieldPath) => void;
onRenameField: (
namespace: string,
fieldPath: FieldPath,
newName: string
) => void;
onDiagramBackgroundClicked: () => void;
onDeleteCollection: (ns: string) => void;
onDeleteRelationship: (rId: string) => void;
Expand Down Expand Up @@ -170,6 +176,7 @@ const DiagramContent: React.FunctionComponent<{
onCollectionSelect,
onRelationshipSelect,
onFieldSelect,
onRenameField,
onDiagramBackgroundClicked,
onCreateNewRelationship,
onRelationshipDrawn,
Expand Down Expand Up @@ -385,6 +392,7 @@ const DiagramContent: React.FunctionComponent<{
onPaneClick,
onEdgeClick,
onFieldClick,
onFieldNameChange: onRenameField,
onNodeDragStop,
onConnect,
} satisfies DiagramProps),
Expand All @@ -399,6 +407,7 @@ const DiagramContent: React.FunctionComponent<{
onPaneClick,
onEdgeClick,
onFieldClick,
onRenameField,
onNodeDragStop,
onConnect,
]
Expand Down Expand Up @@ -461,6 +470,7 @@ const ConnectedDiagramContent = connect(
onCollectionSelect: selectCollection,
onRelationshipSelect: selectRelationship,
onFieldSelect: selectField,
onRenameField: renameField,
onDiagramBackgroundClicked: selectBackground,
onCreateNewRelationship: createNewRelationship,
onDeleteCollection: deleteCollection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,29 @@ describe('getFieldsFromSchema', function () {
expect(result).to.deep.equal([]);
});

it('returns fields for a simple schema', function () {
it('returns fields for a simple schema, with non editable _id', function () {
const result = getFieldsFromSchema({
jsonSchema: {
bsonType: 'object',
properties: {
_id: { bsonType: 'objectId' },
name: { bsonType: 'string' },
age: { bsonType: 'int' },
},
},
});
expect(result).to.deep.equal([
{
name: '_id',
id: ['_id'],
type: 'objectId',
depth: 0,
glyphs: ['key'],
selectable: true,
selected: false,
variant: undefined,
editable: false,
},
{
name: 'name',
id: ['name'],
Expand All @@ -33,6 +45,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'age',
Expand All @@ -43,6 +56,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
]);
});
Expand All @@ -65,6 +79,7 @@ describe('getFieldsFromSchema', function () {
selected: false,
type: ['int', 'string'],
variant: undefined,
editable: true,
});
});

Expand All @@ -90,6 +105,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'age',
Expand All @@ -100,6 +116,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: 'preview',
editable: true,
},
{
name: 'profession',
Expand All @@ -110,6 +127,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
]);
});
Expand All @@ -136,6 +154,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'age',
Expand All @@ -146,6 +165,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: 'preview',
editable: true,
},
{
name: 'profession',
Expand All @@ -156,6 +176,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: 'preview',
editable: true,
},
]);
});
Expand Down Expand Up @@ -193,6 +214,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'name',
Expand All @@ -203,6 +225,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'address',
Expand All @@ -213,6 +236,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'street',
Expand All @@ -223,6 +247,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'city',
Expand All @@ -233,6 +258,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
]);
});
Expand Down Expand Up @@ -269,6 +295,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'name',
Expand All @@ -279,6 +306,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'address',
Expand All @@ -289,6 +317,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'street',
Expand All @@ -299,6 +328,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: 'preview',
editable: true,
},
{
name: 'city',
Expand All @@ -309,6 +339,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
]);
});
Expand Down Expand Up @@ -355,6 +386,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'name',
Expand All @@ -365,6 +397,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'address',
Expand All @@ -375,6 +408,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'street',
Expand All @@ -385,6 +419,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: 'preview',
editable: true,
},
{
name: 'city',
Expand All @@ -395,6 +430,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'billingAddress',
Expand All @@ -405,6 +441,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'street',
Expand All @@ -415,6 +452,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'city',
Expand All @@ -425,6 +463,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: 'preview',
editable: true,
},
]);
});
Expand Down Expand Up @@ -457,6 +496,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'title',
Expand All @@ -467,6 +507,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'completed',
Expand All @@ -477,6 +518,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
]);
});
Expand Down Expand Up @@ -511,6 +553,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
});
expect(result[1]).to.deep.equal({
name: 'first',
Expand All @@ -521,6 +564,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
});
expect(result[2]).to.deep.equal({
name: 'last',
Expand All @@ -531,6 +575,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
});
});

Expand Down Expand Up @@ -567,6 +612,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'title',
Expand All @@ -577,6 +623,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
{
name: 'completed',
Expand All @@ -587,6 +634,7 @@ describe('getFieldsFromSchema', function () {
selectable: true,
selected: false,
variant: undefined,
editable: true,
},
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
Relationship,
} from '../services/data-model-storage';
import { traverseSchema } from './schema-traversal';
import { areFieldPathsEqual } from './utils';
import { areFieldPathsEqual, isIdField } from './utils';

const NO_HIGHLIGHTED_FIELDS = {};

Expand Down Expand Up @@ -100,6 +100,7 @@ export const getFieldsFromSchema = ({
selected:
!!selectedField?.length &&
areFieldPathsEqual(fieldPath, selectedField),
editable: !isIdField(fieldPath),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we want to exclude _id from edits? We obviously can't do that for individual documents, but as a data modeling operation, it kind of seems fine/like something that one would actually want to do

Copy link
Collaborator Author

@paula-stacho paula-stacho Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure.. would we then need to go into validating the collection and highlighting if it's missing _id because it was renamed? I'd rather wait if we get requests for this. On the other hand, changing the type might be a valid use-case, especially because we create this field automatically for a new collection 🤔 .

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment this is in line with the sidebar behaviour (_id is readonly there too), but I'll bring this to the channel and let's discuss

variant:
highlightedFields.length &&
highlightedFields.some((highlightedField) =>
Expand Down
Loading
Loading