|
1 | 1 | import useI18n from '../../../../../../composables/useI18n'
|
2 | 2 | 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' |
4 | 5 | import type { ValidatorFn } from './basic'
|
5 | 6 | import { compose, notEmpty, stringFormat } from './basic'
|
6 | 7 |
|
@@ -51,12 +52,24 @@ export function isUniqueFieldName(
|
51 | 52 | }
|
52 | 53 | }
|
53 | 54 |
|
| 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 | + |
54 | 66 | export function useNodeNameValidator(nodeId: NodeId): ValidatorFn<string> {
|
55 | 67 | const { i18n: { t } } = useI18n()
|
56 | 68 | const errTempVars = { fieldName: t('plugins.free-form.datakit.flow_editor.node_properties.name') }
|
57 | 69 | return compose(
|
58 | 70 | notEmpty(errTempVars),
|
59 | 71 | stringFormat('identifier', errTempVars),
|
| 72 | + conflictWithImplicitNodes(), |
60 | 73 | isUniqueNodeName(nodeId, errTempVars),
|
61 | 74 | )
|
62 | 75 | }
|
|
0 commit comments