Don't assume a command is found in "Find and select command" command bar action (#2019)

This commit is contained in:
Frank Noirot
2024-04-04 19:15:26 -04:00
committed by GitHub
parent 24caeece65
commit 8ac0bf4953
2 changed files with 12 additions and 4 deletions

View File

@ -67,8 +67,15 @@ function ProjectMenuPopover({
project?: IndexLoaderData['project']
file?: IndexLoaderData['file']
}) {
const { commandBarSend } = useCommandsContext()
const { commandBarState, commandBarSend } = useCommandsContext()
const { onProjectClose } = useLspContext()
const exportCommandInfo = { name: 'Export', ownerMachine: 'modeling' }
const findCommand = (obj: { name: string; ownerMachine: string }) =>
Boolean(
commandBarState.context.commands.find(
(c) => c.name === obj.name && c.ownerMachine === obj.ownerMachine
)
)
return (
<Popover className="relative">
@ -150,10 +157,11 @@ function ProjectMenuPopover({
Element="button"
icon={{ icon: 'exportFile', className: 'p-1' }}
className="border-transparent dark:border-transparent"
disabled={!findCommand(exportCommandInfo)}
onClick={() =>
commandBarSend({
type: 'Find and select command',
data: { name: 'Export', ownerMachine: 'modeling' },
data: exportCommandInfo,
})
}
>

View File

@ -402,8 +402,8 @@ export const commandBarMachine = createMachine(
'Initialize arguments to submit': assign({
argumentsToSubmit: (c, e) => {
const command =
'command' in e.data ? e.data.command : c.selectedCommand!
if (!command.args) return {}
'command' in e.data ? e.data.command : c.selectedCommand
if (!command?.args) return {}
const args: { [x: string]: unknown } = {}
for (const [argName, arg] of Object.entries(command.args)) {
args[argName] =