Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Add -term search exclusions and persistent Docker container filter views

rcourtmanc30e223704b7
diff --git a/frontend-modern/src/components/Workloads/__tests__/workloadSelectors.test.ts b/frontend-modern/src/components/Workloads/__tests__/workloadSelectors.test.ts
index bc51a892c8..9fcc67c768 100644
--- a/frontend-modern/src/components/Workloads/__tests__/workloadSelectors.test.ts
+++ b/frontend-modern/src/components/Workloads/__tests__/workloadSelectors.test.ts
@@ -146,6 +146,37 @@ describe('workloadSelectors', () => {
expect(combined.map((g) => g.name)).toEqual(['alpha-api']);
});
+ it('hides workloads matching -term exclusions while keeping comma OR semantics', () => {
+ const guests = [
+ makeGuest(1, { name: 'alpha-api', vmid: 201, node: 'node-a', status: 'running' }),
+ makeGuest(2, { name: 'beta-worker', vmid: 202, node: 'node-b', status: 'running' }),
+ makeGuest(3, { name: 'gamma-db', vmid: 303, node: 'node-c', status: 'stopped' }),
+ ];
+
+ const excluded = filterWorkloads({
+ guests,
+ viewMode: 'all',
+ statusMode: 'all',
+ searchTerm: '-worker',
+ selectedNode: null,
+ selectedHostHint: null,
+ selectedKubernetesContext: null,
+ });
+ expect(excluded.map((g) => g.name)).toEqual(['alpha-api', 'gamma-db']);
+
+ const mixed = filterWorkloads({
+ guests,
+ viewMode: 'all',
+ statusMode: 'all',
+ searchTerm: 'alpha, beta -worker',
+ selectedNode: null,
+ selectedHostHint: null,
+ selectedKubernetesContext: null,
+ });
+ // Exclusions apply globally; the remaining text parts still OR together.
+ expect(mixed.map((g) => g.name)).toEqual(['alpha-api']);
+ });
+
it('searches workload-native fields shown by platform pages', () => {
const guests = [
makeGuest(1, {
diff --git a/frontend-modern/src/components/Workloads/workloadSelectors.ts b/frontend-modern/src/components/Workloads/workloadSelectors.ts
index 029b1edfd3..74fd7d64e7 100644
--- a/frontend-modern/src/components/Workloads/workloadSelectors.ts
+++ b/frontend-modern/src/components/Workloads/workloadSelectors.ts
@@ -3,7 +3,11 @@ import type { WorkloadGuest, ViewMode } from '@/types/workloads';
import type { WorkloadIOEmphasis } from './guestRowModel';
import { computeIOScale } from '@/components/Infrastructure/infrastructureSelectors';
import type { SummarySeriesGroupScope } from '@/components/shared/summaryCardInteraction';
-import { parseFilterStack, evaluateFilterStack } from '@/utils/searchQuery';
+import {
+ parseFilterStack,
+ evaluateFilterStack,
+ splitSearchExclusions,
+} from '@/utils/searchQuery';
import { normalizeSourcePlatformQueryValue } from '@/utils/sourcePlatforms';
import { DEGRADED_HEALTH_STATUSES, OFFLINE_HEALTH_STATUSES } from '@/utils/status';
import { getNodeDisplayName } from '@/utils/nodes';
@@ -173,12 +177,17 @@ export const filterWorkloads = ({
const filters: string[] = [];
const textSearches: string[] = [];
+ // `-term` exclusions apply across the whole result set (AND NOT), while
+ // the remaining comma-separated text parts keep their OR semantics.
+ const exclusions: string[] = [];
searchParts.forEach((part) => {
if (part.includes('>') || part.includes('<') || part.includes(':')) {
filters.push(part);
} else {
- textSearches.push(part.toLowerCase());
+ const split = splitSearchExclusions(part);
+ exclusions.push(...split.excludes);
+ if (split.needle) textSearches.push(split.needle);
}
});
@@ -190,6 +199,12 @@ export const filterWorkloads = ({
}
}
+ if (exclusions.length > 0) {
+ guests = guests.filter(
+ (g) => !exclusions.some((term) => matchesWorkloadTextSearch(g, term)),
+ );
+ }
+
if (textSearches.length > 0) {
guests = guests.filter((g) =>
textSearches.some((term) => matchesWorkloadTextSearch(g, term)),
diff --git a/frontend-modern/src/features/docker/DockerContainersTable.tsx b/frontend-modern/src/features/docker/DockerContainersTable.tsx
index 63d93811aa..1035490d1a 100644
--- a/frontend-modern/src/features/docker/DockerContainersTable.tsx
+++ b/frontend-modern/src/features/docker/DockerContainersTable.tsx
@@ -177,20 +177,56 @@ const containerUpdateAction = (
};
};
+const DOCKER_CONTAINER_SEARCH_TIPS = {
+ popoverId: 'docker-containers-search-help',
+ intro: 'Filter containers by name, image, compose stack, or label.',
+ tips: [
+ { code: 'nginx', description: 'Match container names, images, and labels' },
+ { code: '-watchtower', description: 'Hide containers matching a term' },
+ ],
+ footerHighlight: 'Tip',
+ footerText:
+ 'Combine exclusions and save them as a default view to keep noisy containers hidden.',
+};
+
export const DockerContainersTable: Component<DockerContainersTableProps> = (props) => {
const breakpoint = useBreakpoint();
const layoutMode = createMemo(() => getWorkloadTableLayoutMode(breakpoint.width()));
+ // Search and status live in the URL, like the host scope below, so the
+ // whole filter state is shareable and captured by saved views. That is what
+ // makes exclusions persistent: search `-name`, save it as the default view,
+ // and the containers stay hidden on every visit. URL writes replace the
+ // history entry so typing does not pile up back-button states.
+ const [searchParams, setSearchParams] = useSearchParams();
+ const searchFilter = () => {
+ const value = searchParams[DOCKER_QUERY_PARAMS.query];
+ return typeof value === 'string' ? value : '';
+ };
+ const setSearchFilter = (value: string) =>
+ setSearchParams({ [DOCKER_QUERY_PARAMS.query]: value || null }, { replace: true });
+ const statusFilter = (): DockerResourceStatusFilter => {
+ const value = searchParams[DOCKER_QUERY_PARAMS.status];
+ return value === 'online' || value === 'degraded' || value === 'offline' ? value : 'all';
+ };
+ const setStatusFilter = (value: DockerResourceStatusFilter) =>
+ setSearchParams(
+ { [DOCKER_QUERY_PARAMS.status]: value === 'all' ? null : value },
+ { replace: true },
+ );
const tableState = createPlatformTableFilterState({
resources: () => props.resources,
initialStatus: 'all' as DockerResourceStatusFilter,
filter: filterDockerResources,
+ externalSearch: searchFilter,
+ onExternalSearchChange: setSearchFilter,
+ externalStatus: statusFilter,
+ onExternalStatusChange: setStatusFilter,
});
// Host scope filter, URL-backed so it is shareable and captured by saved
// views. Distinct hosts are derived from the current resource set; the facet
// only appears once more than one host is present (a single-host fleet has
// nothing to scope by).
- const [searchParams, setSearchParams] = useSearchParams();
const hostFilter = () => {
const host = searchParams[DOCKER_QUERY_PARAMS.host];
return typeof host === 'string' ? host : '';
@@ -285,6 +321,7 @@ export const DockerContainersTable: Component<DockerContainersTableProps> = (pro
search={tableState.search}
onSearchChange={tableState.setSearch}
searchPlaceholder="Search containers"
+ searchTips={DOCKER_CONTAINER_SEARCH_TIPS}
status={tableState.status()}
onStatusChange={tableState.setStatus}
statusOptions={PLATFORM_HEALTH_FILTER_OPTIONS}
diff --git a/frontend-modern/src/features/docker/__tests__/DockerNativeTables.test.tsx b/frontend-modern/src/features/docker/__tests__/DockerNativeTables.test.tsx
index 6b01a65cca..68de02cc35 100644
--- a/frontend-modern/src/features/docker/__tests__/DockerNativeTables.test.tsx
+++ b/frontend-modern/src/features/docker/__tests__/DockerNativeTables.test.tsx
@@ -328,6 +328,90 @@ describe('Docker native tables', () => {
expect(screen.queryByText('edge-01')).not.toBeInTheDocument();
});
+ it('applies the URL search filter, including -term exclusions, to container rows', () => {
+ window.history.pushState({}, '', '/?q=-redis');
+
+ renderInRouter(() => (
+ <DockerContainersTable
+ resources={[
+ makeResource({
+ id: 'container-1',
+ type: 'app-container',
+ name: 'edge-web',
+ status: 'running',
+ docker: {
+ hostname: 'edge-01',
+ runtime: 'docker',
+ image: 'nginx:latest',
+ containerState: 'running',
+ },
+ }),
+ makeResource({
+ id: 'container-2',
+ type: 'app-container',
+ name: 'edge-cache',
+ status: 'running',
+ docker: {
+ hostname: 'edge-02',
+ runtime: 'docker',
+ image: 'redis:7.4',
+ containerState: 'running',
+ },
+ }),
+ ]}
+ emptyIcon={<span />}
+ emptyTitle="No containers"
+ emptyDescription="No containers"
+ showToolbar={false}
+ />
+ ));
+
+ expect(screen.getByText('edge-web')).toBeInTheDocument();
+ expect(screen.queryByText('edge-cache')).not.toBeInTheDocument();
+ });
+
+ it('applies the URL status filter to container rows', () => {
+ window.history.pushState({}, '', '/?status=offline');
+
+ renderInRouter(() => (
+ <DockerContainersTable
+ resources={[
+ makeResource({
+ id: 'container-1',
+ type: 'app-container',
+ name: 'edge-web',
+ status: 'running',
+ docker: {
+ hostname: 'edge-01',
+ runtime: 'docker',
+ image: 'nginx:latest',
+ containerState: 'running',
+ },
+ }),
+ makeResource({
+ id: 'container-2',
+ type: 'app-container',
+ name: 'edge-cache',
+ status: 'offline',
+ docker: {
+ hostname: 'edge-02',
+ runtime: 'docker',
+ image: 'redis:7.4',
+ containerState: 'exited',
+ },
+ }),
+ ]}
+ emptyIcon={<span />}
+ emptyTitle="No containers"
+ emptyDescription="No containers"
+ showToolbar={false}
+ />
+ ));
+
+ expect(screen.getByText('edge-cache')).toBeInTheDocument();
+ expect(screen.queryByText('edge-web')).not.toBeInTheDocument();
+ });
+
it('hides the Restarts column when the current containers have no restart signal', () => {
setViewportWidth(1500);
diff --git a/frontend-modern/src/features/docker/__tests__/dockerPageModel.test.ts b/frontend-modern/src/features/docker/__tests__/dockerPageModel.test.ts
index 587e8e7794..d70730e834 100644
--- a/frontend-modern/src/features/docker/__tests__/dockerPageModel.test.ts
+++ b/frontend-modern/src/features/docker/__tests__/dockerPageModel.test.ts
@@ -791,6 +791,24 @@ describe('dockerPageModel', () => {
]);
});
+ it('hides rows matching -term exclusions', () => {
+ expect(filterDockerResources(rows, '-worker', 'all').map((r) => r.id)).toEqual([
+ 'web',
+ 'edge-proxy',
+ 'redis-vol',
+ ]);
+ // Exclusions search the same haystack as positive terms (image, swarm
+ // cluster, volume name), and combine with a positive needle.
+ expect(filterDockerResources(rows, '-traefik -redis', 'all').map((r) => r.id)).toEqual([
+ 'web',
+ 'svc-payments',
+ 'svc-search',
+ ]);
+ expect(filterDockerResources(rows, 'worker -payments', 'all').map((r) => r.id)).toEqual([
+ 'svc-search',
+ ]);
+ });
+
it('matches container labels and Swarm stack names', () => {
const labelled: Resource[] = [
...rows,
diff --git a/frontend-modern/src/features/docker/dockerPageModel.ts b/frontend-modern/src/features/docker/dockerPageModel.ts
index b3d11542d1..c40fdcb76d 100644
--- a/frontend-modern/src/features/docker/dockerPageModel.ts
+++ b/frontend-modern/src/features/docker/dockerPageModel.ts
@@ -1,4 +1,5 @@
import { resolveResourcePlatformType } from '@/utils/sourcePlatforms';
+import { matchesSearchTermSplit, splitSearchExclusions } from '@/utils/searchQuery';
import type {
DockerStorageUsageMeta,
Resource,
@@ -498,18 +499,19 @@ export function filterDockerResources(
search: string,
status: DockerResourceStatusFilter,
): Resource[] {
- const needle = search.trim().toLowerCase();
+ const split = splitSearchExclusions(search);
+ const hasSearch = split.needle.length > 0 || split.excludes.length > 0;
const result: Resource[] = [];
for (const resource of resources) {
if (status !== 'all') {
const triad = mapResourceStatusToTriad(resource.status);
if (triad !== status) continue;
}
- if (!needle) {
+ if (!hasSearch) {
result.push(resource);
continue;
}
- if (dockerResourceSearchHaystack(resource).includes(needle)) {
+ if (matchesSearchTermSplit(dockerResourceSearchHaystack(resource), split)) {
result.push(resource);
}
}
diff --git a/frontend-modern/src/features/kubernetes/kubernetesPageModel.ts b/frontend-modern/src/features/kubernetes/kubernetesPageModel.ts
index 1584aa01e1..a6ab3bb40d 100644
--- a/frontend-modern/src/features/kubernetes/kubernetesPageModel.ts
+++ b/frontend-modern/src/features/kubernetes/kubernetesPageModel.ts
@@ -6,6 +6,7 @@ import type {
} from '@/types/resource';
import type { StatusIndicator, StatusIndicatorVariant } from '@/utils/status';
import { resolveResourcePlatformType } from '@/utils/sourcePlatforms';
+import { matchesSearchTermSplit, splitSearchExclusions } from '@/utils/searchQuery';
export type KubernetesPageTabId =
| 'overview'
@@ -557,18 +558,19 @@ export function filterKubernetesResources(
search: string,
status: KubernetesResourceStatusFilter,
): Resource[] {
- const needle = search.trim().toLowerCase();
+ const split = splitSearchExclusions(search);
+ const hasSearch = split.needle.length > 0 || split.excludes.length > 0;
const result: Resource[] = [];
for (const resource of resources) {
if (status !== 'all') {
const triad = mapResourceStatusToTriad(resource.status);
if (triad !== status) continue;
}
- if (!needle) {
+ if (!hasSearch) {
result.push(resource);
continue;
}
- if (kubernetesResourceSearchHaystack(resource).includes(needle)) {
+ if (matchesSearchTermSplit(kubernetesResourceSearchHaystack(resource), split)) {
result.push(resource);
}
}
diff --git a/frontend-modern/src/features/platformPage/sharedPlatformPage.tsx b/frontend-modern/src/features/platformPage/sharedPlatformPage.tsx
index a462681a18..b627f0922e 100644
--- a/frontend-modern/src/features/platformPage/sharedPlatformPage.tsx
+++ b/frontend-modern/src/features/platformPage/sharedPlatformPage.tsx
@@ -13,6 +13,11 @@ import { useBreakpoint } from '@/hooks/useBreakpoint';
import { UnifiedResourceTable } from '@/components/Infrastructure/UnifiedResourceTable';
import type { Resource } from '@/types/resource';
import { formatBytes, formatRelativeTime, formatUptime } from '@/utils/format';
+import {
+ matchesSearchTermSplit,
+ splitSearchExclusions,
+ type SearchTermSplit,
+} from '@/utils/searchQuery';
import { asTrimmedString } from '@/utils/stringUtils';
import { formatVmwareClusterServices } from '@/utils/vmwareDisplay';
import { getPlatformColumnAlign, type PlatformTableColumnKind } from './columnAlignment';
@@ -620,10 +625,8 @@ const mapResourceStatusToTriad = (
// platform-agnostic and only knows about the generic Resource surface plus
// the small number of provider blocks that still consume it directly
// (Proxmox Mail Gateway, vSphere hosts table).
-const matchesPlatformSearch = (resource: Resource, search: string): boolean => {
- if (!search) return true;
- const needle = search.trim().toLowerCase();
- if (!needle) return true;
+const matchesPlatformSearch = (resource: Resource, split: SearchTermSplit): boolean => {
+ if (!split.needle && split.excludes.length === 0) return true;
const haystack = [
resource.name,
resource.displayName,
@@ -653,7 +656,7 @@ const matchesPlatformSearch = (resource: Resource, search: string): boolean => {
.filter((value): value is string => typeof value === 'string')
.join(' ')
.toLowerCase();
- return haystack.includes(needle);
+ return matchesSearchTermSplit(haystack, split);
};
export const filterPlatformResources = (
@@ -662,9 +665,10 @@ export const filterPlatformResources = (
status: PlatformResourceStatusFilter,
resolveStatus: (resource: Resource) => string | undefined = (resource) => resource.status,
): Resource[] => {
+ const split = splitSearchExclusions(search);
const result: Resource[] = [];
for (const resource of resources) {
- if (!matchesPlatformSearch(resource, search)) continue;
+ if (!matchesPlatformSearch(resource, split)) continue;
if (status !== 'all') {
const mapped = mapResourceStatusToTriad(resolveStatus(resource));
if (mapped !== status) continue;
diff --git a/frontend-modern/src/routing/resourceLinks.ts b/frontend-modern/src/routing/resourceLinks.ts
index f97b3d3a64..5eba4e58e3 100644
--- a/frontend-modern/src/routing/resourceLinks.ts
+++ b/frontend-modern/src/routing/resourceLinks.ts
@@ -58,6 +58,8 @@ export const isExternalAgentSetupHash = (hash: string | null | undefined): boole
export const DOCKER_QUERY_PARAMS = {
host: 'host',
+ query: 'q',
+ status: 'status',
} as const;
export const STORAGE_QUERY_PARAMS = {
diff --git a/frontend-modern/src/utils/__tests__/searchQuery.test.ts b/frontend-modern/src/utils/__tests__/searchQuery.test.ts
index 39101a613c..27c714498f 100644
--- a/frontend-modern/src/utils/__tests__/searchQuery.test.ts
+++ b/frontend-modern/src/utils/__tests__/searchQuery.test.ts
@@ -1,5 +1,11 @@
import { describe, expect, it } from 'vitest';
-import { parseFilter, parseFilterStack, evaluateFilterStack } from '@/utils/searchQuery';
+import {
+ parseFilter,
+ parseFilterStack,
+ evaluateFilterStack,
+ splitSearchExclusions,
+ matchesSearchTermSplit,
+} from '@/utils/searchQuery';
import type { VM } from '@/types/api';
describe('parseFilter', () => {
@@ -362,4 +368,55 @@ describe('evaluateFilterStack', () => {
expect(result).toBe(false);
});
});
+
+ describe('splitSearchExclusions', () => {
+ it('splits -terms out of the positive needle', () => {
+ expect(splitSearchExclusions('nginx -watchtower -Certbot')).toEqual({
+ needle: 'nginx',
+ excludes: ['watchtower', 'certbot'],
+ });
+ });
+
+ it('keeps multi-word positive searches as one substring needle', () => {
+ expect(splitSearchExclusions(' Web Server ')).toEqual({
+ needle: 'web server',
+ excludes: [],
+ });
+ });
+
+ it('supports exclusion-only searches', () => {
+ expect(splitSearchExclusions('-backup')).toEqual({ needle: '', excludes: ['backup'] });
+ });
+
+ it('does not treat interior hyphens or a lone dash as exclusions', () => {
+ expect(splitSearchExclusions('my-app -')).toEqual({
+ needle: 'my-app -',
+ excludes: [],
+ });
+ });
+
+ it('returns empty state for blank input', () => {
+ expect(splitSearchExclusions(' ')).toEqual({ needle: '', excludes: [] });
+ });
+ });
+
+ describe('matchesSearchTermSplit', () => {
+ it('hides haystacks containing any excluded term', () => {
+ const split = splitSearchExclusions('-watchtower');
+ expect(matchesSearchTermSplit('watchtower latest', split)).toBe(false);
+ expect(matchesSearchTermSplit('nginx stable', split)).toBe(true);
+ });
+
+ it('requires the positive needle when present', () => {
+ const split = splitSearchExclusions('nginx -prod');
+ expect(matchesSearchTermSplit('nginx staging', split)).toBe(true);
+ expect(matchesSearchTermSplit('nginx prod-eu', split)).toBe(false);
+ expect(matchesSearchTermSplit('redis staging', split)).toBe(false);
+ });
+
+ it('matches everything when the split is empty', () => {
+ const split = splitSearchExclusions('');
+ expect(matchesSearchTermSplit('anything', split)).toBe(true);
+ });
+ });
});
diff --git a/frontend-modern/src/utils/searchQuery.ts b/frontend-modern/src/utils/searchQuery.ts
index 87211d8997..975339d0c4 100644
--- a/frontend-modern/src/utils/searchQuery.ts
+++ b/frontend-modern/src/utils/searchQuery.ts
@@ -1,5 +1,39 @@
import type { VM, Container } from '@/types/api';
+// Exclusion-aware split of a free-text search. Terms prefixed with `-` hide
+// matching rows ("-watchtower" hides anything whose haystack contains
+// "watchtower"); everything else is kept intact, joined back together, and
+// matched as a single case-insensitive substring so existing multi-word
+// searches keep their meaning. Shared by every platform table search
+// predicate so `-term` behaves identically on Docker, Kubernetes, workloads,
+// and the generic platform tables.
+export interface SearchTermSplit {
+ needle: string;
+ excludes: string[];
+}
+
+export function splitSearchExclusions(search: string): SearchTermSplit {
+ const excludes: string[] = [];
+ const kept: string[] = [];
+ for (const token of search.trim().split(/\s+/)) {
+ if (!token) continue;
+ if (token.length > 1 && token.startsWith('-')) {
+ excludes.push(token.slice(1).toLowerCase());
+ } else {
+ kept.push(token);
+ }
+ }
+ return { needle: kept.join(' ').toLowerCase(), excludes };
+}
+
+export function matchesSearchTermSplit(haystack: string, split: SearchTermSplit): boolean {
+ for (const exclude of split.excludes) {
+ if (haystack.includes(exclude)) return false;
+ }
+ if (!split.needle) return true;
+ return haystack.includes(split.needle);
+}
+
export type ComparisonOperator = '>' | '<' | '>=' | '<=' | '=' | '==';
export type LogicalOperator = 'AND' | 'OR';