1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-21 21:33:18 +01:00

feat: adds labels to fuzzy search dialog (#2649)

This commit is contained in:
Amir Raminfar
2024-01-04 07:47:51 -08:00
committed by GitHub
parent ee4f94ce2e
commit a4026e16e8
7 changed files with 22 additions and 15 deletions

View File

@@ -58,22 +58,24 @@ const store = useContainerStore();
const { containers } = storeToRefs(store); const { containers } = storeToRefs(store);
const list = computed(() => { 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 { return {
id, id,
created, created,
name, name,
state, state,
host, host,
labels: Object.entries(labels).map(([_, value]) => value),
}; };
}); });
}); });
const { results } = useFuse(query, list, { const { results } = useFuse(query, list, {
fuseOptions: { fuseOptions: {
keys: ["name", "host"], keys: ["name", "host", "labels"],
includeScore: true, includeScore: true,
useExtendedSearch: true, useExtendedSearch: true,
threshold: 0.3,
}, },
resultLimit, resultLimit,
matchAllWhenSearchEmpty: true, matchAllWhenSearchEmpty: true,

View File

@@ -18,7 +18,7 @@ describe("Container", () => {
]; ];
test.each(names)("name %s should be %s and %s", (name, expectedName, expectedSwarmId) => { 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.name).toBe(expectedName);
expect(c.swarmId).toBe(expectedSwarmId); expect(c.swarmId).toBe(expectedSwarmId);
}); });

View File

@@ -31,6 +31,7 @@ export class Container {
public readonly name: string, public readonly name: string,
public readonly command: string, public readonly command: string,
public readonly host: string, public readonly host: string,
public readonly labels = {} as Record<string, string>,
public status: string, public status: string,
public state: ContainerState, public state: ContainerState,
public health?: ContainerHealth, public health?: ContainerHealth,

View File

@@ -124,6 +124,7 @@ export const useContainerStore = defineStore("container", () => {
c.name, c.name,
c.command, c.command,
c.host, c.host,
c.labels,
c.status, c.status,
c.state, c.state,
c.health, c.health,

View File

@@ -14,6 +14,7 @@ export type ContainerJson = {
readonly status: string; readonly status: string;
readonly state: ContainerState; readonly state: ContainerState;
readonly host: string; readonly host: string;
readonly labels: Record<string, string>;
readonly health?: ContainerHealth; readonly health?: ContainerHealth;
}; };

View File

@@ -190,6 +190,7 @@ func (d *Client) ListContainers() ([]Container, error) {
Status: c.Status, Status: c.Status,
Host: d.host.ID, Host: d.host.ID,
Health: findBetweenParentheses(c.Status), Health: findBetweenParentheses(c.Status),
Labels: c.Labels,
} }
containers = append(containers, container) containers = append(containers, container)
} }

View File

@@ -18,6 +18,7 @@ type Container struct {
Health string `json:"health,omitempty"` Health string `json:"health,omitempty"`
Host string `json:"host,omitempty"` Host string `json:"host,omitempty"`
Tty bool `json:"-"` Tty bool `json:"-"`
Labels map[string]string `json:"labels,omitempty"`
} }
// ContainerStat represent stats instant for a container // ContainerStat represent stats instant for a container