Persist table sort/filter state in the URL

Tables such as Hosts, Instances, Users, Roles, etc. now write their sort
order, column filters and pagination into the URL query string, so reload,
link-sharing and browser back/forward restore the same view (closes #927).

Every parameter is namespaced with the table name so the URL is
self-describing and two tables can share a page without colliding, e.g.
?user.sort=name&user.name=bob&user.admin=true or ?instance.name=foo.

Adds two reusable hooks, exported from @clusterio/web_ui so plugins can use
them too:
- useTableQueryState: makes an antd Table controlled and round-trips its
  sort/filter/pagination through the URL via useSearchParams. The pure
  serialisation helpers live in util/tableQuery.ts and are unit tested.
- useColumnSearch: a column-header text-search filter (matching the Users
  table style), persisted through the same filter mechanism.

Applied to Hosts, Roles, Plugins, the instance list (standalone and on the
host detail page), Users (main table and the online-players list on the
instance detail page), instance saves, the per-instance user stats, the mod
packs and stored mods tables, and the subspace_storage storage page. The
storage page's resource search moves from a standalone box into the Resource
column header, keeping its regex matching.

The bundled user filter persists as separate readable params (user.name,
user.admin, ...) via a per-column FilterCodec rather than one JSON blob.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 4.8 committed 2026-06-24 23:23:54 +00:00
1 parent 9e727f9a13
commit 49eb594e5b
19 files changed
+639 -78

No files matched your search

+16 -8
View File
@@ -6,6 +6,7 @@ import {
import {
ImportOutlined, PlusOutlined, SearchOutlined, DownloadOutlined,
} from "@ant-design/icons";
import type { ColumnsType } from "antd/es/table";
import * as lib from "@clusterio/lib";
@@ -18,6 +19,7 @@ import PageHeader from "./PageHeader";
import PageLayout from "./PageLayout";
import PluginExtra from "./PluginExtra";
import SectionHeader from "./SectionHeader";
import useTableQueryState from "../util/useTableQueryState";
import ModDetails from "./ModDetails";
import { Dropzone } from "./Dropzone";
import UploadButton from "./UploadButton";
@@ -510,6 +512,12 @@ export default function ModsPage() {
let navigate = useNavigate();
let [mods] = useMods();
let [modPacks] = useModPacks();
const modPackTable = useTableQueryState<lib.ModPack>({
namespace: "modPack", defaultSortKey: "name", pagination: false,
});
const modTable = useTableQueryState<lib.ModInfo>({
namespace: "mod", defaultSortKey: "title", pagination: false,
});
function actions(mod: lib.ModInfo) {
return <Space>
@@ -571,11 +579,10 @@ export default function ModsPage() {
</Space>}
/>
<Table
columns={[
columns={([
{
title: "Name",
dataIndex: "name",
defaultSortOrder: "ascend",
sorter: (a, b) => strcmp(a.name, b.name),
},
{
@@ -588,9 +595,10 @@ export default function ModsPage() {
key: "mods",
render: (_, modPack) => modPack.mods.size,
},
]}
] satisfies ColumnsType<lib.ModPack>).map(modPackTable.applyColumn)}
dataSource={[...modPacks.values()]}
pagination={false}
pagination={modPackTable.pagination}
onChange={modPackTable.onChange}
rowKey={modPack => Number(modPack.id)}
onRow={(modPack, rowIndex) => ({
onClick: event => {
@@ -617,11 +625,10 @@ export default function ModsPage() {
>
<Dropzone />
<Table
columns={[
columns={([
{
title: "Name",
dataIndex: "title",
defaultSortOrder: "ascend",
sorter: (a, b) => (
strcmp(a.name, b.name) || a.integerVersion - b.integerVersion
),
@@ -655,13 +662,14 @@ export default function ModsPage() {
responsive: ["lg"],
render: (_, mod) => actions(mod),
},
]}
] satisfies ColumnsType<lib.ModInfo>).map(modTable.applyColumn)}
expandable={{
expandedRowRender: (mod: lib.ModInfo) => <ModDetails mod={mod} actions={actions} />,
expandedRowClassName: () => "no-expanded-padding",
}}
dataSource={[...mods.values()]}
pagination={false}
pagination={modTable.pagination}
onChange={modTable.onChange}
rowKey={mod => mod.id}
/>
</Upload.Dragger>