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 version, default-view, and isDefault to saved view schema

rcourtman47e0564ca128
diff --git a/frontend-modern/src/components/shared/FilterBar/SavedViewsMenu.tsx b/frontend-modern/src/components/shared/FilterBar/SavedViewsMenu.tsx
index 87cb3c1a6e..7356f6623b 100644
--- a/frontend-modern/src/components/shared/FilterBar/SavedViewsMenu.tsx
+++ b/frontend-modern/src/components/shared/FilterBar/SavedViewsMenu.tsx
@@ -1,6 +1,7 @@
import { Component, For, Show, createEffect, createSignal, onCleanup } from 'solid-js';
import BookmarkIcon from 'lucide-solid/icons/bookmark';
import PlusIcon from 'lucide-solid/icons/plus';
+import StarIcon from 'lucide-solid/icons/star';
import XIcon from 'lucide-solid/icons/x';
import { filterActionButtonClass } from '@/components/shared/FilterToolbar';
import { useSavedViews, type SavedView } from './useSavedViews';
@@ -10,7 +11,8 @@ interface SavedViewsMenuProps {
}
export const SavedViewsMenu: Component<SavedViewsMenuProps> = (props) => {
- const { views, saveCurrent, removeView, applyView } = useSavedViews(props.storageKey);
+ const { views, saveCurrent, removeView, applyView, setDefault, clearDefault } =
+ useSavedViews(props.storageKey);
const [open, setOpen] = createSignal(false);
const [savePromptOpen, setSavePromptOpen] = createSignal(false);
const [name, setName] = createSignal('');
@@ -124,6 +126,40 @@ export const SavedViewsMenu: Component<SavedViewsMenuProps> = (props) => {
>
{view.name}
</button>
+ <button
+ type="button"
+ onClick={(event) => {
+ event.stopPropagation();
+ if (view.isDefault === true) {
+ clearDefault();
+ } else {
+ setDefault(view.id);
+ }
+ }}
+ aria-label={
+ view.isDefault === true
+ ? `Unset "${view.name}" as default`
+ : `Set "${view.name}" as default`
+ }
+ title={
+ view.isDefault === true
+ ? 'Default view — applied when you land on this page'
+ : 'Set as default for this page'
+ }
+ class={
+ view.isDefault === true
+ ? 'rounded-full p-0.5 text-amber-500 opacity-100'
+ : 'rounded-full p-0.5 text-muted opacity-0 transition-opacity hover:text-base-content group-hover:opacity-100 focus-visible:opacity-100'
+ }
+ >
+ <StarIcon
+ class={
+ view.isDefault === true
+ ? 'h-3 w-3 fill-current'
+ : 'h-3 w-3'
+ }
+ />
+ </button>
<button
type="button"
onClick={(event) => {
diff --git a/frontend-modern/src/components/shared/FilterBar/useSavedViews.ts b/frontend-modern/src/components/shared/FilterBar/useSavedViews.ts
index 03ca88894b..de7f5ff3ef 100644
--- a/frontend-modern/src/components/shared/FilterBar/useSavedViews.ts
+++ b/frontend-modern/src/components/shared/FilterBar/useSavedViews.ts
@@ -6,8 +6,15 @@ export interface SavedView {
name: string;
query: string;
savedAt: number;
+ version: number;
+ isDefault?: boolean;
}
+// Bump when the on-wire shape of a saved view's `query` changes incompatibly
+// (e.g. a FilterDef renames its URL key or changes encoding). Reads tolerate
+// missing version by treating entries as v1.
+const CURRENT_VERSION = 1;
+
const STORAGE_PREFIX = 'pulse:filterbar:saved-views:';
const storageKeyFor = (key: string): string => `${STORAGE_PREFIX}${key}`;
@@ -20,6 +27,12 @@ const isSavedView = (entry: unknown): entry is SavedView =>
typeof (entry as SavedView).query === 'string' &&
typeof (entry as SavedView).savedAt === 'number';
+const normalize = (entry: SavedView): SavedView => ({
+ ...entry,
+ version: typeof entry.version === 'number' ? entry.version : 1,
+ isDefault: entry.isDefault === true,
+});
+
const readStored = (key: string): SavedView[] => {
if (typeof window === 'undefined') return [];
try {
@@ -27,7 +40,7 @@ const readStored = (key: string): SavedView[] => {
if (!raw) return [];
const parsed = JSON.parse(raw);
if (!Array.isArray(parsed)) return [];
- return parsed.filter(isSavedView);
+ return parsed.filter(isSavedView).map(normalize);
} catch {
return [];
}
@@ -49,11 +62,17 @@ const generateId = (): string => {
return `view-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
};
+export interface ApplyViewOptions {
+ replace?: boolean;
+}
+
export interface UseSavedViewsResult {
views: Accessor<SavedView[]>;
saveCurrent: (name: string) => SavedView | null;
removeView: (id: string) => void;
- applyView: (view: SavedView) => void;
+ applyView: (view: SavedView, options?: ApplyViewOptions) => void;
+ setDefault: (id: string) => void;
+ clearDefault: () => void;
}
export function useSavedViews(key: string): UseSavedViewsResult {
@@ -61,8 +80,25 @@ export function useSavedViews(key: string): UseSavedViewsResult {
const location = useLocation();
const [views, setViews] = createSignal<SavedView[]>([]);
+ const applyView = (view: SavedView, options?: ApplyViewOptions): void => {
+ const path = `${location.pathname}${view.query ? `?${view.query}` : ''}`;
+ navigate(path, { replace: options?.replace ?? false });
+ };
+
onMount(() => {
- setViews(readStored(key));
+ const stored = readStored(key);
+ setViews(stored);
+ // Auto-apply default view on a fresh landing only. If the URL already
+ // carries a query the user (or a deep link) chose it explicitly and we
+ // leave it alone. Replace the history entry so the back button doesn't
+ // bounce against an empty-query state that would just re-fire the
+ // default and trap navigation.
+ if (typeof window !== 'undefined' && window.location.search === '') {
+ const fallback = stored.find((view) => view.isDefault === true);
+ if (fallback) {
+ applyView(fallback, { replace: true });
+ }
+ }
});
const saveCurrent = (name: string): SavedView | null => {
@@ -75,6 +111,7 @@ export function useSavedViews(key: string): UseSavedViewsResult {
name: trimmed,
query,
savedAt: Date.now(),
+ version: CURRENT_VERSION,
};
const next = [...views(), view];
setViews(next);
@@ -88,10 +125,22 @@ export function useSavedViews(key: string): UseSavedViewsResult {
writeStored(key, next);
};
- const applyView = (view: SavedView): void => {
- const path = `${location.pathname}${view.query ? `?${view.query}` : ''}`;
- navigate(path, { replace: false });
+ const setDefault = (id: string): void => {
+ const next = views().map((view) => ({
+ ...view,
+ isDefault: view.id === id,
+ }));
+ setViews(next);
+ writeStored(key, next);
+ };
+
+ const clearDefault = (): void => {
+ const next = views().map((view) =>
+ view.isDefault ? { ...view, isDefault: false } : view,
+ );
+ setViews(next);
+ writeStored(key, next);
};
- return { views, saveCurrent, removeView, applyView };
+ return { views, saveCurrent, removeView, applyView, setDefault, clearDefault };
}