Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

feat(views): view picker UI + ResourceListPage integration

Juan Denis1c226b0ad6d0
diff --git a/frontend/src/components/ds/ViewMenu.jsx b/frontend/src/components/ds/ViewMenu.jsx
new file mode 100644
index 00000000..7be880ce
--- /dev/null
+++ b/frontend/src/components/ds/ViewMenu.jsx
@@ -0,0 +1,154 @@
+import { useState } from 'react';
+import { LayoutList, Star, Trash2, Check } from 'lucide-react';
+import { Button } from '@/components/ui/button';
+import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
+import { cn } from '@/lib/utils';
+import { useToast } from '@/contexts/ToastContext';
+
+// Saved-view picker (CRM style: Twenty view switcher / Frappe view dropdown).
+// Lists built-in views plus the user's saved views for the page; clicking a
+// row applies it, the star toggles the per-user default, and the footer saves
+// the table's current state as a new view. The trigger shows the active
+// view's name.
+//
+// const views = useTableViews({ page, builtinViews, capture, apply });
+// <ViewMenu views={views} />
+export function ViewMenu({ views, className }) {
+ const {
+ builtinViews, userViews, activeView,
+ applyView, saveView, updateActiveView, toggleDefault, removeView,
+ } = views;
+ const toast = useToast();
+ const [open, setOpen] = useState(false);
+ const [name, setName] = useState('');
+ const [saving, setSaving] = useState(false);
+
+ const handleSave = async () => {
+ const trimmed = name.trim();
+ if (!trimmed || saving) return;
+ setSaving(true);
+ try {
+ await saveView(trimmed);
+ setName('');
+ toast.success(`View "${trimmed}" saved`);
+ } catch (err) {
+ toast.error(err?.data?.error || err?.message || 'Could not save the view');
+ } finally {
+ setSaving(false);
+ }
+ };
+
+ const handleUpdate = async () => {
+ try {
+ await updateActiveView();
+ toast.success(`View "${activeView.name}" updated`);
+ } catch (err) {
+ toast.error(err?.data?.error || err?.message || 'Could not update the view');
+ }
+ };
+
+ const handleDelete = async (view) => {
+ try {
+ await removeView(view);
+ toast.success(`View "${view.name}" deleted`);
+ } catch (err) {
+ toast.error(err?.data?.error || err?.message || 'Could not delete the view');
+ }
+ };
+
+ const isActive = (view) => activeView && activeView.name === view.name
+ && activeView.builtin === !!view.builtin;
+
+ const row = (view) => (
+ <div
+ key={view.builtin ? `b-${view.name}` : `u-${view.id}`}
+ className={cn('sk-viewmenu__row', isActive(view) && 'is-active')}
+ >
+ <button
+ type="button"
+ className="sk-viewmenu__apply"
+ onClick={() => { applyView(view); setOpen(false); }}
+ >
+ {isActive(view) && <Check size={13} aria-hidden="true" />}
+ <span className="sk-viewmenu__name">{view.name}</span>
+ </button>
+ {!view.builtin && (
+ <>
+ <button
+ type="button"
+ className={cn('sk-viewmenu__star', view.is_default && 'is-on')}
+ onClick={() => toggleDefault(view)}
+ title={view.is_default ? 'Remove as default' : 'Set as default view'}
+ aria-label={view.is_default ? 'Remove as default' : 'Set as default view'}
+ aria-pressed={view.is_default}
+ >
+ <Star size={13} />
+ </button>
+ <button
+ type="button"
+ className="sk-viewmenu__delete"
+ onClick={() => handleDelete(view)}
+ title={`Delete "${view.name}"`}
+ aria-label={`Delete view ${view.name}`}
+ >
+ <Trash2 size={13} />
+ </button>
+ </>
+ )}
+ </div>
+ );
+
+ return (
+ <Popover open={open} onOpenChange={setOpen}>
+ <PopoverTrigger asChild>
+ <Button
+ variant="outline"
+ size="sm"
+ className={cn('sk-filter-btn', activeView && 'sk-filter-btn--active', className)}
+ >
+ <LayoutList aria-hidden="true" />
+ {activeView ? activeView.name : 'Views'}
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent align="end" className="sk-tablemenu sk-viewmenu">
+ {builtinViews.length > 0 && (
+ <>
+ <div className="sk-tablemenu__title">Built in</div>
+ <div className="sk-tablemenu__list">{builtinViews.map(row)}</div>
+ </>
+ )}
+ <div className="sk-tablemenu__title">Saved views</div>
+ {userViews.length === 0 ? (
+ <div className="sk-tablemenu__empty">
+ No saved views yet — tune the table, then save it below.
+ </div>
+ ) : (
+ <div className="sk-tablemenu__list">{userViews.map(row)}</div>
+ )}
+ {activeView && !activeView.builtin && (
+ <div className="sk-viewmenu__update">
+ <Button variant="ghost" size="sm" onClick={handleUpdate}>
+ Update &ldquo;{activeView.name}&rdquo; with current state
+ </Button>
+ </div>
+ )}
+ <div className="sk-viewmenu__save">
+ <input
+ type="text"
+ value={name}
+ onChange={(e) => setName(e.target.value)}
+ onKeyDown={(e) => { if (e.key === 'Enter') handleSave(); }}
+ placeholder="Save current as…"
+ aria-label="New view name"
+ maxLength={120}
+ />
+ <Button size="sm" onClick={handleSave} disabled={!name.trim() || saving}>
+ Save
+ </Button>
+ </div>
+ </PopoverContent>
+ </Popover>
+ );
+}
+
+export default ViewMenu;
diff --git a/frontend/src/components/ds/index.js b/frontend/src/components/ds/index.js
index 188c705f..871ad1fa 100644
--- a/frontend/src/components/ds/index.js
+++ b/frontend/src/components/ds/index.js
@@ -23,5 +23,6 @@ export { SortMenu } from './SortMenu';
export { SortChipBar } from './SortChipBar';
export { ColumnsMenu } from './ColumnsMenu';
export { DataTableFooter } from './DataTableFooter';
+export { ViewMenu } from './ViewMenu';
export { ResourceCard, ResourceList } from './ResourceCard';
export { svcGrad, initials, gaugeColor } from './utils';
diff --git a/frontend/src/components/layouts/ResourceListPage.jsx b/frontend/src/components/layouts/ResourceListPage.jsx
index 17f1195a..f0a7d419 100644
--- a/frontend/src/components/layouts/ResourceListPage.jsx
+++ b/frontend/src/components/layouts/ResourceListPage.jsx
@@ -1,11 +1,12 @@
-import { useMemo, useState } from 'react';
+import { useCallback, useMemo, useState } from 'react';
import { Search, Rows3, LayoutGrid, X } from 'lucide-react';
import { cn } from '@/lib/utils';
-import { SegControl, SortMenu, SortChipBar, ColumnsMenu, DataTableFooter } from '@/components/ds';
+import { SegControl, SortMenu, SortChipBar, ColumnsMenu, DataTableFooter, ViewMenu } from '@/components/ds';
import EmptyState from '../EmptyState';
import DataTable from '@/components/ds/DataTable';
import { useTableSort } from '@/hooks/useTableSort';
import { useColumnVisibility } from '@/hooks/useColumnVisibility';
+import { useTableViews } from '@/hooks/useTableViews';
// Shared chrome for resource list pages (Services, Servers, …): the status
// filter + search toolbar, sort & column menus, the DataTable with a standard
@@ -43,6 +44,11 @@ export default function ResourceListPage({
sortable = true,
// Optional localStorage namespace for sort / column / page-size choices.
storageKey,
+ // Saved views: pass the page's view key (e.g. 'services') plus any built-in
+ // views to grow a Views menu in the toolbar. A view state is
+ // { filter, search, sorts, hiddenKeys, pageSize } — all keys optional.
+ viewPageKey,
+ builtinViews = [],
// optional content rendered inside the wrapper, above the toolbar/empty
// state (e.g. a one-time credentials banner)
header,
@@ -86,7 +92,7 @@ export default function ResourceListPage({
const { sorts, setSorts } = useTableSort({
storageKey: storageKey ? `${storageKey}-sort` : undefined,
});
- const { hiddenKeys, toggleColumn, showAllColumns } = useColumnVisibility({
+ const { hiddenKeys, setHiddenKeys, toggleColumn, showAllColumns } = useColumnVisibility({
storageKey: storageKey ? `${storageKey}-cols` : undefined,
});
const [pageSize, setPageSize] = useState(() => {
@@ -124,6 +130,34 @@ export default function ResourceListPage({
[items, pageSize],
);
+ // Saved views: capture/apply the full table chrome state (status filter,
+ // search, sort levels, hidden columns, page size). The filter and search
+ // values themselves are owned by the page — apply() routes through its
+ // setters so a view can drive them.
+ const captureView = useCallback(() => ({
+ filter: activeFilter,
+ search: searchTerm,
+ sorts,
+ hiddenKeys,
+ pageSize,
+ }), [activeFilter, searchTerm, sorts, hiddenKeys, pageSize]);
+
+ const applyView = useCallback((state) => {
+ if (state.filter !== undefined) onFilterChange?.(state.filter);
+ if (state.search !== undefined) onSearchChange?.(state.search);
+ if (Array.isArray(state.sorts)) setSorts(state.sorts);
+ if (Array.isArray(state.hiddenKeys)) setHiddenKeys(state.hiddenKeys);
+ if (state.pageSize !== undefined) changePageSize(state.pageSize);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [onFilterChange, onSearchChange, setSorts, setHiddenKeys]);
+
+ const tableViews = useTableViews({
+ page: viewPageKey,
+ builtinViews,
+ capture: captureView,
+ apply: applyView,
+ });
+
if (loading) {
// Same wrapper as the loaded state below. A skeleton that renders
// outside the page's padded container occupies a different box than the
@@ -180,6 +214,7 @@ export default function ResourceListPage({
{toolbarExtra}
{view === 'list' && (
<div className="wp-list__tabletools">
+ {viewPageKey && <ViewMenu views={tableViews} />}
{sortable && (
<SortMenu columns={columns} sorts={sorts} onChange={setSorts} />
)}
diff --git a/frontend/src/hooks/useTableViews.js b/frontend/src/hooks/useTableViews.js
new file mode 100644
index 00000000..7cb0c66e
--- /dev/null
+++ b/frontend/src/hooks/useTableViews.js
@@ -0,0 +1,115 @@
+import { useCallback, useEffect, useRef, useState } from 'react';
+import api from '@/services/api';
+
+// Saved table views (CRM-style) for one list page. Combines the page's
+// BUILT-IN views (shipped in code, e.g. "Expiring soon") with the current
+// user's saved views from /api/v1/views, and applies a view by handing its
+// state to the page's `apply` adapter.
+//
+// const views = useTableViews({
+// page: 'domains',
+// builtinViews: [{ name: 'Expiring soon', state: { sorts: [{ key: 'expires', direction: 'asc' }] } }],
+// capture: () => ({ status, search, sorts, hiddenKeys }), // read current table state
+// apply: (state) => { …setters… }, // push a view's state back
+// });
+// <ViewMenu {...views.menuProps} />
+//
+// On first load the user's DEFAULT view (if any) is applied automatically.
+export function useTableViews({ page, builtinViews = [], capture, apply }) {
+ const [userViews, setUserViews] = useState([]);
+ const [activeKey, setActiveKey] = useState(null);
+ const [loading, setLoading] = useState(true);
+ const appliedInitial = useRef(false);
+
+ const keyOf = (view) => (view.builtin ? `builtin:${view.name}` : `user:${view.id}`);
+ const allViews = [
+ ...builtinViews.map((v) => ({ ...v, builtin: true })),
+ ...userViews,
+ ];
+ const activeView = allViews.find((v) => keyOf(v) === activeKey) || null;
+
+ useEffect(() => {
+ if (!page) { setLoading(false); return undefined; }
+ let cancelled = false;
+ setLoading(true);
+ api.getViews(page)
+ .then((resp) => {
+ if (cancelled) return;
+ const views = resp?.views || [];
+ setUserViews(views);
+ // Auto-apply the user's default view once per mount.
+ if (!appliedInitial.current) {
+ appliedInitial.current = true;
+ const defaultView = views.find((v) => v.is_default);
+ if (defaultView) {
+ apply(defaultView.state || {});
+ setActiveKey(keyOf(defaultView));
+ }
+ }
+ })
+ .catch(() => { /* views are an enhancement — the page works without them */ })
+ .finally(() => { if (!cancelled) setLoading(false); });
+ return () => { cancelled = true; };
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [page]);
+
+ const applyView = useCallback((view) => {
+ apply(view.state || {});
+ setActiveKey(keyOf(view));
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [apply]);
+
+ const saveView = useCallback(async (name, { setDefault = false } = {}) => {
+ const created = await api.createView({
+ page,
+ name,
+ state: capture(),
+ is_default: setDefault,
+ });
+ setUserViews((prev) => [
+ ...(setDefault ? prev.map((v) => ({ ...v, is_default: false })) : prev),
+ created,
+ ]);
+ setActiveKey(keyOf(created));
+ return created;
+ }, [page, capture]);
+
+ // Update the active saved view's state from the current table state.
+ const updateActiveView = useCallback(async () => {
+ if (!activeView || activeView.builtin) return null;
+ const updated = await api.updateView(activeView.id, { state: capture() });
+ setUserViews((prev) => prev.map((v) => (v.id === updated.id ? updated : v)));
+ return updated;
+ }, [activeView, capture]);
+
+ const toggleDefault = useCallback(async (view) => {
+ if (view.builtin) return;
+ const next = !view.is_default;
+ const updated = await api.updateView(view.id, { is_default: next });
+ setUserViews((prev) => prev.map((v) => ({
+ ...v,
+ is_default: v.id === updated.id ? updated.is_default : (next ? false : v.is_default),
+ })));
+ }, []);
+
+ const removeView = useCallback(async (view) => {
+ if (view.builtin) return;
+ await api.deleteView(view.id);
+ setUserViews((prev) => prev.filter((v) => v.id !== view.id));
+ if (activeKey === keyOf(view)) setActiveKey(null);
+ }, [activeKey]);
+
+ return {
+ builtinViews: allViews.filter((v) => v.builtin),
+ userViews,
+ activeView,
+ loading,
+ applyView,
+ saveView,
+ updateActiveView,
+ toggleDefault,
+ removeView,
+ };
+}
+
+export default useTableViews;
diff --git a/frontend/src/pages/Services.jsx b/frontend/src/pages/Services.jsx
index 9439ae53..856cb41a 100644
--- a/frontend/src/pages/Services.jsx
+++ b/frontend/src/pages/Services.jsx
@@ -338,6 +338,12 @@ const Services = () => {
loading={loading}
loadingTitle="Loading services..."
storageKey="serverkit-list-services"
+ viewPageKey="services"
+ builtinViews={[
+ { name: 'Running', state: { filter: 'running', search: '', sorts: [], hiddenKeys: [] } },
+ { name: 'Stopped', state: { filter: 'stopped', search: '', sorts: [], hiddenKeys: [] } },
+ { name: 'Recently deployed', state: { filter: 'all', search: '', sorts: [{ key: 'last_deploy', direction: 'desc' }], hiddenKeys: [] } },
+ ]}
totalCount={apps.length}
items={filteredApps}
columns={columns}
diff --git a/frontend/src/pages/Workspaces.jsx b/frontend/src/pages/Workspaces.jsx
index 7ac65793..562d79aa 100644
--- a/frontend/src/pages/Workspaces.jsx
+++ b/frontend/src/pages/Workspaces.jsx
@@ -173,6 +173,12 @@ const Workspaces = () => {
loading={loading}
loadingTitle="Loading workspaces"
storageKey="serverkit-list-workspaces"
+ viewPageKey="workspaces"
+ builtinViews={[
+ { name: 'Active', state: { filter: 'active', search: '', sorts: [], hiddenKeys: [] } },
+ { name: 'Inactive', state: { filter: 'inactive', search: '', sorts: [], hiddenKeys: [] } },
+ { name: 'Most members', state: { filter: 'all', search: '', sorts: [{ key: 'members', direction: 'desc' }], hiddenKeys: [] } },
+ ]}
totalCount={workspaces.length}
items={shownWorkspaces}
columns={columns}
diff --git a/frontend/src/services/api/index.js b/frontend/src/services/api/index.js
index e36797dd..747ea550 100644
--- a/frontend/src/services/api/index.js
+++ b/frontend/src/services/api/index.js
@@ -47,6 +47,7 @@ import * as testSandboxMethods from './testSandbox.js';
import * as themeMethods from './themes.js';
import * as dashboardMethods from './dashboards.js';
import * as monitorMethods from './monitors.js';
+import * as viewMethods from './views.js';
class ApiService extends ApiClient {
constructor() {
@@ -101,6 +102,7 @@ class ApiService extends ApiClient {
themeMethods,
dashboardMethods,
monitorMethods,
+ viewMethods,
];
for (const mod of modules) {
for (const [key, fn] of Object.entries(mod)) {
diff --git a/frontend/src/services/api/views.js b/frontend/src/services/api/views.js
new file mode 100644
index 00000000..531f67df
--- /dev/null
+++ b/frontend/src/services/api/views.js
@@ -0,0 +1,21 @@
+// Saved table views API — per-user named table states (filter/search/sort/
+// columns/page-size) for list pages, with one default per page.
+
+// List the current user's views for a page ('services', 'domains', …).
+export async function getViews(page) {
+ return this.request(`/views?page=${encodeURIComponent(page)}`);
+}
+
+// Save a new view: { page, name, state, is_default? }.
+export async function createView(view) {
+ return this.request('/views', { method: 'POST', body: JSON.stringify(view) });
+}
+
+// Rename / restate / (un)default a view: { name?, state?, is_default? }.
+export async function updateView(id, patch) {
+ return this.request(`/views/${id}`, { method: 'PUT', body: JSON.stringify(patch) });
+}
+
+export async function deleteView(id) {
+ return this.request(`/views/${id}`, { method: 'DELETE' });
+}
diff --git a/frontend/src/styles/components/_design-system.scss b/frontend/src/styles/components/_design-system.scss
index d8f5485f..3807b986 100644
--- a/frontend/src/styles/components/_design-system.scss
+++ b/frontend/src/styles/components/_design-system.scss
@@ -642,6 +642,107 @@ $sk-tones: ('accent', 'green', 'cyan', 'amber', 'red', 'violet');
}
}
+// ------------------------------------------------------------
+// ViewMenu — saved-view picker. Reuses the .sk-tablemenu popover chrome and
+// adds view rows (apply / default-star / delete) plus the save-current form.
+// ------------------------------------------------------------
+.sk-viewmenu {
+ &__row {
+ display: flex;
+ align-items: center;
+ gap: 2px;
+ border-radius: 7px;
+ padding-right: 4px;
+ transition: background 0.12s;
+
+ &:hover { background: var(--surface-2); }
+ &.is-active { background: var(--accent-bg-soft); }
+ }
+
+ &__apply {
+ flex: 1;
+ min-width: 0;
+ display: flex;
+ align-items: center;
+ gap: 7px;
+ padding: 6px 8px;
+ border: none;
+ background: none;
+ color: var(--text-dim);
+ font-size: 12.5px;
+ font-family: inherit;
+ text-align: left;
+ cursor: pointer;
+
+ .is-active & { color: var(--accent-bright); font-weight: 550; }
+ svg { flex-shrink: 0; }
+ }
+
+ &__name {
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ }
+
+ &__star,
+ &__delete {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: 24px;
+ height: 24px;
+ border: none;
+ border-radius: 6px;
+ background: transparent;
+ color: var(--text-faint);
+ cursor: pointer;
+ opacity: 0;
+ transition: 0.12s;
+
+ .sk-viewmenu__row:hover & { opacity: 1; }
+ &:hover { background: var(--surface); color: var(--text); }
+ }
+
+ // The default star stays visible even when the row isn't hovered.
+ &__star.is-on {
+ opacity: 1;
+ color: var(--amber);
+ fill: var(--amber);
+ }
+
+ &__update {
+ padding: 6px 2px 2px;
+ border-top: 1px solid var(--border-soft);
+ margin-top: 4px;
+ }
+
+ &__save {
+ display: flex;
+ gap: 8px;
+ padding-top: 8px;
+ margin-top: 4px;
+ border-top: 1px solid var(--border-soft);
+
+ input {
+ flex: 1;
+ min-width: 0;
+ height: 30px;
+ padding: 0 10px;
+ background: var(--surface-2);
+ border: 1px solid var(--border-soft);
+ border-radius: 8px;
+ color: var(--text);
+ font-size: 12.5px;
+ font-family: inherit;
+ outline: none;
+ transition: border-color 0.14s;
+
+ &::placeholder { color: var(--text-faint); }
+ &:focus { border-color: var(--accent-dim); }
+ }
+ }
+}
+
// ------------------------------------------------------------
// Floating bulk-actions pill — appears only while rows are selected
// (Frappe ListSelectBanner style), instead of a permanent toolbar row.