From 3206123770187e2f9e7dbc3ad8da804feb36672a Mon Sep 17 00:00:00 2001 From: Jeroen Nijhuis Date: Thu, 8 Feb 2024 20:05:37 +0100 Subject: [PATCH] feat: added keywords to quickly filter through commands in the command palette --- src/command-palette/index.ts | 1 + src/components/ContextSwitcher.vue | 10 ++++++++-- src/components/ui/command/CommandDialog.vue | 9 ++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/command-palette/index.ts b/src/command-palette/index.ts index 52d79e1..96083a3 100644 --- a/src/command-palette/index.ts +++ b/src/command-palette/index.ts @@ -2,6 +2,7 @@ type BaseCommand = { id: string; name: string; description?: string; + keywords?: string[]; }; type ExecutableCommand = { diff --git a/src/components/ContextSwitcher.vue b/src/components/ContextSwitcher.vue index 62e1e05..40759d4 100644 --- a/src/components/ContextSwitcher.vue +++ b/src/components/ContextSwitcher.vue @@ -23,6 +23,7 @@ onMounted(() => { id: "switch-context", name: "Switch context", description: "Switch the current context", + keywords: ["ctx", "context"], commands: async (): Promise => { const contexts = await Kubernetes.getContexts(); @@ -63,6 +64,7 @@ onMounted(() => { name: "Switch namespace", description: "Switch the current namespace", id: "switch-namespace", + keywords: ["ns", "namespace"], commands: async (): Promise => { const namespaces = await Kubernetes.getNamespaces(context.value); @@ -95,8 +97,12 @@ onMounted(() => { class="flex flex-col w-full text-xs border rounded-lg p-2 text-left hover:bg-background" @click="showSingleCommand('switch-context')" > - {{ context || "No context" }} - {{ namespace == "" ? "All namespaces" : namespace }} + {{ + context || "No context" + }} + {{ + namespace == "" ? "All namespaces" : namespace + }} Click here to set context diff --git a/src/components/ui/command/CommandDialog.vue b/src/components/ui/command/CommandDialog.vue index 44da854..82ae379 100644 --- a/src/components/ui/command/CommandDialog.vue +++ b/src/components/ui/command/CommandDialog.vue @@ -14,7 +14,14 @@ const emitsAsProps = useEmitAsProps(emits); const filter = (list: Command[], query: string): Command[] => { const fuse = new Fuse(list, { threshold: 0.3, - keys: ["name", "description"], + keys: [ + { + name: "keywords", + weight: 2, + }, + "name", + "description", + ], }); return fuse.search(query).map((result) => result.item); };