From a4026e16e893cd1348e9fa2fa628581c0d6634fd Mon Sep 17 00:00:00 2001 From: Amir Raminfar Date: Thu, 4 Jan 2024 07:47:51 -0800 Subject: [PATCH] feat: adds labels to fuzzy search dialog (#2649) --- assets/components/FuzzySearchModal.vue | 6 ++++-- assets/models/Container.spec.ts | 2 +- assets/models/Container.ts | 1 + assets/stores/container.ts | 1 + assets/types/Container.d.ts | 1 + internal/docker/client.go | 1 + internal/docker/types.go | 25 +++++++++++++------------ 7 files changed, 22 insertions(+), 15 deletions(-) diff --git a/assets/components/FuzzySearchModal.vue b/assets/components/FuzzySearchModal.vue index caf198b5..fd1eb081 100644 --- a/assets/components/FuzzySearchModal.vue +++ b/assets/components/FuzzySearchModal.vue @@ -58,22 +58,24 @@ const store = useContainerStore(); const { containers } = storeToRefs(store); const list = computed(() => { - return containers.value.map(({ id, created, name, state, hostLabel: host }) => { + return containers.value.map(({ id, created, name, state, labels, hostLabel: host }) => { return { id, created, name, state, host, + labels: Object.entries(labels).map(([_, value]) => value), }; }); }); const { results } = useFuse(query, list, { fuseOptions: { - keys: ["name", "host"], + keys: ["name", "host", "labels"], includeScore: true, useExtendedSearch: true, + threshold: 0.3, }, resultLimit, matchAllWhenSearchEmpty: true, diff --git a/assets/models/Container.spec.ts b/assets/models/Container.spec.ts index ffa6cb9f..e91a0961 100644 --- a/assets/models/Container.spec.ts +++ b/assets/models/Container.spec.ts @@ -18,7 +18,7 @@ describe("Container", () => { ]; test.each(names)("name %s should be %s and %s", (name, expectedName, expectedSwarmId) => { - const c = new Container("id", new Date(), "image", name!, "command", "host", "status", "created"); + const c = new Container("id", new Date(), "image", name!, "command", "host", {}, "status", "created"); expect(c.name).toBe(expectedName); expect(c.swarmId).toBe(expectedSwarmId); }); diff --git a/assets/models/Container.ts b/assets/models/Container.ts index 2471f339..8c6d8e07 100644 --- a/assets/models/Container.ts +++ b/assets/models/Container.ts @@ -31,6 +31,7 @@ export class Container { public readonly name: string, public readonly command: string, public readonly host: string, + public readonly labels = {} as Record, public status: string, public state: ContainerState, public health?: ContainerHealth, diff --git a/assets/stores/container.ts b/assets/stores/container.ts index beada1fc..41089a4a 100644 --- a/assets/stores/container.ts +++ b/assets/stores/container.ts @@ -124,6 +124,7 @@ export const useContainerStore = defineStore("container", () => { c.name, c.command, c.host, + c.labels, c.status, c.state, c.health, diff --git a/assets/types/Container.d.ts b/assets/types/Container.d.ts index 5faf2bdb..16b2e624 100644 --- a/assets/types/Container.d.ts +++ b/assets/types/Container.d.ts @@ -14,6 +14,7 @@ export type ContainerJson = { readonly status: string; readonly state: ContainerState; readonly host: string; + readonly labels: Record; readonly health?: ContainerHealth; }; diff --git a/internal/docker/client.go b/internal/docker/client.go index 0e5d9466..913fb5aa 100644 --- a/internal/docker/client.go +++ b/internal/docker/client.go @@ -190,6 +190,7 @@ func (d *Client) ListContainers() ([]Container, error) { Status: c.Status, Host: d.host.ID, Health: findBetweenParentheses(c.Status), + Labels: c.Labels, } containers = append(containers, container) } diff --git a/internal/docker/types.go b/internal/docker/types.go index 9f21f5e6..1efc8da2 100644 --- a/internal/docker/types.go +++ b/internal/docker/types.go @@ -6,18 +6,19 @@ import ( // Container represents an internal representation of docker containers type Container struct { - ID string `json:"id"` - Names []string `json:"names"` - Name string `json:"name"` - Image string `json:"image"` - ImageID string `json:"imageId"` - Command string `json:"command"` - Created int64 `json:"created"` - State string `json:"state"` - Status string `json:"status"` - Health string `json:"health,omitempty"` - Host string `json:"host,omitempty"` - Tty bool `json:"-"` + ID string `json:"id"` + Names []string `json:"names"` + Name string `json:"name"` + Image string `json:"image"` + ImageID string `json:"imageId"` + Command string `json:"command"` + Created int64 `json:"created"` + State string `json:"state"` + Status string `json:"status"` + Health string `json:"health,omitempty"` + Host string `json:"host,omitempty"` + Tty bool `json:"-"` + Labels map[string]string `json:"labels,omitempty"` } // ContainerStat represent stats instant for a container