Compare commits
	
		
			3 Commits
		
	
	
		
			kcl-82
			...
			pierremtb/
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 82d1fe5436 | |||
| bfb0bd6997 | |||
| 7aa6e58121 | 
| @ -352,13 +352,12 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig< | |||||||
|         selectionTypes: ['cap', 'wall'], |         selectionTypes: ['cap', 'wall'], | ||||||
|         multiple: true, |         multiple: true, | ||||||
|         required: true, |         required: true, | ||||||
|         validation: shellValidator, |  | ||||||
|       }, |       }, | ||||||
|       thickness: { |       thickness: { | ||||||
|         inputType: 'kcl', |         inputType: 'kcl', | ||||||
|         defaultValue: KCL_DEFAULT_LENGTH, |         defaultValue: KCL_DEFAULT_LENGTH, | ||||||
|         required: true, |         required: true, | ||||||
|         // TODO: add dry-run validation on thickness param |         validation: shellValidator, | ||||||
|       }, |       }, | ||||||
|     }, |     }, | ||||||
|   }, |   }, | ||||||
|  | |||||||
| @ -3,6 +3,7 @@ import { engineCommandManager } from 'lib/singletons' | |||||||
| import { uuidv4 } from 'lib/utils' | import { uuidv4 } from 'lib/utils' | ||||||
| import { CommandBarContext } from 'machines/commandBarMachine' | import { CommandBarContext } from 'machines/commandBarMachine' | ||||||
| import { Selections } from 'lib/selections' | import { Selections } from 'lib/selections' | ||||||
|  | import { KclCommandValue } from 'lib/commandTypes' | ||||||
| import { ApiError_type } from '@kittycad/lib/dist/types/src/models' | import { ApiError_type } from '@kittycad/lib/dist/types/src/models' | ||||||
|  |  | ||||||
| export const disableDryRunWithRetry = async (numberOfRetries = 3) => { | export const disableDryRunWithRetry = async (numberOfRetries = 3) => { | ||||||
| @ -171,16 +172,21 @@ export const loftValidator = async ({ | |||||||
| } | } | ||||||
|  |  | ||||||
| export const shellValidator = async ({ | export const shellValidator = async ({ | ||||||
|  |   context, | ||||||
|   data, |   data, | ||||||
| }: { | }: { | ||||||
|   data: { selection: Selections } |   context: CommandBarContext | ||||||
|  |   data: { thickness: KclCommandValue } | ||||||
| }): Promise<boolean | string> => { | }): 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' |     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 |   // No validation on the args, filtering is done upstream and we have the dry run validation just below | ||||||
|   const face_ids = data.selection.graphSelections.flatMap((s) => |   const shell_thickness = Number(thicknessArg.valueCalculated) | ||||||
|  |   const face_ids = selectionArg.graphSelections.flatMap((s) => | ||||||
|     s.artifact ? s.artifact.id : [] |     s.artifact ? s.artifact.id : [] | ||||||
|   ) |   ) | ||||||
|  |  | ||||||
| @ -197,14 +203,12 @@ export const shellValidator = async ({ | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   const command = 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 DEFAULT_HOLLOW = false | ||||||
|     const cmdArgs = { |     const cmdArgs = { | ||||||
|       face_ids, |       face_ids, | ||||||
|       object_id, |       object_id, | ||||||
|  |       shell_thickness, | ||||||
|       hollow: DEFAULT_HOLLOW, |       hollow: DEFAULT_HOLLOW, | ||||||
|       shell_thickness: DEFAULT_THICKNESS, |  | ||||||
|     } |     } | ||||||
|     return await engineCommandManager.sendSceneCommand({ |     return await engineCommandManager.sendSceneCommand({ | ||||||
|       type: 'modeling_cmd_req', |       type: 'modeling_cmd_req', | ||||||
|  | |||||||
| @ -171,6 +171,13 @@ export type CommandArgumentConfig< | |||||||
|             commandBarContext: ContextFrom<typeof commandBarMachine>, |             commandBarContext: ContextFrom<typeof commandBarMachine>, | ||||||
|             machineContext?: C |             machineContext?: C | ||||||
|           ) => string) |           ) => string) | ||||||
|  |       validation?: ({ | ||||||
|  |         data, | ||||||
|  |         context, | ||||||
|  |       }: { | ||||||
|  |         data: any | ||||||
|  |         context: CommandBarContext | ||||||
|  |       }) => Promise<boolean | string> | ||||||
|     } |     } | ||||||
|   | { |   | { | ||||||
|       inputType: 'string' |       inputType: 'string' | ||||||
| @ -267,6 +274,13 @@ export type CommandArgument< | |||||||
|             commandBarContext: ContextFrom<typeof commandBarMachine>, |             commandBarContext: ContextFrom<typeof commandBarMachine>, | ||||||
|             machineContext?: ContextFrom<T> |             machineContext?: ContextFrom<T> | ||||||
|           ) => string) |           ) => string) | ||||||
|  |       validation?: ({ | ||||||
|  |         data, | ||||||
|  |         context, | ||||||
|  |       }: { | ||||||
|  |         data: any | ||||||
|  |         context: CommandBarContext | ||||||
|  |       }) => Promise<boolean | string> | ||||||
|     } |     } | ||||||
|   | { |   | { | ||||||
|       inputType: 'string' |       inputType: 'string' | ||||||
|  | |||||||
| @ -193,6 +193,7 @@ export function buildCommandArgument< | |||||||
|       createVariableByDefault: arg.createVariableByDefault, |       createVariableByDefault: arg.createVariableByDefault, | ||||||
|       variableName: arg.variableName, |       variableName: arg.variableName, | ||||||
|       defaultValue: arg.defaultValue, |       defaultValue: arg.defaultValue, | ||||||
|  |       validation: arg.validation, | ||||||
|       ...baseCommandArgument, |       ...baseCommandArgument, | ||||||
|     } satisfies CommandArgument<O, T> & { inputType: 'kcl' } |     } satisfies CommandArgument<O, T> & { inputType: 'kcl' } | ||||||
|   } else { |   } else { | ||||||
|  | |||||||
| @ -294,7 +294,8 @@ export const commandBarMachine = setup({ | |||||||
|           if ( |           if ( | ||||||
|             context.currentArgument && |             context.currentArgument && | ||||||
|             context.selectedCommand && |             context.selectedCommand && | ||||||
|             argConfig?.inputType === 'selection' && |             (argConfig?.inputType === 'selection' || | ||||||
|  |               argConfig?.inputType === 'kcl') && | ||||||
|             argConfig?.validation |             argConfig?.validation | ||||||
|           ) { |           ) { | ||||||
|             argConfig |             argConfig | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	