mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 00:13:12 +09:00
Address review: tidy pagination handling and comments
Let useTableQueryState accept a full TablePaginationConfig (only defaultPageSize is read) so UsersTable passes its pagination prop straight through instead of extracting and casting it. Drop the redundant pagination: false from the tables that just want it disabled (that is already the default). Clarify the comment on the Last Seen online-only default to mention the onlyOnline prop, and explain why onChange only uses the first sorter. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
8cacdc5112
commit
1e7b8f08cf
9 files changed
+19
-17
No files matched your search
@@ -208,7 +208,7 @@ export default function HostsPage() {
|
|||||||
const [showNumbers, setShowNumbers] = useState(false);
|
const [showNumbers, setShowNumbers] = useState(false);
|
||||||
const [showCpuModel, setShowCpuModel] = useState(false);
|
const [showCpuModel, setShowCpuModel] = useState(false);
|
||||||
const tableState = useTableQueryState<lib.HostDetails>({
|
const tableState = useTableQueryState<lib.HostDetails>({
|
||||||
namespace: "host", defaultSortKey: "name", pagination: false,
|
namespace: "host", defaultSortKey: "name",
|
||||||
});
|
});
|
||||||
const nameSearch = useColumnSearch<lib.HostDetails>(host => host.name, "Search hosts");
|
const nameSearch = useColumnSearch<lib.HostDetails>(host => host.name, "Search hosts");
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export default function InstanceList(props: InstanceListProps) {
|
|||||||
let [hosts] = useHosts();
|
let [hosts] = useHosts();
|
||||||
const [systems] = useSystems();
|
const [systems] = useSystems();
|
||||||
const tableState = useTableQueryState<lib.InstanceDetails>({
|
const tableState = useTableQueryState<lib.InstanceDetails>({
|
||||||
namespace: "instance", defaultSortKey: "name", pagination: false,
|
namespace: "instance", defaultSortKey: "name",
|
||||||
});
|
});
|
||||||
const nameSearch = useColumnSearch<lib.InstanceDetails>(instance => instance.name, "Search instances");
|
const nameSearch = useColumnSearch<lib.InstanceDetails>(instance => instance.name, "Search instances");
|
||||||
|
|
||||||
|
|||||||
@@ -511,10 +511,10 @@ export default function ModsPage() {
|
|||||||
let [mods] = useMods();
|
let [mods] = useMods();
|
||||||
let [modPacks] = useModPacks();
|
let [modPacks] = useModPacks();
|
||||||
const modPackTable = useTableQueryState<lib.ModPack>({
|
const modPackTable = useTableQueryState<lib.ModPack>({
|
||||||
namespace: "modPack", defaultSortKey: "name", pagination: false,
|
namespace: "modPack", defaultSortKey: "name",
|
||||||
});
|
});
|
||||||
const modTable = useTableQueryState<lib.ModInfo>({
|
const modTable = useTableQueryState<lib.ModInfo>({
|
||||||
namespace: "mod", defaultSortKey: "title", pagination: false,
|
namespace: "mod", defaultSortKey: "title",
|
||||||
});
|
});
|
||||||
|
|
||||||
function actions(mod: lib.ModInfo) {
|
function actions(mod: lib.ModInfo) {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export default function PluginsPage() {
|
|||||||
let navigate = useNavigate();
|
let navigate = useNavigate();
|
||||||
let [pluginList, setPluginList] = useState<PluginWebApi[]>([]);
|
let [pluginList, setPluginList] = useState<PluginWebApi[]>([]);
|
||||||
const tableState = useTableQueryState<PluginRow>({
|
const tableState = useTableQueryState<PluginRow>({
|
||||||
namespace: "plugin", defaultSortKey: "name", pagination: false,
|
namespace: "plugin", defaultSortKey: "name",
|
||||||
});
|
});
|
||||||
const nameSearch = useColumnSearch<PluginRow>(
|
const nameSearch = useColumnSearch<PluginRow>(
|
||||||
plugin => (plugin.info ? plugin.info.title : plugin.meta.name), "Search plugins"
|
plugin => (plugin.info ? plugin.info.title : plugin.meta.name), "Search plugins"
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ export default function RolesPage() {
|
|||||||
let account = useAccount();
|
let account = useAccount();
|
||||||
let navigate = useNavigate();
|
let navigate = useNavigate();
|
||||||
const [roles] = useRoles();
|
const [roles] = useRoles();
|
||||||
const tableState = useTableQueryState<lib.Role>({ namespace: "role", pagination: false });
|
const tableState = useTableQueryState<lib.Role>({ namespace: "role" });
|
||||||
const nameSearch = useColumnSearch<lib.Role>(role => role.name, "Search roles");
|
const nameSearch = useColumnSearch<lib.Role>(role => role.name, "Search roles");
|
||||||
|
|
||||||
return <PageLayout nav={[{ name: "Roles" }]}>
|
return <PageLayout nav={[{ name: "Roles" }]}>
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ export default function SavesList(props: { instance: lib.InstanceDetails }) {
|
|||||||
let [starting, setStarting] = useState(false);
|
let [starting, setStarting] = useState(false);
|
||||||
let [uploadingFiles, setUploadingFiles] = useState<File[]>([]);
|
let [uploadingFiles, setUploadingFiles] = useState<File[]>([]);
|
||||||
const tableState = useTableQueryState<lib.SaveDetails>({
|
const tableState = useTableQueryState<lib.SaveDetails>({
|
||||||
namespace: "save", defaultSortKey: "mtimeMs", defaultSortOrder: "descend", pagination: false,
|
namespace: "save", defaultSortKey: "mtimeMs", defaultSortOrder: "descend",
|
||||||
});
|
});
|
||||||
|
|
||||||
let hostOffline = ["unassigned", "unknown"].includes(props.instance.status!);
|
let hostOffline = ["unassigned", "unknown"].includes(props.instance.status!);
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ export default function UserViewPage() {
|
|||||||
let [roles] = useRoles();
|
let [roles] = useRoles();
|
||||||
let [form] = Form.useForm();
|
let [form] = Form.useForm();
|
||||||
const statsTable = useTableQueryState<[number, lib.PlayerStats]>({
|
const statsTable = useTableQueryState<[number, lib.PlayerStats]>({
|
||||||
namespace: "stats", defaultSortKey: "instance", pagination: false,
|
namespace: "stats", defaultSortKey: "instance",
|
||||||
});
|
});
|
||||||
let [rolesDirty, setRolesDirty] = useState<boolean>(false);
|
let [rolesDirty, setRolesDirty] = useState<boolean>(false);
|
||||||
let [banReasonDirty, setBanReasonDirty] = useState<boolean>(false);
|
let [banReasonDirty, setBanReasonDirty] = useState<boolean>(false);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Table, Tag } from "antd";
|
import { Table, Tag, type TablePaginationConfig } from "antd";
|
||||||
import { SearchOutlined } from "@ant-design/icons";
|
import { SearchOutlined } from "@ant-design/icons";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ export interface UsersTableProps {
|
|||||||
/** Show only players that are currently online, works with instanceId to show online of a particular instance */
|
/** Show only players that are currently online, works with instanceId to show online of a particular instance */
|
||||||
onlyOnline?: boolean;
|
onlyOnline?: boolean;
|
||||||
/** Ant Design pagination prop. Pass `false` to disable pagination. */
|
/** Ant Design pagination prop. Pass `false` to disable pagination. */
|
||||||
pagination?: false | object;
|
pagination?: false | TablePaginationConfig;
|
||||||
/** Ant Design size prop */
|
/** Ant Design size prop */
|
||||||
size?: "small" | "middle" | "large";
|
size?: "small" | "middle" | "large";
|
||||||
}
|
}
|
||||||
@@ -36,12 +36,11 @@ export default function UsersTable(
|
|||||||
const [roles, rolesSynced] = useRoles();
|
const [roles, rolesSynced] = useRoles();
|
||||||
const [users, usersSynced] = useUsers();
|
const [users, usersSynced] = useUsers();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const callerPagination = pagination && typeof pagination === "object" ? pagination : undefined;
|
|
||||||
const defaultPageSize = (callerPagination as { defaultPageSize?: number })?.defaultPageSize ?? 50;
|
|
||||||
const tableState = useTableQueryState<lib.UserDetails>({
|
const tableState = useTableQueryState<lib.UserDetails>({
|
||||||
namespace: "user",
|
namespace: "user",
|
||||||
defaultSortKey: "name",
|
defaultSortKey: "name",
|
||||||
pagination: pagination === false ? false : { defaultPageSize },
|
// Default to 50 per page when the caller does not specify a pagination config.
|
||||||
|
pagination: pagination === false ? false : (pagination ?? { defaultPageSize: 50 }),
|
||||||
filterCodecs: { name: userFilterCodec },
|
filterCodecs: { name: userFilterCodec },
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -168,7 +167,8 @@ export default function UsersTable(
|
|||||||
key: "lastSeen",
|
key: "lastSeen",
|
||||||
filterMultiple: false,
|
filterMultiple: false,
|
||||||
filters: durationFilters,
|
filters: durationFilters,
|
||||||
// Default to online-only when nothing for this column is in the URL yet.
|
// With the onlyOnline prop set, seed this column's filter to "online" until the
|
||||||
|
// URL provides one, so the table starts out showing only online players.
|
||||||
filteredValue: tableState.filteredValue("lastSeen") ?? (onlyOnline ? ["online"] : null),
|
filteredValue: tableState.filteredValue("lastSeen") ?? (onlyOnline ? ["online"] : null),
|
||||||
onFilter: (value: any, record: lib.UserDetails) => onFilterDuration(value, record, calculateLastSeen),
|
onFilter: (value: any, record: lib.UserDetails) => onFilterDuration(value, record, calculateLastSeen),
|
||||||
sorter: (a: lib.UserDetails, b: lib.UserDetails) => sortLastSeen(a, b, instanceId, instanceId),
|
sorter: (a: lib.UserDetails, b: lib.UserDetails) => sortLastSeen(a, b, instanceId, instanceId),
|
||||||
@@ -187,7 +187,7 @@ export default function UsersTable(
|
|||||||
tablePagination = false;
|
tablePagination = false;
|
||||||
} else {
|
} else {
|
||||||
// Controlled current/pageSize from the URL win over the caller's display props.
|
// Controlled current/pageSize from the URL win over the caller's display props.
|
||||||
tablePagination = { ...displayPagination, ...callerPagination, ...(tableState.pagination || {}) };
|
tablePagination = { ...displayPagination, ...pagination, ...(tableState.pagination || {}) };
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ export interface TableQueryStateOptions {
|
|||||||
defaultSortKey?: string;
|
defaultSortKey?: string;
|
||||||
/** Direction of the default sort. Default "ascend". */
|
/** Direction of the default sort. Default "ascend". */
|
||||||
defaultSortOrder?: SortOrder;
|
defaultSortOrder?: SortOrder;
|
||||||
/** Pass an object to persist pagination; omit/false for `pagination={false}` tables. */
|
/** Pagination config to persist pagination; only `defaultPageSize` is read (omit for `pagination={false}`). */
|
||||||
pagination?: false | { defaultPageSize?: number };
|
pagination?: false | TablePaginationConfig;
|
||||||
/** Per-column-key codecs to persist a bundled filter value as separate readable params. */
|
/** Per-column-key codecs to persist a bundled filter value as separate readable params. */
|
||||||
filterCodecs?: Record<string, FilterCodec>;
|
filterCodecs?: Record<string, FilterCodec>;
|
||||||
}
|
}
|
||||||
@@ -59,6 +59,8 @@ export default function useTableQueryState<T>(options: TableQueryStateOptions):
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
onChange(pagination, tableFilters, sorter) {
|
onChange(pagination, tableFilters, sorter) {
|
||||||
|
// Only single-column sort is persisted; antd passes an array when several
|
||||||
|
// columns are sorted, so take the first (primary) sorter.
|
||||||
const single = Array.isArray(sorter) ? sorter[0] : sorter;
|
const single = Array.isArray(sorter) ? sorter[0] : sorter;
|
||||||
const order = single && single.order ? single.order : undefined;
|
const order = single && single.order ? single.order : undefined;
|
||||||
const columnKey = order ? String(single.columnKey ?? single.field ?? "") : undefined;
|
const columnKey = order ? String(single.columnKey ?? single.field ?? "") : undefined;
|
||||||
|
|||||||
Reference in new issue
Block a user