diff --git a/src/Toolbar.tsx b/src/Toolbar.tsx index 0e15e9401..1fb91863b 100644 --- a/src/Toolbar.tsx +++ b/src/Toolbar.tsx @@ -114,7 +114,7 @@ export function Toolbar({ () => commandBarSend({ type: 'Find and select command', - data: { name: 'Extrude', ownerMachine: 'modeling' }, + data: { name: 'Extrude', groupId: 'modeling' }, }), { enabled: !disableAllButtons, scopes: ['modeling'] } ) @@ -378,7 +378,7 @@ export function Toolbar({ onClick={() => commandBarSend({ type: 'Find and select command', - data: { name: 'Extrude', ownerMachine: 'modeling' }, + data: { name: 'Extrude', groupId: 'modeling' }, }) } disabled={!state.can('Extrude') || disableAllButtons} diff --git a/src/components/ProjectSidebarMenu.tsx b/src/components/ProjectSidebarMenu.tsx index 0aff34c38..800d456a4 100644 --- a/src/components/ProjectSidebarMenu.tsx +++ b/src/components/ProjectSidebarMenu.tsx @@ -82,11 +82,11 @@ function ProjectMenuPopover({ }) { const { commandBarState, commandBarSend } = useCommandsContext() const { onProjectClose } = useLspContext() - const exportCommandInfo = { name: 'Export', ownerMachine: 'modeling' } - const findCommand = (obj: { name: string; ownerMachine: string }) => + const exportCommandInfo = { name: 'Export', groupId: 'modeling' } + const findCommand = (obj: { name: string; groupId: string }) => Boolean( commandBarState.context.commands.find( - (c) => c.name === obj.name && c.ownerMachine === obj.ownerMachine + (c) => c.name === obj.name && c.groupId === obj.groupId ) ) diff --git a/src/hooks/useStateMachineCommands.ts b/src/hooks/useStateMachineCommands.ts index 83f53fa15..e3b2b3549 100644 --- a/src/hooks/useStateMachineCommands.ts +++ b/src/hooks/useStateMachineCommands.ts @@ -60,7 +60,8 @@ export default function useStateMachineCommands< .filter((e) => !['done.', 'error.'].some((n) => e.includes(n))) .map((type) => createMachineCommand({ - ownerMachine: machineId, + // The group is the owner machine's ID. + groupId: machineId, type, state, send, diff --git a/src/lib/commandBarConfigs/settingsCommandConfig.ts b/src/lib/commandBarConfigs/settingsCommandConfig.ts index 6d91a33c6..bdfd24d5f 100644 --- a/src/lib/commandBarConfigs/settingsCommandConfig.ts +++ b/src/lib/commandBarConfigs/settingsCommandConfig.ts @@ -124,7 +124,7 @@ export function createSettingsCommand({ displayName: `Settings · ${decamelize(type.replaceAll('.', ' · '), { separator: ' ', })}`, - ownerMachine: 'settings', + groupId: 'settings', icon: 'settings', needsReview: false, onSubmit: (data) => { diff --git a/src/lib/commandTypes.ts b/src/lib/commandTypes.ts index 64e506105..cd957a84d 100644 --- a/src/lib/commandTypes.ts +++ b/src/lib/commandTypes.ts @@ -65,7 +65,7 @@ export type Command< CommandSchema extends CommandSetSchema[CommandName] = CommandSetSchema[CommandName] > = { name: CommandName - ownerMachine: T['id'] + groupId: T['id'] needsReview: boolean onSubmit: (data?: CommandSchema) => void onCancel?: () => void @@ -84,7 +84,7 @@ export type CommandConfig< CommandSchema extends CommandSetSchema[CommandName] = CommandSetSchema[CommandName] > = Omit< Command, - 'name' | 'ownerMachine' | 'onSubmit' | 'onCancel' | 'args' | 'needsReview' + 'name' | 'groupId' | 'onSubmit' | 'onCancel' | 'args' | 'needsReview' > & { needsReview?: true args?: { diff --git a/src/lib/createMachineCommand.ts b/src/lib/createMachineCommand.ts index 3ba0795f4..191ec2e3f 100644 --- a/src/lib/createMachineCommand.ts +++ b/src/lib/createMachineCommand.ts @@ -20,7 +20,7 @@ interface CreateMachineCommandProps< S extends CommandSetSchema > { type: EventFrom['type'] - ownerMachine: T['id'] + groupId: T['id'] state: StateFrom send: Function actor: InterpreterFrom @@ -34,7 +34,7 @@ export function createMachineCommand< T extends AnyStateMachine, S extends CommandSetSchema >({ - ownerMachine, + groupId, type, state, send, @@ -62,7 +62,7 @@ export function createMachineCommand< const command: Command = { name: type, - ownerMachine: ownerMachine, + groupId, icon, needsReview: commandConfig.needsReview || false, onSubmit: (data?: S[typeof type]) => { diff --git a/src/machines/commandBarMachine.ts b/src/machines/commandBarMachine.ts index d3491dde6..de3833de4 100644 --- a/src/machines/commandBarMachine.ts +++ b/src/machines/commandBarMachine.ts @@ -57,7 +57,7 @@ export type CommandBarMachineEvent = } | { type: 'Find and select command' - data: { name: string; ownerMachine: string } + data: { name: string; groupId: string } } | { type: 'Change current argument' @@ -120,9 +120,7 @@ export const commandBarMachine = createMachine( context.commands.filter( (c) => !event.data.commands.some( - (c2) => - c2.name === c.name && - c2.ownerMachine === c.ownerMachine + (c2) => c2.name === c.name && c2.groupId === c.groupId ) ), }), @@ -393,9 +391,7 @@ export const commandBarMachine = createMachine( selectedCommand: (c, e) => { if (e.type !== 'Find and select command') return c.selectedCommand const found = c.commands.find( - (cmd) => - cmd.name === e.data.name && - cmd.ownerMachine === e.data.ownerMachine + (cmd) => cmd.name === e.data.name && cmd.groupId === e.data.groupId ) return !!found ? found : c.selectedCommand @@ -514,7 +510,7 @@ export const commandBarMachine = createMachine( ) function sortCommands(a: Command, b: Command) { - if (b.ownerMachine === 'auth') return -1 - if (a.ownerMachine === 'auth') return 1 + if (b.groupId === 'auth') return -1 + if (a.groupId === 'auth') return 1 return a.name.localeCompare(b.name) }