Don't assume a command is found in "Find and select command" command bar action (#2019)
This commit is contained in:
@ -67,8 +67,15 @@ function ProjectMenuPopover({
|
|||||||
project?: IndexLoaderData['project']
|
project?: IndexLoaderData['project']
|
||||||
file?: IndexLoaderData['file']
|
file?: IndexLoaderData['file']
|
||||||
}) {
|
}) {
|
||||||
const { commandBarSend } = useCommandsContext()
|
const { commandBarState, commandBarSend } = useCommandsContext()
|
||||||
const { onProjectClose } = useLspContext()
|
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 (
|
return (
|
||||||
<Popover className="relative">
|
<Popover className="relative">
|
||||||
@ -150,10 +157,11 @@ function ProjectMenuPopover({
|
|||||||
Element="button"
|
Element="button"
|
||||||
icon={{ icon: 'exportFile', className: 'p-1' }}
|
icon={{ icon: 'exportFile', className: 'p-1' }}
|
||||||
className="border-transparent dark:border-transparent"
|
className="border-transparent dark:border-transparent"
|
||||||
|
disabled={!findCommand(exportCommandInfo)}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
commandBarSend({
|
commandBarSend({
|
||||||
type: 'Find and select command',
|
type: 'Find and select command',
|
||||||
data: { name: 'Export', ownerMachine: 'modeling' },
|
data: exportCommandInfo,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
@ -402,8 +402,8 @@ export const commandBarMachine = createMachine(
|
|||||||
'Initialize arguments to submit': assign({
|
'Initialize arguments to submit': assign({
|
||||||
argumentsToSubmit: (c, e) => {
|
argumentsToSubmit: (c, e) => {
|
||||||
const command =
|
const command =
|
||||||
'command' in e.data ? e.data.command : c.selectedCommand!
|
'command' in e.data ? e.data.command : c.selectedCommand
|
||||||
if (!command.args) return {}
|
if (!command?.args) return {}
|
||||||
const args: { [x: string]: unknown } = {}
|
const args: { [x: string]: unknown } = {}
|
||||||
for (const [argName, arg] of Object.entries(command.args)) {
|
for (const [argName, arg] of Object.entries(command.args)) {
|
||||||
args[argName] =
|
args[argName] =
|
||||||
|
Reference in New Issue
Block a user