Check for local name clash with existing variables in Insert flow (#6375)
Check for local name alias clashes with extisting var in Insert flow Fixes #6230
This commit is contained in:
@ -220,6 +220,13 @@ export type CommandArgumentConfig<
|
||||
machineContext?: C
|
||||
) => OutputType)
|
||||
defaultValueFromContext?: (context: C) => OutputType
|
||||
validation?: ({
|
||||
data,
|
||||
context,
|
||||
}: {
|
||||
data: any
|
||||
context: CommandBarContext
|
||||
}) => Promise<boolean | string>
|
||||
}
|
||||
| {
|
||||
inputType: 'text'
|
||||
@ -343,6 +350,13 @@ export type CommandArgument<
|
||||
commandBarContext: ContextFrom<typeof commandBarMachine>,
|
||||
machineContext?: ContextFrom<T>
|
||||
) => OutputType)
|
||||
validation?: ({
|
||||
data,
|
||||
context,
|
||||
}: {
|
||||
data: any
|
||||
context: CommandBarContext
|
||||
}) => Promise<boolean | string>
|
||||
}
|
||||
| {
|
||||
inputType: 'path'
|
||||
|
||||
@ -211,6 +211,15 @@ export function buildCommandArgument<
|
||||
defaultValue: arg.defaultValue,
|
||||
...baseCommandArgument,
|
||||
} satisfies CommandArgument<O, T> & { inputType: 'kcl' }
|
||||
} else if (arg.inputType === 'string') {
|
||||
return {
|
||||
inputType: arg.inputType,
|
||||
defaultValue: arg.defaultValueFromContext
|
||||
? arg.defaultValueFromContext(context)
|
||||
: arg.defaultValue,
|
||||
validation: arg.validation,
|
||||
...baseCommandArgument,
|
||||
} satisfies CommandArgument<O, T> & { inputType: 'string' }
|
||||
} else {
|
||||
return {
|
||||
inputType: arg.inputType,
|
||||
|
||||
@ -133,6 +133,14 @@ export function kclCommands(commandProps: KclCommandConfig): Command[] {
|
||||
const path = context.argumentsToSubmit['path'] as string
|
||||
return getPathFilenameInVariableCase(path)
|
||||
},
|
||||
validation: async ({ data, context }) => {
|
||||
const variableExists = kclManager.variables[data.localName]
|
||||
if (variableExists) {
|
||||
return 'This variable name is already in use.'
|
||||
}
|
||||
|
||||
return true
|
||||
},
|
||||
},
|
||||
},
|
||||
onSubmit: (data) => {
|
||||
|
||||
Reference in New Issue
Block a user