Compare commits

...

3 Commits

5 changed files with 29 additions and 10 deletions

View File

@ -352,13 +352,12 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
selectionTypes: ['cap', 'wall'],
multiple: true,
required: true,
validation: shellValidator,
},
thickness: {
inputType: 'kcl',
defaultValue: KCL_DEFAULT_LENGTH,
required: true,
// TODO: add dry-run validation on thickness param
validation: shellValidator,
},
},
},

View File

@ -3,6 +3,7 @@ import { engineCommandManager } from 'lib/singletons'
import { uuidv4 } from 'lib/utils'
import { CommandBarContext } from 'machines/commandBarMachine'
import { Selections } from 'lib/selections'
import { KclCommandValue } from 'lib/commandTypes'
import { ApiError_type } from '@kittycad/lib/dist/types/src/models'
export const disableDryRunWithRetry = async (numberOfRetries = 3) => {
@ -171,16 +172,21 @@ export const loftValidator = async ({
}
export const shellValidator = async ({
context,
data,
}: {
data: { selection: Selections }
context: CommandBarContext
data: { thickness: KclCommandValue }
}): Promise<boolean | string> => {
if (!isSelections(data.selection)) {
const thicknessArg = data.thickness
const selectionArg = context.argumentsToSubmit['selection'] as Selections
if (!isSelections(selectionArg)) {
return 'Unable to shell, selections are missing'
}
// No validation on the faces, filtering is done upstream and we have the dry run validation just below
const face_ids = data.selection.graphSelections.flatMap((s) =>
// No validation on the args, filtering is done upstream and we have the dry run validation just below
const shell_thickness = Number(thicknessArg.valueCalculated)
const face_ids = selectionArg.graphSelections.flatMap((s) =>
s.artifact ? s.artifact.id : []
)
@ -197,14 +203,12 @@ export const shellValidator = async ({
}
const command = async () => {
// TODO: figure out something better than an arbitrarily small value
const DEFAULT_THICKNESS: Models['LengthUnit_type'] = 1e-9
const DEFAULT_HOLLOW = false
const cmdArgs = {
face_ids,
object_id,
shell_thickness,
hollow: DEFAULT_HOLLOW,
shell_thickness: DEFAULT_THICKNESS,
}
return await engineCommandManager.sendSceneCommand({
type: 'modeling_cmd_req',

View File

@ -171,6 +171,13 @@ export type CommandArgumentConfig<
commandBarContext: ContextFrom<typeof commandBarMachine>,
machineContext?: C
) => string)
validation?: ({
data,
context,
}: {
data: any
context: CommandBarContext
}) => Promise<boolean | string>
}
| {
inputType: 'string'
@ -267,6 +274,13 @@ export type CommandArgument<
commandBarContext: ContextFrom<typeof commandBarMachine>,
machineContext?: ContextFrom<T>
) => string)
validation?: ({
data,
context,
}: {
data: any
context: CommandBarContext
}) => Promise<boolean | string>
}
| {
inputType: 'string'

View File

@ -193,6 +193,7 @@ export function buildCommandArgument<
createVariableByDefault: arg.createVariableByDefault,
variableName: arg.variableName,
defaultValue: arg.defaultValue,
validation: arg.validation,
...baseCommandArgument,
} satisfies CommandArgument<O, T> & { inputType: 'kcl' }
} else {

View File

@ -294,7 +294,8 @@ export const commandBarMachine = setup({
if (
context.currentArgument &&
context.selectedCommand &&
argConfig?.inputType === 'selection' &&
(argConfig?.inputType === 'selection' ||
argConfig?.inputType === 'kcl') &&
argConfig?.validation
) {
argConfig