Skip to content

Commit

Permalink
feat: added keywords to quickly filter through commands in the comman…
Browse files Browse the repository at this point in the history
…d palette
  • Loading branch information
Jeroen Nijhuis committed Feb 8, 2024
1 parent 03ef8e2 commit 3206123
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/command-palette/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ type BaseCommand = {
id: string;
name: string;
description?: string;
keywords?: string[];
};

type ExecutableCommand = {
Expand Down
10 changes: 8 additions & 2 deletions src/components/ContextSwitcher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ onMounted(() => {
id: "switch-context",
name: "Switch context",
description: "Switch the current context",
keywords: ["ctx", "context"],
commands: async (): Promise<Command[]> => {
const contexts = await Kubernetes.getContexts();
Expand Down Expand Up @@ -63,6 +64,7 @@ onMounted(() => {
name: "Switch namespace",
description: "Switch the current namespace",
id: "switch-namespace",
keywords: ["ns", "namespace"],
commands: async (): Promise<Command[]> => {
const namespaces = await Kubernetes.getNamespaces(context.value);
Expand Down Expand Up @@ -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')"
>
<span class="uppercase font-bold mb-1">{{ context || "No context" }}</span>
<span v-if="context">{{ namespace == "" ? "All namespaces" : namespace }}</span>
<span class="uppercase font-bold mb-1">{{
context || "No context"
}}</span>
<span v-if="context">{{
namespace == "" ? "All namespaces" : namespace
}}</span>
<span v-else>Click here to set context</span>
</button>
</div>
Expand Down
9 changes: 8 additions & 1 deletion src/components/ui/command/CommandDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down

0 comments on commit 3206123

Please sign in to comment.