A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.
feat: add Docker name filter matching controls (#7105)
Thomas6c30b39cae65
diff --git a/apps/docs/docs/widgets/docker-containers/index.mdx b/apps/docs/docs/widgets/docker-containers/index.mdxindex 120e5415d..1de9badf1 100644--- a/apps/docs/docs/widgets/docker-containers/index.mdx+++ b/apps/docs/docs/widgets/docker-containers/index.mdx@@ -26,6 +26,15 @@ import dockerTable from "./img/table.png";<img src={dockerTable.src} alt="docker-stats table docker-containers" width={128 * 3} height={128 * 2} />+### Container filters++Filters match complete container names and are case sensitive by default. Matching containers are excluded+unless **Filter as a whitelist** is enabled. An empty filter shows all containers in either mode.++Enable **Allow wildcards** to use `*` for zero or more characters: `qbit*` matches `qbittorrent`, and+`*arr` matches names ending in `arr`. The entire name must still match. All other characters, including+`%` and regex symbols, are literal. Disable **Case sensitive** to match `Qbittorrent` with `qbittorrent`.+### InteractionsColumn order and width are saved per widget. These controls are unavailable while the board is in edit mode.diff --git a/packages/translation/src/lang/en.json b/packages/translation/src/lang/en.jsonindex 991b96405..2a09a8bc2 100644--- a/packages/translation/src/lang/en.json+++ b/packages/translation/src/lang/en.json@@ -3381,6 +3381,13 @@"containerFilter": {"label": "Containers to filter"},+ "filterCaseSensitive": {+ "label": "Case sensitive"+ },+ "filterAllowWildcards": {+ "label": "Allow wildcards",+ "description": "Use * for zero or more characters."+ },"filterIsWhitelist": {"label": "Filter as a whitelist"},diff --git a/packages/widgets/src/docker/component.tsx b/packages/widgets/src/docker/component.tsxindex 956ec8892..1ba725671 100644--- a/packages/widgets/src/docker/component.tsx+++ b/packages/widgets/src/docker/component.tsx@@ -51,6 +51,7 @@ import { getUsableWidgetQueryData } from "../common/query-state";import actionTargetClasses from "../common/action-target.module.css";import { HomarrDataTable } from "../common/homarr-data-table";import { usePersistedTableLayout, useTableLayoutPersistence } from "../common/use-persisted-table-layout";+import { matchesContainerFilter } from "./filter";import { getDockerColumnVisibility, getDockerFooterVisibility } from "./layout";type DockerContainer = RouterOutputs["docker"]["getContainers"]["containers"][number];@@ -95,12 +96,6 @@ const getContainersQueryInput = (endpointIds: string[]) => {return { endpointIds };};-function matchesContainerFilter(name: string, containerFilter: string[], filterIsWhitelist: boolean): boolean {- if (containerFilter.length === 0) return true;- const matches = containerFilter.includes(name);- return filterIsWhitelist === matches;-}-const ContainerStateBadge = ({ state }: { state: ContainerState }) => {const t = useI18n("docker.field.state.option");@@ -289,9 +284,20 @@ export default function DockerWidget({const containers = useMemo(() =>(data?.containers ?? []).filter((container) =>- matchesContainerFilter(container.name, options.containerFilter, options.filterIsWhitelist),+ matchesContainerFilter(container.name, {+ containerFilter: options.containerFilter,+ filterIsWhitelist: options.filterIsWhitelist,+ filterCaseSensitive: options.filterCaseSensitive,+ filterAllowWildcards: options.filterAllowWildcards,+ }),),- [data?.containers, options.containerFilter, options.filterIsWhitelist],+ [+ data?.containers,+ options.containerFilter,+ options.filterIsWhitelist,+ options.filterCaseSensitive,+ options.filterAllowWildcards,+ ],);const timestamp = useMemo(() => data?.timestamp ?? new Date(), [data?.timestamp]);const relativeTime = useTimeAgo(timestamp);diff --git a/packages/widgets/src/docker/filter.ts b/packages/widgets/src/docker/filter.tsnew file mode 100644index 000000000..6ccd9e51c--- /dev/null+++ b/packages/widgets/src/docker/filter.ts@@ -0,0 +1,35 @@+interface ContainerFilterOptions {+ containerFilter: string[];+ filterIsWhitelist: boolean;+ filterCaseSensitive: boolean;+ filterAllowWildcards: boolean;+}++export function matchesContainerFilter(name: string, options: ContainerFilterOptions): boolean {+ if (options.containerFilter.length === 0) return true;++ let candidate = name;+ if (!options.filterCaseSensitive) candidate = candidate.toLowerCase();++ const matches = options.containerFilter.some((filter) => {+ let pattern = filter;+ if (!options.filterCaseSensitive) pattern = pattern.toLowerCase();+ if (!options.filterAllowWildcards || !pattern.includes("*")) return candidate === pattern;++ const parts = pattern.split("*");+ const first = parts[0] ?? "";+ if (!candidate.startsWith(first)) return false;++ let offset = first.length;+ for (const part of parts.slice(1, -1)) {+ const index = candidate.indexOf(part, offset);+ if (index === -1) return false;+ offset = index + part.length;+ }++ const last = parts.at(-1) ?? "";+ return candidate.endsWith(last) && candidate.length - last.length >= offset;+ });++ return options.filterIsWhitelist === matches;+}diff --git a/packages/widgets/src/docker/index.ts b/packages/widgets/src/docker/index.tsindex 8fb190cae..42edee3b7 100644--- a/packages/widgets/src/docker/index.ts+++ b/packages/widgets/src/docker/index.ts@@ -77,6 +77,13 @@ export const { definition, componentLoader } = createWidgetDefinition("dockerConfilterIsWhitelist: factory.switch({defaultValue: false,}),+ filterCaseSensitive: factory.switch({+ defaultValue: true,+ }),+ filterAllowWildcards: factory.switch({+ defaultValue: false,+ withDescription: true,+ }),columnOrder: factory.text({ defaultValue: "" }),columnWidths: factory.text({ defaultValue: "" }),}),