diff --git a/e2e/playwright/feature-tree-pane.spec.ts b/e2e/playwright/feature-tree-pane.spec.ts index 7b51ecea8..ad4a4acdb 100644 --- a/e2e/playwright/feature-tree-pane.spec.ts +++ b/e2e/playwright/feature-tree-pane.spec.ts @@ -274,7 +274,6 @@ test.describe('Feature Tree pane', () => { currentArgKey: 'distance', currentArgValue: initialInput, headerArguments: { - Selection: '1 face', Distance: initialInput, }, highlightedHeaderArg: 'distance', @@ -291,7 +290,6 @@ test.describe('Feature Tree pane', () => { await cmdBar.expectState({ stage: 'review', headerArguments: { - Selection: '1 face', // The calculated value is shown in the argument summary Distance: initialInput, }, diff --git a/src/components/CommandBar/CommandBarHeader.tsx b/src/components/CommandBar/CommandBarHeader.tsx index f02f82a25..2a232d24d 100644 --- a/src/components/CommandBar/CommandBarHeader.tsx +++ b/src/components/CommandBar/CommandBarHeader.tsx @@ -17,7 +17,12 @@ function CommandBarHeader({ children }: React.PropsWithChildren<{}>) { if (!selectedCommand?.args) return undefined const s = { ...selectedCommand.args } for (const [name, arg] of Object.entries(s)) { - if (arg.hidden) delete s[name] + if ( + typeof arg.hidden === 'function' + ? arg.hidden(commandBarState.context) + : arg.hidden + ) + delete s[name] } return s }, [selectedCommand]) diff --git a/src/lib/commandBarConfigs/modelingCommandConfig.ts b/src/lib/commandBarConfigs/modelingCommandConfig.ts index 191ea0b41..f39461fdc 100644 --- a/src/lib/commandBarConfigs/modelingCommandConfig.ts +++ b/src/lib/commandBarConfigs/modelingCommandConfig.ts @@ -319,6 +319,7 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig< multiple: false, // TODO: multiple selection required: true, skip: true, + hidden: (context) => Boolean(context.argumentsToSubmit.nodeToEdit), }, // result: { // inputType: 'options', @@ -407,6 +408,7 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig< multiple: false, // TODO: multiple selection required: true, skip: true, + hidden: (context) => Boolean(context.argumentsToSubmit.nodeToEdit), }, axisOrEdge: { inputType: 'options', @@ -416,6 +418,7 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig< { name: 'Axis', isCurrent: true, value: 'Axis' }, { name: 'Edge', isCurrent: false, value: 'Edge' }, ], + hidden: (context) => Boolean(context.argumentsToSubmit.nodeToEdit), }, axis: { required: (commandContext) => @@ -437,6 +440,7 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig< selectionTypes: ['segment', 'sweepEdge', 'edgeCutEdge'], multiple: false, validation: revolveAxisValidator, + hidden: (context) => Boolean(context.argumentsToSubmit.nodeToEdit), }, angle: { inputType: 'kcl', diff --git a/src/lib/commandTypes.ts b/src/lib/commandTypes.ts index 7fa740d36..95879bc67 100644 --- a/src/lib/commandTypes.ts +++ b/src/lib/commandTypes.ts @@ -120,7 +120,12 @@ export type CommandArgumentConfig< ) => boolean) warningMessage?: string /** If `true`, arg is used as passed-through data, never for user input */ - hidden?: boolean + hidden?: + | boolean + | (( + commandBarContext: { argumentsToSubmit: Record }, // Should be the commandbarMachine's context, but it creates a circular dependency + machineContext?: C + ) => boolean) skip?: boolean /** For showing a summary display of the current value, such as in * the command bar's header @@ -236,7 +241,12 @@ export type CommandArgument< machineContext?: ContextFrom ) => boolean) /** If `true`, arg is used as passed-through data, never for user input */ - hidden?: boolean + hidden?: + | boolean + | (( + commandBarContext: { argumentsToSubmit: Record }, // Should be the commandbarMachine's context, but it creates a circular dependency + machineContext?: ContextFrom + ) => boolean) skip?: boolean machineActor?: Actor warningMessage?: string diff --git a/src/machines/commandBarMachine.ts b/src/machines/commandBarMachine.ts index aa6673ce8..acfbe2691 100644 --- a/src/machines/commandBarMachine.ts +++ b/src/machines/commandBarMachine.ts @@ -134,8 +134,10 @@ export const commandBarMachine = setup({ // that is, the first argument that is not already in the argumentsToSubmit // or hidden, or that is not undefined, or that is not marked as "skippable". // TODO validate the type of the existing arguments - const nonHiddenArgs = Object.entries(selectedCommand.args).filter( - (a) => !a[1].hidden + const nonHiddenArgs = Object.entries(selectedCommand.args).filter((a) => + a[1].hidden && typeof a[1].hidden === 'function' + ? !a[1].hidden(context) + : !a[1].hidden ) let argIndex = 0 @@ -260,7 +262,11 @@ export const commandBarMachine = setup({ }, 'All arguments are skippable': ({ context }) => { return Object.values(context.selectedCommand!.args!).every( - (argConfig) => argConfig.skip || argConfig.hidden + (argConfig) => + argConfig.skip || + (typeof argConfig.hidden === 'function' + ? argConfig.hidden(context) + : argConfig.hidden) ) }, 'Has selected command': ({ context }) => !!context.selectedCommand,