refactor: Rename ownerMachine to groupId in Command (#3010)

* refactor: Rename ownerMachine to groupId in Command

Commands don't need to be part of a state machine.

* Fix formatting
This commit is contained in:
Jonathan Tran
2024-07-11 18:10:47 -04:00
committed by GitHub
parent b971f3ecf4
commit 2dd1f0f213
7 changed files with 18 additions and 21 deletions

View File

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