Skip to content

Commit eb716a9

Browse files
committed
restrict idField
1 parent c5b4f14 commit eb716a9

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { getDefaultRelationshipName } from '../../utils';
2020
import FieldDrawerContent from './field-drawer-content';
2121
import type { FieldPath } from '../../services/data-model-storage';
2222
import { getFieldFromSchema } from '../../utils/schema-traversal';
23+
import { isIdField } from '../../utils/utils';
2324

2425
export const DATA_MODELING_DRAWER_ID = 'data-modeling-drawer';
2526

@@ -110,11 +111,15 @@ function DiagramEditorSidePanel({
110111
></FieldDrawerContent>
111112
),
112113
actions: [
113-
{
114-
action: 'delete',
115-
label: 'Delete Field',
116-
icon: 'Trash' as const,
117-
},
114+
...(!isIdField(selectedItems.fieldPath)
115+
? [
116+
{
117+
action: 'delete',
118+
label: 'Delete Field',
119+
icon: 'Trash' as const,
120+
},
121+
]
122+
: []),
118123
],
119124
handleAction: (actionName: string) => {
120125
if (actionName === 'delete') {

packages/compass-data-modeling/src/components/drawer/field-drawer-content.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ import {
2626
import { useChangeOnBlur } from './use-change-on-blur';
2727
import { RelationshipsSection } from './relationships-section';
2828
import { getFieldFromSchema } from '../../utils/schema-traversal';
29-
import { areFieldPathsEqual, isRelationshipOfAField } from '../../utils/utils';
29+
import {
30+
areFieldPathsEqual,
31+
isIdField,
32+
isRelationshipOfAField,
33+
} from '../../utils/utils';
3034

3135
type FieldDrawerContentProps = {
3236
namespace: string;
@@ -138,6 +142,7 @@ const FieldDrawerContent: React.FunctionComponent<FieldDrawerContentProps> = ({
138142
<DMFormFieldContainer>
139143
<TextInput
140144
label="Field name"
145+
disabled={isIdField(fieldPath)}
141146
data-testid="data-model-collection-drawer-name-input"
142147
sizeVariant="small"
143148
value={fieldName}

packages/compass-data-modeling/src/utils/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import type { FieldPath, Relationship } from '../services/data-model-storage';
22

3+
export const isIdField = (fieldPath: FieldPath): boolean =>
4+
fieldPath.length === 1 && fieldPath[0] === '_id';
5+
36
export function areFieldPathsEqual(
47
fieldA: FieldPath,
58
fieldB: FieldPath

0 commit comments

Comments
 (0)