Convert commands to flat structure

This commit is contained in:
Elias Meire 2024-10-30 11:39:11 +01:00
parent acd2074e71
commit fa597ce627
No known key found for this signature in database

View file

@ -1576,32 +1576,41 @@ onBeforeUnmount(() => {
} }
}); });
const hotkeys = computed(() => [ type NinjaKeysCommand = {
id: string;
title: string;
section?: string;
children?: string[];
handler?: () => void;
};
const hotkeys = computed<NinjaKeysCommand[]>(() => {
const allOpenNodeCommands = getAllNodesCommands.value;
const allAddNodeCommands = addNodeCommand.value;
const rootCommands: NinjaKeysCommand[] = [
{ {
id: 'Add node', id: 'Add node',
title: 'Add node', title: 'Add node',
section: 'Nodes', section: 'Nodes',
parent: null, children: allAddNodeCommands.map((cmd) => cmd.id),
children: addNodeCommand.value,
}, },
{ {
id: 'Open node', id: 'Open node',
title: 'Open node', title: 'Open node',
children: allOpenNodeCommands.map((cmd) => cmd.id),
section: 'Nodes', section: 'Nodes',
parent: null,
children: getAllNodesCommands.value,
}, },
]); ];
const getAllNodesCommands = computed(() => { return rootCommands.concat(allOpenNodeCommands).concat(addNodeCommand.value);
});
const getAllNodesCommands = computed<NinjaKeysCommand[]>(() => {
return editableWorkflow.value.nodes.map((node) => { return editableWorkflow.value.nodes.map((node) => {
const { id, name } = node; const { id, name } = node;
console.log({ id, name });
return { return {
id, id,
title: name, title: `Open "${name}" Node`,
parent: 'Open node', parent: 'Open node',
handler: () => { handler: () => {
setNodeActive(id); setNodeActive(id);
@ -1610,7 +1619,7 @@ const getAllNodesCommands = computed(() => {
}); });
}); });
const addNodeCommand = computed(() => { const addNodeCommand = computed<NinjaKeysCommand[]>(() => {
const httpOnlyCredentials = useCredentialsStore().httpOnlyCredentialTypes; const httpOnlyCredentials = useCredentialsStore().httpOnlyCredentialTypes;
const nodeTypes = useNodeTypesStore().visibleNodeTypes; const nodeTypes = useNodeTypesStore().visibleNodeTypes;
@ -1620,7 +1629,7 @@ const addNodeCommand = computed(() => {
const { name, displayName } = node; const { name, displayName } = node;
return { return {
id: name, id: name,
title: displayName, title: `Add ${displayName} Node`,
parent: 'Add node', parent: 'Add node',
handler: async () => { handler: async () => {
await addNodes([{ type: name }]); await addNodes([{ type: name }]);
@ -1722,7 +1731,11 @@ const addNodeCommand = computed(() => {
--> -->
</Suspense> </Suspense>
<Teleport to="body"> <Teleport to="body">
<ninja-keys :class="uiStore.appliedTheme" :data="hotkeys"></ninja-keys> <ninja-keys
:class="uiStore.appliedTheme"
:data="hotkeys"
:no-auto-load-md-icons="true"
></ninja-keys>
</Teleport> </Teleport>
</WorkflowCanvas> </WorkflowCanvas>
</template> </template>