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:
@ -274,7 +274,6 @@ test.describe('Feature Tree pane', () => {
|
|||||||
currentArgKey: 'distance',
|
currentArgKey: 'distance',
|
||||||
currentArgValue: initialInput,
|
currentArgValue: initialInput,
|
||||||
headerArguments: {
|
headerArguments: {
|
||||||
Selection: '1 face',
|
|
||||||
Distance: initialInput,
|
Distance: initialInput,
|
||||||
},
|
},
|
||||||
highlightedHeaderArg: 'distance',
|
highlightedHeaderArg: 'distance',
|
||||||
@ -291,7 +290,6 @@ test.describe('Feature Tree pane', () => {
|
|||||||
await cmdBar.expectState({
|
await cmdBar.expectState({
|
||||||
stage: 'review',
|
stage: 'review',
|
||||||
headerArguments: {
|
headerArguments: {
|
||||||
Selection: '1 face',
|
|
||||||
// The calculated value is shown in the argument summary
|
// The calculated value is shown in the argument summary
|
||||||
Distance: initialInput,
|
Distance: initialInput,
|
||||||
},
|
},
|
||||||
|
@ -17,7 +17,12 @@ function CommandBarHeader({ children }: React.PropsWithChildren<{}>) {
|
|||||||
if (!selectedCommand?.args) return undefined
|
if (!selectedCommand?.args) return undefined
|
||||||
const s = { ...selectedCommand.args }
|
const s = { ...selectedCommand.args }
|
||||||
for (const [name, arg] of Object.entries(s)) {
|
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
|
return s
|
||||||
}, [selectedCommand])
|
}, [selectedCommand])
|
||||||
|
@ -319,6 +319,7 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
|
|||||||
multiple: false, // TODO: multiple selection
|
multiple: false, // TODO: multiple selection
|
||||||
required: true,
|
required: true,
|
||||||
skip: true,
|
skip: true,
|
||||||
|
hidden: (context) => Boolean(context.argumentsToSubmit.nodeToEdit),
|
||||||
},
|
},
|
||||||
// result: {
|
// result: {
|
||||||
// inputType: 'options',
|
// inputType: 'options',
|
||||||
@ -407,6 +408,7 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
|
|||||||
multiple: false, // TODO: multiple selection
|
multiple: false, // TODO: multiple selection
|
||||||
required: true,
|
required: true,
|
||||||
skip: true,
|
skip: true,
|
||||||
|
hidden: (context) => Boolean(context.argumentsToSubmit.nodeToEdit),
|
||||||
},
|
},
|
||||||
axisOrEdge: {
|
axisOrEdge: {
|
||||||
inputType: 'options',
|
inputType: 'options',
|
||||||
@ -416,6 +418,7 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
|
|||||||
{ name: 'Axis', isCurrent: true, value: 'Axis' },
|
{ name: 'Axis', isCurrent: true, value: 'Axis' },
|
||||||
{ name: 'Edge', isCurrent: false, value: 'Edge' },
|
{ name: 'Edge', isCurrent: false, value: 'Edge' },
|
||||||
],
|
],
|
||||||
|
hidden: (context) => Boolean(context.argumentsToSubmit.nodeToEdit),
|
||||||
},
|
},
|
||||||
axis: {
|
axis: {
|
||||||
required: (commandContext) =>
|
required: (commandContext) =>
|
||||||
@ -437,6 +440,7 @@ export const modelingMachineCommandConfig: StateMachineCommandSetConfig<
|
|||||||
selectionTypes: ['segment', 'sweepEdge', 'edgeCutEdge'],
|
selectionTypes: ['segment', 'sweepEdge', 'edgeCutEdge'],
|
||||||
multiple: false,
|
multiple: false,
|
||||||
validation: revolveAxisValidator,
|
validation: revolveAxisValidator,
|
||||||
|
hidden: (context) => Boolean(context.argumentsToSubmit.nodeToEdit),
|
||||||
},
|
},
|
||||||
angle: {
|
angle: {
|
||||||
inputType: 'kcl',
|
inputType: 'kcl',
|
||||||
|
@ -120,7 +120,12 @@ export type CommandArgumentConfig<
|
|||||||
) => boolean)
|
) => boolean)
|
||||||
warningMessage?: string
|
warningMessage?: string
|
||||||
/** If `true`, arg is used as passed-through data, never for user input */
|
/** 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
|
skip?: boolean
|
||||||
/** For showing a summary display of the current value, such as in
|
/** For showing a summary display of the current value, such as in
|
||||||
* the command bar's header
|
* the command bar's header
|
||||||
@ -236,7 +241,12 @@ export type CommandArgument<
|
|||||||
machineContext?: ContextFrom<T>
|
machineContext?: ContextFrom<T>
|
||||||
) => boolean)
|
) => boolean)
|
||||||
/** If `true`, arg is used as passed-through data, never for user input */
|
/** 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
|
skip?: boolean
|
||||||
machineActor?: Actor<T>
|
machineActor?: Actor<T>
|
||||||
warningMessage?: string
|
warningMessage?: string
|
||||||
|
@ -134,8 +134,10 @@ export const commandBarMachine = setup({
|
|||||||
// that is, the first argument that is not already in the argumentsToSubmit
|
// 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".
|
// or hidden, or that is not undefined, or that is not marked as "skippable".
|
||||||
// TODO validate the type of the existing arguments
|
// TODO validate the type of the existing arguments
|
||||||
const nonHiddenArgs = Object.entries(selectedCommand.args).filter(
|
const nonHiddenArgs = Object.entries(selectedCommand.args).filter((a) =>
|
||||||
(a) => !a[1].hidden
|
a[1].hidden && typeof a[1].hidden === 'function'
|
||||||
|
? !a[1].hidden(context)
|
||||||
|
: !a[1].hidden
|
||||||
)
|
)
|
||||||
let argIndex = 0
|
let argIndex = 0
|
||||||
|
|
||||||
@ -260,7 +262,11 @@ export const commandBarMachine = setup({
|
|||||||
},
|
},
|
||||||
'All arguments are skippable': ({ context }) => {
|
'All arguments are skippable': ({ context }) => {
|
||||||
return Object.values(context.selectedCommand!.args!).every(
|
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,
|
'Has selected command': ({ context }) => !!context.selectedCommand,
|
||||||
|
Reference in New Issue
Block a user