Make commands disable, not unregister, based on their machineActor (#5070)
* Make "Find and select command" global to commandBarMachine * Make commands not removed based on their actor state, only disabled * Sort commands better in CommandComboBox * Break out sort logic, add a few unit tests * Fix missed name change * Needed to make one more change from source branch: since `optionsFromContext` now only gets fired once, I/O-based options need to use the `options` config instead. --------- Co-authored-by: 49fl <ircsurfer33@gmail.com>
This commit is contained in:
@ -2,6 +2,9 @@
|
||||
// That object also contains some metadata about what to do with the KCL expression,
|
||||
// such as whether we need to create a new variable for it.
|
||||
// This function extracts the value field from those arg payloads and returns
|
||||
|
||||
import { Command } from './commandTypes'
|
||||
|
||||
// The arg object with all its field as natural values that the command to be executed will expect.
|
||||
export function getCommandArgumentKclValuesOnly(args: Record<string, unknown>) {
|
||||
return Object.fromEntries(
|
||||
@ -13,3 +16,42 @@ export function getCommandArgumentKclValuesOnly(args: Record<string, unknown>) {
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export interface CommandWithDisabledState {
|
||||
command: Command
|
||||
disabled: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorting logic for commands in the command combo box.
|
||||
*/
|
||||
export function sortCommands(
|
||||
a: CommandWithDisabledState,
|
||||
b: CommandWithDisabledState
|
||||
) {
|
||||
// Disabled commands should be at the bottom
|
||||
if (a.disabled && !b.disabled) {
|
||||
return 1
|
||||
}
|
||||
if (b.disabled && !a.disabled) {
|
||||
return -1
|
||||
}
|
||||
// Settings commands should be next-to-last
|
||||
if (a.command.groupId === 'settings' && b.command.groupId !== 'settings') {
|
||||
return 1
|
||||
}
|
||||
if (b.command.groupId === 'settings' && a.command.groupId !== 'settings') {
|
||||
return -1
|
||||
}
|
||||
// Modeling commands should be first
|
||||
if (a.command.groupId === 'modeling' && b.command.groupId !== 'modeling') {
|
||||
return -1
|
||||
}
|
||||
if (b.command.groupId === 'modeling' && a.command.groupId !== 'modeling') {
|
||||
return 1
|
||||
}
|
||||
// Sort alphabetically
|
||||
return (a.command.displayName || a.command.name).localeCompare(
|
||||
b.command.displayName || b.command.name
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user