Hide selection-type args from command palette while in an edit flow (#5763)

* Allow `hidden` config to be a callback

* Hide selection type args if `nodeToEdit` is present

in workflows that have an edit flow set up

* Remove Selection from headerArguments in edit flow tests
This commit is contained in:
Frank Noirot
2025-03-11 16:29:03 -04:00
committed by GitHub
parent b5028f7aa8
commit 724e65ac97
5 changed files with 31 additions and 8 deletions

View File

@ -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,
},

View File

@ -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])

View File

@ -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',

View File

@ -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<string, unknown> }, // 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<T>
) => boolean)
/** If `true`, arg is used as passed-through data, never for user input */
hidden?: boolean
hidden?:
| boolean
| ((
commandBarContext: { argumentsToSubmit: Record<string, unknown> }, // Should be the commandbarMachine's context, but it creates a circular dependency
machineContext?: ContextFrom<T>
) => boolean)
skip?: boolean
machineActor?: Actor<T>
warningMessage?: string

View File

@ -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,