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.

URL-back Kubernetes shared toolbar filters so saved views persist exclusions

rcourtman05883ba4b23a
diff --git a/frontend-modern/src/components/Workloads/__tests__/useWorkloadsControlsState.test.ts b/frontend-modern/src/components/Workloads/__tests__/useWorkloadsControlsState.test.ts
index bb89f26506..0f133cd527 100644
--- a/frontend-modern/src/components/Workloads/__tests__/useWorkloadsControlsState.test.ts
+++ b/frontend-modern/src/components/Workloads/__tests__/useWorkloadsControlsState.test.ts
@@ -93,6 +93,33 @@ describe('useWorkloadsControlsState', () => {
});
});
+ it('URL-backs free-text search via q so saved views capture -term exclusions', () => {
+ createRoot((dispose) => {
+ try {
+ const [showFilters, setShowFilters] = createSignal(false);
+ const state = useWorkloadsControlsState({
+ viewMode: () => 'all' as ViewMode,
+ showFilters,
+ setShowFilters,
+ });
+
+ expect(state.search()).toBe('');
+
+ state.setSearch('-noisy');
+
+ expect(navigateSpy).toHaveBeenCalledWith('/workloads?q=-noisy', { replace: true });
+ expect(state.search()).toBe('-noisy');
+
+ state.setSearch('');
+
+ expect(mockRouterSearch()).toBe('');
+ expect(state.search()).toBe('');
+ } finally {
+ dispose();
+ }
+ });
+ });
+
it('persists scoped workload status so platform pages restore it when revisited', async () => {
createRoot((dispose) => {
try {
diff --git a/frontend-modern/src/features/docker/DockerContainersTable.tsx b/frontend-modern/src/features/docker/DockerContainersTable.tsx
index 1035490d1a..bbe4df1c83 100644
--- a/frontend-modern/src/features/docker/DockerContainersTable.tsx
+++ b/frontend-modern/src/features/docker/DockerContainersTable.tsx
@@ -264,10 +264,19 @@ export const DockerContainersTable: Component<DockerContainersTableProps> = (pro
return host ? base.filter((resource) => dockerHostName(resource) === host) : base;
});
const hasActiveFilters = () => tableState.hasActiveFilters() || hostFilter() !== '';
- const resetFilters = () => {
- tableState.resetFilters();
- setHostFilter('');
- };
+ // Reset must clear every URL param in ONE navigation. Consecutive
+ // setSearchParams calls each merge against the pre-navigation URL (the
+ // router commits inside an async transition), so clearing search, status,
+ // and host as three writes would leave the first two params resurrected.
+ const resetFilters = () =>
+ setSearchParams(
+ {
+ [DOCKER_QUERY_PARAMS.query]: null,
+ [DOCKER_QUERY_PARAMS.status]: null,
+ [DOCKER_QUERY_PARAMS.host]: null,
+ },
+ { replace: true },
+ );
const sortedRows = createMemo(() => [...scopedRows()].sort(compareDockerContainers));
// Runtime is host-level data repeated on every container row; it only
// informs when the fleet actually mixes runtimes (docker vs podman).
diff --git a/frontend-modern/src/features/docker/__tests__/DockerNativeTables.test.tsx b/frontend-modern/src/features/docker/__tests__/DockerNativeTables.test.tsx
index 68de02cc35..4b6757723c 100644
--- a/frontend-modern/src/features/docker/__tests__/DockerNativeTables.test.tsx
+++ b/frontend-modern/src/features/docker/__tests__/DockerNativeTables.test.tsx
@@ -412,6 +412,54 @@ describe('Docker native tables', () => {
expect(screen.queryByText('edge-web')).not.toBeInTheDocument();
});
+ it('clears search, status, and host in one navigation when resetting filters', async () => {
+ window.history.pushState({}, '', '/?q=-redis&status=offline&host=edge-01');
+
+ 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"
+ />
+ ));
+
+ fireEvent.click(screen.getByLabelText('Clear all'));
+
+ // Reset must be a single setSearchParams write: consecutive writes each
+ // merge against the pre-navigation URL (the router commits inside an
+ // async transition), so a per-param reset resurrects the params cleared
+ // by the earlier writes.
+ await waitFor(() => expect(window.location.search).toBe(''));
+ expect(screen.getByText('edge-web')).toBeInTheDocument();
+ expect(screen.getByText('edge-cache')).toBeInTheDocument();
+ });
+
it('hides the Restarts column when the current containers have no restart signal', () => {
setViewportWidth(1500);
diff --git a/frontend-modern/src/features/kubernetes/KubernetesPageSurface.tsx b/frontend-modern/src/features/kubernetes/KubernetesPageSurface.tsx
index 4cb5c10945..027b3353bf 100644
--- a/frontend-modern/src/features/kubernetes/KubernetesPageSurface.tsx
+++ b/frontend-modern/src/features/kubernetes/KubernetesPageSurface.tsx
@@ -1,5 +1,5 @@
import { useLocation, useSearchParams } from '@solidjs/router';
-import { Show, createMemo, createSignal, type Accessor } from 'solid-js';
+import { Show, createMemo, type Accessor } from 'solid-js';
import { buildInfrastructureAgentUpdatesPath } from '@/components/Settings/infrastructureWorkspaceModel';
import type { FilterDef } from '@/components/shared/FilterBar';
import { getPlatformIcon } from '@/features/platformPage/platformIcon';
@@ -9,6 +9,7 @@ import {
formatAgentVersionDisplay,
} from '@/features/platformPage/agentVersion';
import { useUnifiedResources } from '@/hooks/useUnifiedResources';
+import { KUBERNETES_QUERY_PARAMS } from '@/routing/resourceLinks';
import { updateStore } from '@/stores/updates';
import {
PLATFORM_HEALTH_FILTER_OPTIONS,
@@ -185,17 +186,46 @@ type SharedToolbarState = {
status: Accessor<KubernetesResourceStatusFilter>;
setStatus: (value: KubernetesResourceStatusFilter) => void;
hasActiveFilters: Accessor<boolean>;
- resetFilters: () => void;
+ resetFilters: (extraParams?: Record<string, string | null>) => void;
};
+// Search and status live in the URL, like the namespace scope below, so the
+// whole filter state is shareable and captured by saved views. That is what
+// makes -term exclusions persistent: search `-name`, save it as the default
+// view, and the noisy rows stay hidden on every visit. URL writes replace the
+// history entry so typing does not pile up back-button states.
function createKubernetesSharedToolbar(): SharedToolbarState {
- const [search, setSearch] = createSignal('');
- const [status, setStatus] = createSignal<KubernetesResourceStatusFilter>('all');
- const hasActiveFilters = createMemo(() => search().trim().length > 0 || status() !== 'all');
- const resetFilters = () => {
- setSearch('');
- setStatus('all');
+ const [searchParams, setSearchParams] = useSearchParams();
+ const search = () => {
+ const value = searchParams[KUBERNETES_QUERY_PARAMS.query];
+ return typeof value === 'string' ? value : '';
+ };
+ const setSearch = (value: string) =>
+ setSearchParams({ [KUBERNETES_QUERY_PARAMS.query]: value || null }, { replace: true });
+ const status = (): KubernetesResourceStatusFilter => {
+ const value = searchParams[KUBERNETES_QUERY_PARAMS.status];
+ return value === 'online' || value === 'degraded' || value === 'offline' ? value : 'all';
};
+ const setStatus = (value: KubernetesResourceStatusFilter) =>
+ setSearchParams(
+ { [KUBERNETES_QUERY_PARAMS.status]: value === 'all' ? null : value },
+ { replace: true },
+ );
+ const hasActiveFilters = createMemo(() => search().trim().length > 0 || status() !== 'all');
+ // Reset must clear every URL param in ONE navigation. Consecutive
+ // setSearchParams calls each merge against the pre-navigation URL (the
+ // router commits inside an async transition), so a second call would
+ // resurrect the params the first one just cleared. Callers pass the params
+ // they own (e.g. namespace) instead of issuing their own follow-up write.
+ const resetFilters = (extraParams?: Record<string, string | null>) =>
+ setSearchParams(
+ {
+ [KUBERNETES_QUERY_PARAMS.query]: null,
+ [KUBERNETES_QUERY_PARAMS.status]: null,
+ ...extraParams,
+ },
+ { replace: true },
+ );
return { search, setSearch, status, setStatus, hasActiveFilters, resetFilters };
}
@@ -215,7 +245,6 @@ type KubernetesNamespaceScope = {
scopedSections: Accessor<Resource[][]>;
scopeFilters: Accessor<FilterDef[]>;
hasActiveNamespace: Accessor<boolean>;
- clearNamespace: () => void;
};
// Namespace scope for a shared-toolbar Kubernetes tab. Namespace is the primary
@@ -227,8 +256,10 @@ function createKubernetesNamespaceScope(
sections: Accessor<Resource[][]>,
): KubernetesNamespaceScope {
const [searchParams, setSearchParams] = useSearchParams();
- const namespaceFilter = () =>
- typeof searchParams.namespace === 'string' ? searchParams.namespace : '';
+ const namespaceFilter = () => {
+ const value = searchParams[KUBERNETES_QUERY_PARAMS.namespace];
+ return typeof value === 'string' ? value : '';
+ };
const namespaceOf = (resource: Resource) => (resource.kubernetes?.namespace ?? '').trim();
const matchesNamespace = (resource: Resource) => {
const namespace = namespaceFilter();
@@ -259,7 +290,8 @@ function createKubernetesNamespaceScope(
...namespaceOptions().map((namespace) => ({ value: namespace, label: namespace })),
],
value: namespaceFilter,
- setValue: (value: string) => setSearchParams({ namespace: value || null }),
+ setValue: (value: string) =>
+ setSearchParams({ [KUBERNETES_QUERY_PARAMS.namespace]: value || null }),
defaultValue: '',
},
];
@@ -268,7 +300,6 @@ function createKubernetesNamespaceScope(
scopedSections,
scopeFilters,
hasActiveNamespace: () => namespaceFilter() !== '',
- clearNamespace: () => setSearchParams({ namespace: null }),
};
}
@@ -297,10 +328,8 @@ function KubernetesWorkloads(props: { model: KubernetesPageModel; controllers: R
countKubernetesVisible(scope.scopedSections(), toolbar.search(), toolbar.status()),
);
const hasActiveFilters = () => toolbar.hasActiveFilters() || scope.hasActiveNamespace();
- const resetFilters = () => {
- toolbar.resetFilters();
- scope.clearNamespace();
- };
+ const resetFilters = () =>
+ toolbar.resetFilters({ [KUBERNETES_QUERY_PARAMS.namespace]: null });
return (
<Show
@@ -395,10 +424,8 @@ function KubernetesServices(props: { model: KubernetesPageModel }) {
countKubernetesVisible(scope.scopedSections(), toolbar.search(), toolbar.status()),
);
const hasActiveFilters = () => toolbar.hasActiveFilters() || scope.hasActiveNamespace();
- const resetFilters = () => {
- toolbar.resetFilters();
- scope.clearNamespace();
- };
+ const resetFilters = () =>
+ toolbar.resetFilters({ [KUBERNETES_QUERY_PARAMS.namespace]: null });
return (
<Show
@@ -468,10 +495,8 @@ function KubernetesConfiguration(props: { model: KubernetesPageModel }) {
countKubernetesVisible(scope.scopedSections(), toolbar.search(), toolbar.status()),
);
const hasActiveFilters = () => toolbar.hasActiveFilters() || scope.hasActiveNamespace();
- const resetFilters = () => {
- toolbar.resetFilters();
- scope.clearNamespace();
- };
+ const resetFilters = () =>
+ toolbar.resetFilters({ [KUBERNETES_QUERY_PARAMS.namespace]: null });
return (
<Show
diff --git a/frontend-modern/src/features/kubernetes/__tests__/KubernetesPageSurfaceUrlFilters.test.tsx b/frontend-modern/src/features/kubernetes/__tests__/KubernetesPageSurfaceUrlFilters.test.tsx
new file mode 100644
index 0000000000..af34629d60
--- /dev/null
+++ b/frontend-modern/src/features/kubernetes/__tests__/KubernetesPageSurfaceUrlFilters.test.tsx
@@ -0,0 +1,145 @@
+import { Route, Router } from '@solidjs/router';
+import { cleanup, fireEvent, render, screen, waitFor } from '@solidjs/testing-library';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import type { Resource } from '@/types/resource';
+import { KubernetesPageSurface } from '../KubernetesPageSurface';
+
+// URL-backed shared-toolbar filters: the workloads / services / configuration
+// tabs read search (q) and status from the URL so saved views capture -term
+// exclusions, mirroring the Docker containers table. These tests render the
+// real surface with a real router; only the data hooks are mocked.
+
+const mockUseUnifiedResources = vi.fn();
+const mockVersionInfo = vi.hoisted(() => vi.fn());
+
+vi.mock('@/hooks/useUnifiedResources', () => ({
+ useUnifiedResources: (...args: unknown[]) => mockUseUnifiedResources(...args),
+}));
+
+vi.mock('@/stores/updates', () => ({
+ updateStore: {
+ versionInfo: mockVersionInfo,
+ },
+}));
+
+const makeResource = (resource: Partial<Resource> & Pick<Resource, 'id' | 'type'>): Resource => ({
+ name: resource.id,
+ displayName: resource.id,
+ platformId: 'cluster-1',
+ platformType: 'kubernetes',
+ sourceType: 'agent',
+ sources: ['kubernetes'],
+ status: 'online',
+ lastSeen: 1_700_000_000_000,
+ kubernetes: {
+ clusterId: 'cluster-1',
+ clusterName: 'Cluster 1',
+ namespace: 'default',
+ },
+ ...resource,
+});
+
+const setResources = (resources: Resource[]) => {
+ mockUseUnifiedResources.mockReturnValue({
+ resources: () => resources,
+ loading: () => false,
+ error: () => null,
+ refetch: vi.fn(),
+ });
+};
+
+const renderSurfaceAt = (url: string) => {
+ window.history.pushState({}, '', url);
+ return render(() => (
+ <Router>
+ <Route path="/kubernetes/:section?" component={KubernetesPageSurface} />
+ </Router>
+ ));
+};
+
+afterEach(() => {
+ cleanup();
+ vi.clearAllMocks();
+});
+
+beforeEach(() => {
+ mockVersionInfo.mockReturnValue(undefined);
+ window.history.pushState({}, '', '/kubernetes');
+});
+
+describe('Kubernetes URL-backed shared toolbar filters', () => {
+ it('applies the URL search filter, including -term exclusions, on the workloads tab', () => {
+ setResources([
+ makeResource({ id: 'checkout-api', type: 'k8s-deployment' }),
+ makeResource({ id: 'cache-worker', type: 'k8s-deployment' }),
+ ]);
+
+ renderSurfaceAt('/kubernetes/workloads?q=-cache');
+
+ expect(screen.getByText('checkout-api')).toBeInTheDocument();
+ expect(screen.queryByText('cache-worker')).not.toBeInTheDocument();
+ });
+
+ it('applies the URL status filter on the workloads tab', () => {
+ setResources([
+ makeResource({ id: 'checkout-api', type: 'k8s-deployment', status: 'online' }),
+ makeResource({ id: 'batch-runner', type: 'k8s-deployment', status: 'offline' }),
+ ]);
+
+ renderSurfaceAt('/kubernetes/workloads?status=offline');
+
+ expect(screen.getByText('batch-runner')).toBeInTheDocument();
+ expect(screen.queryByText('checkout-api')).not.toBeInTheDocument();
+ });
+
+ it('applies the URL search filter on the services tab', () => {
+ setResources([
+ makeResource({ id: 'checkout-svc', type: 'k8s-service' }),
+ makeResource({ id: 'cache-svc', type: 'k8s-service' }),
+ ]);
+
+ renderSurfaceAt('/kubernetes/services?q=-cache');
+
+ expect(screen.getByText('checkout-svc')).toBeInTheDocument();
+ expect(screen.queryByText('cache-svc')).not.toBeInTheDocument();
+ });
+
+ it('applies the URL search filter on the configuration tab', () => {
+ setResources([
+ makeResource({ id: 'app-settings', type: 'k8s-configmap' }),
+ makeResource({ id: 'cache-settings', type: 'k8s-configmap' }),
+ ]);
+
+ renderSurfaceAt('/kubernetes/config?q=-cache');
+
+ expect(screen.getByText('app-settings')).toBeInTheDocument();
+ expect(screen.queryByText('cache-settings')).not.toBeInTheDocument();
+ });
+
+ it('clears search, status, and namespace in one navigation on reset', async () => {
+ setResources([
+ makeResource({
+ id: 'checkout-api',
+ type: 'k8s-deployment',
+ kubernetes: { clusterId: 'cluster-1', clusterName: 'Cluster 1', namespace: 'prod' },
+ }),
+ makeResource({
+ id: 'cache-worker',
+ type: 'k8s-deployment',
+ status: 'offline',
+ kubernetes: { clusterId: 'cluster-1', clusterName: 'Cluster 1', namespace: 'staging' },
+ }),
+ ]);
+
+ renderSurfaceAt('/kubernetes/workloads?q=-cache&status=offline&namespace=prod');
+
+ fireEvent.click(screen.getByLabelText('Clear all'));
+
+ // A multi-write reset would leave earlier-cleared params resurrected by
+ // later writes (each merges against the pre-navigation URL); the settled
+ // URL must lose all three params.
+ await waitFor(() => expect(window.location.search).toBe(''));
+ expect(screen.getByText('checkout-api')).toBeInTheDocument();
+ expect(screen.getByText('cache-worker')).toBeInTheDocument();
+ });
+});
diff --git a/frontend-modern/src/routing/resourceLinks.ts b/frontend-modern/src/routing/resourceLinks.ts
index 5eba4e58e3..3623eaca40 100644
--- a/frontend-modern/src/routing/resourceLinks.ts
+++ b/frontend-modern/src/routing/resourceLinks.ts
@@ -62,6 +62,12 @@ export const DOCKER_QUERY_PARAMS = {
status: 'status',
} as const;
+export const KUBERNETES_QUERY_PARAMS = {
+ namespace: 'namespace',
+ query: 'q',
+ status: 'status',
+} as const;
+
export const STORAGE_QUERY_PARAMS = {
tab: 'tab',
group: 'group',