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(datatable): active-sort chip bar (Twenty-style)

Juan Denis7b4cf90b0c3f
diff --git a/frontend/src/components/ds/SortChipBar.jsx b/frontend/src/components/ds/SortChipBar.jsx
new file mode 100644
index 00000000..5d8b2766
--- /dev/null
+++ b/frontend/src/components/ds/SortChipBar.jsx
@@ -0,0 +1,64 @@
+import { ArrowUp, ArrowDown, X } from 'lucide-react';
+import { cn } from '@/lib/utils';
+
+// Active-sort chip bar (Twenty's EditableSortChip pattern). Renders one chip
+// per sort level above the table: click the chip body to flip direction, ✕ to
+// remove the level, "Reset" clears all. Collapses to nothing when no sort is
+// active — the bar never sits empty.
+//
+// const { sorts, setSorts } = useTableSort();
+// <SortChipBar columns={columns} sorts={sorts} onChange={setSorts} />
+export function SortChipBar({ columns = [], sorts = [], onChange, className }) {
+ if (!sorts.length) return null;
+
+ const labelFor = (key) => {
+ const column = columns.find((c) => c.key === key);
+ if (!column) return key;
+ return typeof column.header === 'string' && column.header ? column.header : column.key;
+ };
+
+ const flip = (key) => onChange?.(
+ sorts.map((s) => (s.key === key
+ ? { ...s, direction: s.direction === 'asc' ? 'desc' : 'asc' }
+ : s)),
+ );
+ const remove = (key) => onChange?.(sorts.filter((s) => s.key !== key));
+
+ return (
+ <div className={cn('sk-sortchips', className)} role="list" aria-label="Active sorting">
+ {sorts.map((sort, index) => (
+ <span key={sort.key} className="sk-sortchips__chip" role="listitem">
+ {sorts.length > 1 && (
+ <span className="sk-sortchips__priority">{index + 1}</span>
+ )}
+ <button
+ type="button"
+ className="sk-sortchips__body"
+ onClick={() => flip(sort.key)}
+ title="Click to flip direction"
+ >
+ <span className="sk-sortchips__label">{labelFor(sort.key)}</span>
+ {sort.direction === 'asc' ? <ArrowUp size={12} /> : <ArrowDown size={12} />}
+ </button>
+ <button
+ type="button"
+ className="sk-sortchips__remove"
+ onClick={() => remove(sort.key)}
+ aria-label={`Remove sort on ${labelFor(sort.key)}`}
+ >
+ <X size={12} />
+ </button>
+ </span>
+ ))}
+ <button
+ type="button"
+ className="sk-sortchips__reset"
+ onClick={() => onChange?.([])}
+ >
+ Reset
+ </button>
+ </div>
+ );
+}
+
+export default SortChipBar;
diff --git a/frontend/src/components/ds/index.js b/frontend/src/components/ds/index.js
index ea3b3859..188c705f 100644
--- a/frontend/src/components/ds/index.js
+++ b/frontend/src/components/ds/index.js
@@ -20,6 +20,7 @@ export {
export { PageTopbar } from './PageTopbar';
export { DataTable } from './DataTable';
export { SortMenu } from './SortMenu';
+export { SortChipBar } from './SortChipBar';
export { ColumnsMenu } from './ColumnsMenu';
export { DataTableFooter } from './DataTableFooter';
export { ResourceCard, ResourceList } from './ResourceCard';
diff --git a/frontend/src/components/layouts/ResourceListPage.jsx b/frontend/src/components/layouts/ResourceListPage.jsx
index fab832e3..17f1195a 100644
--- a/frontend/src/components/layouts/ResourceListPage.jsx
+++ b/frontend/src/components/layouts/ResourceListPage.jsx
@@ -1,7 +1,7 @@
import { useMemo, useState } from 'react';
import { Search, Rows3, LayoutGrid, X } from 'lucide-react';
import { cn } from '@/lib/utils';
-import { SegControl, SortMenu, ColumnsMenu, DataTableFooter } from '@/components/ds';
+import { SegControl, SortMenu, SortChipBar, ColumnsMenu, DataTableFooter } from '@/components/ds';
import EmptyState from '../EmptyState';
import DataTable from '@/components/ds/DataTable';
import { useTableSort } from '@/hooks/useTableSort';
@@ -210,6 +210,10 @@ export default function ResourceListPage({
)}
</div>
+ {view === 'list' && (
+ <SortChipBar columns={columns} sorts={sorts} onChange={setSorts} />
+ )}
+
{items.length === 0 ? (
<EmptyState
icon={filteredEmptyIcon || emptyIcon}
diff --git a/frontend/src/pages/Servers.jsx b/frontend/src/pages/Servers.jsx
index bb3c2822..d3a57e9c 100644
--- a/frontend/src/pages/Servers.jsx
+++ b/frontend/src/pages/Servers.jsx
@@ -8,7 +8,7 @@ import Modal from '@/components/Modal';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import {
- ColumnsMenu, DataTable, DataTableFooter, Drawer, Gauge, Pill, SearchField, SegControl, SortMenu,
+ ColumnsMenu, DataTable, DataTableFooter, Drawer, Gauge, Pill, SearchField, SegControl, SortChipBar, SortMenu,
} from '@/components/ds';
import { useTopbarActions } from '@/hooks/useTopbarActions';
import { useTableSort } from '@/hooks/useTableSort';
@@ -259,6 +259,8 @@ const Servers = () => {
/>
</div>
+ <SortChipBar columns={SERVER_COLUMNS} sorts={sorts} onChange={setSorts} />
+
{filteredServers.length === 0 ? (
<EmptyState
icon={ServerLucideIcon}
diff --git a/frontend/src/styles/components/_design-system.scss b/frontend/src/styles/components/_design-system.scss
index 3a92271c..d8f5485f 100644
--- a/frontend/src/styles/components/_design-system.scss
+++ b/frontend/src/styles/components/_design-system.scss
@@ -560,6 +560,88 @@ $sk-tones: ('accent', 'green', 'cyan', 'amber', 'red', 'violet');
}
}
+// ------------------------------------------------------------
+// SortChipBar — active-sort chips above the table (Twenty style). Renders
+// nothing when no sort is active, so the bar never sits empty.
+// ------------------------------------------------------------
+.sk-sortchips {
+ display: flex;
+ align-items: center;
+ gap: 7px;
+ flex-wrap: wrap;
+ padding: 8px 2px 0;
+
+ &__chip {
+ display: inline-flex;
+ align-items: center;
+ gap: 2px;
+ height: 24px;
+ padding-left: 9px;
+ border-radius: 999px;
+ background: var(--accent-bg-soft);
+ border: 1px solid var(--accent-dim);
+ color: var(--accent-bright);
+ font-size: 12px;
+ user-select: none;
+ white-space: nowrap;
+ }
+
+ &__priority {
+ font-family: var(--mono);
+ font-size: 10px;
+ font-weight: 600;
+ opacity: 0.8;
+ margin-right: 2px;
+ }
+
+ &__body {
+ display: inline-flex;
+ align-items: center;
+ gap: 5px;
+ height: 100%;
+ padding: 0 4px 0 0;
+ border: none;
+ background: none;
+ color: inherit;
+ font-size: inherit;
+ font-family: inherit;
+ cursor: pointer;
+ }
+
+ &__label { font-weight: 550; }
+
+ &__remove {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: 18px;
+ height: 18px;
+ margin-right: 3px;
+ border: none;
+ border-radius: 999px;
+ background: transparent;
+ color: inherit;
+ opacity: 0.7;
+ cursor: pointer;
+ transition: 0.12s;
+
+ &:hover { opacity: 1; background: var(--accent-bg); }
+ }
+
+ &__reset {
+ border: none;
+ background: none;
+ padding: 0 4px;
+ color: var(--text-faint);
+ font-size: 12px;
+ font-family: inherit;
+ cursor: pointer;
+ transition: color 0.12s;
+
+ &:hover { color: var(--text); }
+ }
+}
+
// ------------------------------------------------------------
// Floating bulk-actions pill — appears only while rows are selected
// (Frappe ListSelectBanner style), instead of a permanent toolbar row.