Skip to content

Commit 223a1cb

Browse files
authored
feat(entities-plugins): datakit - reserved node name check [KM-1617] (#2366)
1 parent 9e96dca commit 223a1cb

File tree

2 files changed

+16
-2
lines changed
  • packages/entities/entities-plugins/src

2 files changed

+16
-2
lines changed

packages/entities/entities-plugins/src/components/free-form/Datakit/flow-editor/composables/validation/business.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import useI18n from '../../../../../../composables/useI18n'
22
import { useEditorStore } from '../../../composables'
3-
import type { FieldId, FieldName, NodeId, NodeInstance } from '../../../types'
3+
import type { FieldId, FieldName, NodeId, NodeInstance, NodeName } from '../../../types'
4+
import { isImplicitName } from '../../node/node'
45
import type { ValidatorFn } from './basic'
56
import { compose, notEmpty, stringFormat } from './basic'
67

@@ -51,12 +52,24 @@ export function isUniqueFieldName(
5152
}
5253
}
5354

55+
function conflictWithImplicitNodes(): ValidatorFn<string> {
56+
const { i18n: { t } } = useI18n()
57+
58+
return function validateConflictWithImplicitNodes(nodeName): undefined | string {
59+
if (isImplicitName(nodeName as NodeName)) {
60+
return t('plugins.free-form.datakit.flow_editor.node_properties.errors.reserved_node_name', { nodeName })
61+
}
62+
return undefined
63+
}
64+
}
65+
5466
export function useNodeNameValidator(nodeId: NodeId): ValidatorFn<string> {
5567
const { i18n: { t } } = useI18n()
5668
const errTempVars = { fieldName: t('plugins.free-form.datakit.flow_editor.node_properties.name') }
5769
return compose(
5870
notEmpty(errTempVars),
5971
stringFormat('identifier', errTempVars),
72+
conflictWithImplicitNodes(),
6073
isUniqueNodeName(nodeId, errTempVars),
6174
)
6275
}

packages/entities/entities-plugins/src/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,8 @@
770770
"not_number": "{fieldName} must be a number",
771771
"not_unique": "{fieldName} must be unique",
772772
"number_range": "{fieldName} must be between {min} and {max}",
773-
"string_len_range": "{fieldName} must be between {min} and {max} characters"
773+
"string_len_range": "{fieldName} must be between {min} and {max} characters",
774+
"reserved_node_name": "\"{nodeName}\" is a reserved node name"
774775
}
775776
}
776777
},

0 commit comments

Comments
 (0)