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

+13 -4
View File
@@ -3,6 +3,8 @@ import { useNavigate } from "react-router-dom";
import { Button, Flex, Form, InputNumber, Modal, Space, Switch, Table, Tooltip, Typography } from "antd";
import { ExclamationCircleOutlined, CopyOutlined } from "@ant-design/icons";
import type { ColumnsType } from "antd/es/table";
import * as lib from "@clusterio/lib";
import webUiPackage from "../../package.json";
@@ -20,6 +22,8 @@ import {
import { useHosts } from "../model/host";
import { useSystems } from "../model/system";
import notify, { notifyErrorHandler } from "../util/notify";
import useTableQueryState from "../util/useTableQueryState";
import useColumnSearch from "./useColumnSearch";
const strcmp = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" }).compare;
@@ -205,6 +209,10 @@ export default function HostsPage() {
const [showRatios, setShowRatios] = useState(true);
const [showNumbers, setShowNumbers] = useState(false);
const [showCpuModel, setShowCpuModel] = useState(false);
const tableState = useTableQueryState<lib.HostDetails>({
namespace: "host", defaultSortKey: "name", pagination: false,
});
const nameSearch = useColumnSearch<lib.HostDetails>(host => host.name, "Search hosts");
return <PageLayout nav={[{ name: "Hosts" }]}>
<PageHeader
@@ -213,12 +221,12 @@ export default function HostsPage() {
/>
<Table
style={{ overflowX: "auto" }}
columns={[
columns={([
{
title: "Name",
dataIndex: "name",
defaultSortOrder: "ascend",
sorter: (a, b) => strcmp(a.name, b.name),
...nameSearch,
},
{
title: "CPU Model",
@@ -302,10 +310,11 @@ export default function HostsPage() {
</>,
sorter: (a, b) => Number(a.connected) - Number(b.connected),
},
]}
] satisfies ColumnsType<lib.HostDetails>).map(tableState.applyColumn)}
dataSource={[...hosts.values()]}
rowKey={host => host.id}
pagination={false}
pagination={tableState.pagination}
onChange={tableState.onChange}
onRow={(record, rowIndex) => ({
onClick: event => {
navigate(`/hosts/${record.id}/view`);