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(list): ResourceListPage on the grid chrome -- Services + Workspaces

Juan Denisb0f46510fd97
diff --git a/frontend/src/components/layouts/ResourceListPage.jsx b/frontend/src/components/layouts/ResourceListPage.jsx
index bf98e6fa..b40a74c8 100644
--- a/frontend/src/components/layouts/ResourceListPage.jsx
+++ b/frontend/src/components/layouts/ResourceListPage.jsx
@@ -1,13 +1,19 @@
import { useCallback, useMemo, useState } from 'react';
import { Search, Rows3, LayoutGrid, X } from 'lucide-react';
import { cn } from '@/lib/utils';
-import { SegControl, SortMenu, SortChipBar, ColumnsMenu, GroupMenu, DataTableFooter, ViewMenu, ListToolbar } from '@/components/ds';
+import { SegControl, DataTableFooter, ListToolbar } from '@/components/ds';
+import {
+ GridViewPicker, GridChips, GridFilterButton, GridToolsMenu, GridFilterDrawer,
+ withInferredTypes,
+} from '@/components/ds/grid';
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';
+const NO_FILTERS = { match: 'all', rules: [] };
+
// Shared chrome for resource list pages (Services, Servers, …): the status
// filter + search toolbar, sort & column menus, the DataTable with a standard
// footer, and the loading / empty / filtered-empty states. Pages become thin:
@@ -49,6 +55,8 @@ export default function ResourceListPage({
// { filter, search, sorts, hiddenKeys, pageSize } — all keys optional.
viewPageKey,
builtinViews = [],
+ // Plural label used by the view picker, footer and export filename.
+ noun = 'rows',
// optional content rendered inside the wrapper, above the toolbar/empty
// state (e.g. a one-time credentials banner)
header,
@@ -149,6 +157,26 @@ export default function ResourceListPage({
}
};
+ // Per-column filter rules + column order, owned here rather than by
+ // DataTable, so they can be captured into a saved view and mirrored in the
+ // chip bar and the drawer. DataTable stays the renderer.
+ const [columnFilters, setColumnFilters] = useState(NO_FILTERS);
+ const [columnOrder, setColumnOrder] = useState(null);
+ const [filterDrawerOpen, setFilterDrawerOpen] = useState(false);
+
+ const putColumnRule = useCallback((key, rule) => {
+ setColumnFilters((prev) => ({
+ ...prev,
+ rules: [...prev.rules.filter((r) => r.field !== key), ...(rule ? [rule] : [])],
+ }));
+ }, []);
+ const removeRule = useCallback(
+ (id) => setColumnFilters((prev) => ({ ...prev, rules: prev.rules.filter((r) => r.id !== id) })),
+ [],
+ );
+ const clearRules = useCallback(() => setColumnFilters((prev) => ({ ...prev, rules: [] })), []);
+ const setMatch = useCallback((match) => setColumnFilters((prev) => ({ ...prev, match })), []);
+
const changeView = (next) => {
setView(next);
if (!viewStorageKey) return;
@@ -164,6 +192,62 @@ export default function ResourceListPage({
[items, pageSize],
);
+ // ---- adapter: present this page's state as a DataGrid cfg/api pair ------
+ // The grid chrome (view picker, chip bar, filter drawer, tools menu) is
+ // written against ONE serialisable cfg. This page predates that and keeps
+ // sorts[]/hiddenKeys/groupBy instead. Rather than fork the chrome — which
+ // is exactly the per-page duplication this layout exists to stop — adapt
+ // the state here, once, and every list page built on this wrapper gets the
+ // same chrome for free.
+ // Types are inferred HERE, once, so the chip bar, the drawer and the table
+ // all reason about the same column list. Inferring separately inside
+ // DataTable would leave the drawer looking up OPS[undefined] for a rule the
+ // header menu had just created.
+ const typedColumns = useMemo(() => withInferredTypes(columns, items), [columns, items]);
+
+ const orderedColumns = useMemo(() => {
+ if (!columnOrder?.length) return typedColumns;
+ const byKey = new Map(typedColumns.map((c) => [c.key, c]));
+ const moved = columnOrder.map((k) => byKey.get(k)).filter(Boolean);
+ return [...moved, ...typedColumns.filter((c) => !columnOrder.includes(c.key))];
+ }, [typedColumns, columnOrder]);
+
+ const gridCfg = useMemo(() => ({
+ cols: orderedColumns.filter((c) => !hiddenKeys.includes(c.key)).map((c) => c.key),
+ sort: sorts[0] ? { key: sorts[0].key, dir: sorts[0].direction } : { key: null, dir: 'asc' },
+ group: groupBy,
+ filters: columnFilters,
+ // DataTable auto-sizes its columns and has no sub-detail line, so the
+ // drawer's density / row-detail panes are switched off below rather
+ // than shown as controls that do nothing.
+ density: 'cozy',
+ sub: [],
+ }), [orderedColumns, hiddenKeys, sorts, groupBy, columnFilters]);
+
+ const gridApi = useMemo(() => ({
+ setRules: (rules) => setColumnFilters((prev) => ({ ...prev, rules })),
+ setMatch,
+ addRule: (cols) => {
+ const first = cols.find((c) => c.type && c.filterable !== false);
+ if (!first) return;
+ setColumnFilters((prev) => ({
+ ...prev,
+ rules: [...prev.rules, {
+ id: `r${prev.rules.length}${Math.random().toString(36).slice(2, 6)}`,
+ field: first.key,
+ op: first.type === 'enum' ? 'any' : first.type === 'bool' ? 'is' : first.type === 'num' ? 'lt' : 'contains',
+ value: first.type === 'enum' ? [] : first.type === 'bool' ? true : '',
+ }],
+ }));
+ },
+ removeRule,
+ setColumnOrder,
+ toggleColumn: (key) => toggleColumn(key),
+ setSub: () => {},
+ setDensity: () => {},
+ resetToView: () => { clearRules(); showAllColumns(); setColumnOrder(null); },
+ }), [setMatch, removeRule, toggleColumn, clearRules, showAllColumns]);
+
// 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
@@ -175,7 +259,12 @@ export default function ResourceListPage({
hiddenKeys,
pageSize,
groupBy,
- }), [activeFilter, searchTerm, sorts, hiddenKeys, pageSize, groupBy]);
+ // `columnFilters`, not `filters`: `filters` is already this component's
+ // prop name for the SegControl options, and other pages capture a
+ // `filters` key of their own with a different shape.
+ columnFilters,
+ columnOrder,
+ }), [activeFilter, searchTerm, sorts, hiddenKeys, pageSize, groupBy, columnFilters, columnOrder]);
const applyView = useCallback((state) => {
if (state.filter !== undefined) onFilterChange?.(state.filter);
@@ -184,6 +273,10 @@ export default function ResourceListPage({
if (Array.isArray(state.hiddenKeys)) setHiddenKeys(state.hiddenKeys);
if (state.pageSize !== undefined) changePageSize(state.pageSize);
if (state.groupBy !== undefined) changeGroupBy(state.groupBy);
+ // A preset that sets no rules must CLEAR the live ones, or switching
+ // views leaves the previous view's filters silently applied.
+ setColumnFilters(state.columnFilters ?? NO_FILTERS);
+ setColumnOrder(state.columnOrder ?? null);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [onFilterChange, onSearchChange, setSorts, setHiddenKeys]);
@@ -227,6 +320,22 @@ export default function ResourceListPage({
/>
) : (
<div className="wp-list">
+ {/* The saved view names what you are looking at, so it is the
+ page's heading rather than another toolbar button. Sort,
+ Group and Columns are gone from the toolbar entirely —
+ they live in each column's own "⋮" now, next to the
+ column they act on. */}
+ {viewPageKey && view === 'list' && (
+ <GridViewPicker
+ views={tableViews}
+ label={noun}
+ total={`${items.length} of ${resolvedTotal} ${noun}`}
+ onCreate={(name, fromCurrent) => {
+ if (!fromCurrent) gridApi.resetToView();
+ tableViews.saveView(name);
+ }}
+ />
+ )}
<ListToolbar
filters={filters && (
<SegControl
@@ -239,16 +348,21 @@ export default function ResourceListPage({
<>
{view === 'list' && (
<>
- {viewPageKey && <ViewMenu views={tableViews} />}
- <GroupMenu columns={columns} groupBy={groupBy} onChange={changeGroupBy} />
- {sortable && (
- <SortMenu columns={columns} sorts={sorts} onChange={setSorts} />
- )}
- <ColumnsMenu
- columns={columns}
- hiddenKeys={hiddenKeys}
- onToggle={toggleColumn}
- onShowAll={showAllColumns}
+ <GridFilterButton
+ count={columnFilters.rules.length}
+ onClick={() => setFilterDrawerOpen(true)}
+ />
+ <GridToolsMenu
+ cfg={gridCfg}
+ columns={orderedColumns}
+ rows={items}
+ selectedRows={selectable && selectedIds
+ ? items.filter((i) => selectedIds.has(i[keyField]))
+ : []}
+ viewName={tableViews.activeView?.name || noun}
+ noun={noun}
+ onReset={gridApi.resetToView}
+ showDensity={false}
/>
</>
)}
@@ -288,7 +402,13 @@ export default function ResourceListPage({
</ListToolbar>
{view === 'list' && (
- <SortChipBar columns={columns} sorts={sorts} onChange={setSorts} />
+ <GridChips
+ cfg={gridCfg}
+ columns={orderedColumns}
+ onRemove={removeRule}
+ onClear={clearRules}
+ onMatchChange={setMatch}
+ />
)}
{items.length === 0 ? (
@@ -312,15 +432,20 @@ export default function ResourceListPage({
) : (
<div className="wp-list__card">
<DataTable
- columns={columns}
+ columns={orderedColumns}
data={pagedItems}
keyField={keyField}
sortable={sortable}
sorts={sorts}
onSortsChange={setSorts}
hiddenKeys={hiddenKeys}
+ onHiddenKeysChange={setHiddenKeys}
groupBy={groupBy}
onGroupByChange={changeGroupBy}
+ filters={columnFilters}
+ onFiltersChange={setColumnFilters}
+ columnOrder={columnOrder}
+ onColumnOrderChange={setColumnOrder}
selectable={selectable}
selectedKeys={selectable && selectedIds ? [...selectedIds] : undefined}
onToggleRow={selectable ? onToggleSelect : undefined}
@@ -332,7 +457,7 @@ export default function ResourceListPage({
<DataTableFooter
shown={pagedItems.length}
total={items.length}
- noun="row"
+ noun={noun.replace(/s$/, '')}
pageSize={pageSize}
onPageSizeChange={changePageSize}
/>
@@ -361,6 +486,18 @@ export default function ResourceListPage({
)}
</div>
)}
+ <GridFilterDrawer
+ open={filterDrawerOpen}
+ onOpenChange={setFilterDrawerOpen}
+ columns={orderedColumns}
+ rows={items}
+ cfg={gridCfg}
+ grid={gridApi}
+ noun={noun}
+ showRowDetail={false}
+ showDensity={false}
+ />
+
{children}
</div>
);
diff --git a/frontend/src/pages/Services.jsx b/frontend/src/pages/Services.jsx
index c7ee9069..ec50e0c3 100644
--- a/frontend/src/pages/Services.jsx
+++ b/frontend/src/pages/Services.jsx
@@ -30,6 +30,62 @@ const STATUS_SORT_ORDER = { running: 0, deploying: 1, building: 2, stopped: 3, f
const UNASSIGN = '__unassign__';
const NO_ENV = '__no_env__';
+// Preset views: the questions people open this page to answer. Each is a
+// snapshot of the same chrome state a personal view saves, so any of them can
+// be tweaked and re-saved under a new name.
+const SERVICE_VIEWS = [
+ { name: 'Running', state: { filter: 'running', search: '', sorts: [], hiddenKeys: [] } },
+ { name: 'Stopped', state: { filter: 'stopped', search: '', sorts: [], hiddenKeys: [] } },
+ {
+ name: 'Recently deployed',
+ state: {
+ filter: 'all', search: '', hiddenKeys: [],
+ sorts: [{ key: 'last_deploy', direction: 'desc' }],
+ },
+ },
+ {
+ // Anything not cleanly live — the triage list during an incident.
+ name: 'Broken or unknown',
+ state: {
+ filter: 'all', search: '', hiddenKeys: ['bandwidth'], groupBy: null,
+ sorts: [{ key: 'status', direction: 'desc' }, { key: 'name', direction: 'asc' }],
+ columnFilters: {
+ match: 'any',
+ rules: [{ id: 'bk1', field: 'status', op: 'any', value: ['failed', 'stopped'] }],
+ },
+ },
+ },
+ {
+ // Live, but nobody has shipped to it in a long time.
+ name: 'Stale live services',
+ state: {
+ filter: 'running', search: '', hiddenKeys: ['source', 'bandwidth'], groupBy: null,
+ sorts: [{ key: 'last_deploy', direction: 'asc' }],
+ columnFilters: { match: 'all', rules: [] },
+ },
+ },
+ {
+ // Deployed by hand or by upload — the ones with no git history to roll back to.
+ name: 'Not git-deployed',
+ state: {
+ filter: 'all', search: '', hiddenKeys: ['bandwidth'], groupBy: null,
+ sorts: [{ key: 'name', direction: 'asc' }],
+ columnFilters: {
+ match: 'all',
+ rules: [{ id: 'sr1', field: 'source', op: 'any', value: ['manual', 'upload'] }],
+ },
+ },
+ },
+ {
+ name: 'By project',
+ state: {
+ filter: 'all', search: '', hiddenKeys: ['source', 'bandwidth'], groupBy: 'project',
+ sorts: [{ key: 'status', direction: 'asc' }, { key: 'name', direction: 'asc' }],
+ columnFilters: { match: 'all', rules: [] },
+ },
+ },
+];
+
const Services = () => {
const navigate = useNavigate();
const toast = useToast();
@@ -254,6 +310,13 @@ const Services = () => {
key: 'status',
header: 'Status',
sortable: true,
+ type: 'enum',
+ // `value` is the FILTER/GROUP value, `sortValue` is the ORDERING key —
+ // they differ here, and the column has to say so. Without an explicit
+ // `value` the filter engine falls back to sortValue and compares
+ // against the severity NUMBER, so a "status is running" rule would
+ // silently match nothing.
+ value: (app) => app.status,
// Same severity order as the page's default ordering, not alphabet.
sortValue: (app) => STATUS_SORT_ORDER[app.status] ?? 5,
groupable: true,
@@ -310,11 +373,8 @@ const Services = () => {
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: [] } },
- ]}
+ noun="services"
+ builtinViews={SERVICE_VIEWS}
totalCount={apps.length}
items={filteredApps}
columns={columns}
diff --git a/frontend/src/pages/Workspaces.jsx b/frontend/src/pages/Workspaces.jsx
index b2197f4b..c85a10b6 100644
--- a/frontend/src/pages/Workspaces.jsx
+++ b/frontend/src/pages/Workspaces.jsx
@@ -15,6 +15,44 @@ import { Textarea } from '@/components/ui/textarea';
// Matches WorkspaceSwitcher: the active workspace id lives in localStorage.
const ACTIVE_KEY = 'active_workspace_id';
+// Preset views. Only three: `servers` and `users` are quota CEILINGS, not
+// usage, so there is no column to express "near capacity" against.
+const WORKSPACE_VIEWS = [
+ { name: 'Active', state: { filter: 'active', search: '', sorts: [], hiddenKeys: [] } },
+ { name: 'Inactive', state: { filter: 'inactive', search: '', sorts: [], hiddenKeys: [] } },
+ {
+ name: 'Most members',
+ state: {
+ filter: 'all', search: '', hiddenKeys: [],
+ sorts: [{ key: 'members', direction: 'desc' }],
+ },
+ },
+ {
+ // Created and then never staffed — candidates to archive.
+ name: 'Empty workspaces',
+ state: {
+ filter: 'all', search: '', hiddenKeys: ['servers', 'users'], groupBy: null,
+ sorts: [{ key: 'name', direction: 'asc' }],
+ columnFilters: {
+ match: 'all',
+ rules: [{ id: 'ew1', field: 'members', op: 'eq', value: 0 }],
+ },
+ },
+ },
+ {
+ // Deactivated but people are still attached — access that outlived the workspace.
+ name: 'Archived but still staffed',
+ state: {
+ filter: 'inactive', search: '', hiddenKeys: ['servers', 'users'], groupBy: null,
+ sorts: [{ key: 'members', direction: 'desc' }],
+ columnFilters: {
+ match: 'all',
+ rules: [{ id: 'as1', field: 'members', op: 'gt', value: 0 }],
+ },
+ },
+ },
+];
+
// "since Jun 2026" card meta from the workspace's real created_at.
const formatSince = (iso) => {
if (!iso) return null;
@@ -163,11 +201,8 @@ const Workspaces = () => {
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: [] } },
- ]}
+ noun="workspaces"
+ builtinViews={WORKSPACE_VIEWS}
totalCount={workspaces.length}
items={shownWorkspaces}
columns={columns}