mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 00:13:12 +09:00
Always persist table state; drop the persistState prop
Every render site of InstanceList and UsersTable already passed persistState, so the prop and its uncontrolled fallback branch were dead config. Remove the prop and the conditionals so these tables always persist their state to the URL. No runtime behaviour change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
245483cb35
commit
82629a57c6
6 files changed
+13
-20
No files matched your search
@@ -169,7 +169,7 @@ export default function HostViewPage() {
|
|||||||
</Descriptions>
|
</Descriptions>
|
||||||
{account.hasPermission("core.instance.list") && <>
|
{account.hasPermission("core.instance.list") && <>
|
||||||
<Title level={5} style={{ marginTop: 16 }}>Instances</Title>
|
<Title level={5} style={{ marginTop: 16 }}>Instances</Title>
|
||||||
<InstanceList instances={hostInstances} size="small" hideAssignedHost persistState />
|
<InstanceList instances={hostInstances} size="small" hideAssignedHost />
|
||||||
</>}
|
</>}
|
||||||
{account.hasPermission("core.log.follow") && <>
|
{account.hasPermission("core.log.follow") && <>
|
||||||
<Flex justify="space-between" align="baseline">
|
<Flex justify="space-between" align="baseline">
|
||||||
|
|||||||
@@ -23,8 +23,6 @@ type InstanceListProps = {
|
|||||||
instances: ReadonlyMap<number, Readonly<lib.InstanceDetails>>;
|
instances: ReadonlyMap<number, Readonly<lib.InstanceDetails>>;
|
||||||
size?: SizeType;
|
size?: SizeType;
|
||||||
hideAssignedHost?: boolean;
|
hideAssignedHost?: boolean;
|
||||||
/** Persist sort/search state in the URL and show a search box (for the standalone Instances page). */
|
|
||||||
persistState?: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function InstanceList(props: InstanceListProps) {
|
export default function InstanceList(props: InstanceListProps) {
|
||||||
@@ -32,7 +30,6 @@ export default function InstanceList(props: InstanceListProps) {
|
|||||||
let navigate = useNavigate();
|
let navigate = useNavigate();
|
||||||
let [hosts] = useHosts();
|
let [hosts] = useHosts();
|
||||||
const [systems] = useSystems();
|
const [systems] = useSystems();
|
||||||
const persist = props.persistState ?? false;
|
|
||||||
const tableState = useTableQueryState<lib.InstanceDetails>({
|
const tableState = useTableQueryState<lib.InstanceDetails>({
|
||||||
namespace: "instance", defaultSortKey: "name", pagination: false,
|
namespace: "instance", defaultSortKey: "name", pagination: false,
|
||||||
});
|
});
|
||||||
@@ -58,7 +55,7 @@ export default function InstanceList(props: InstanceListProps) {
|
|||||||
dataIndex: "name",
|
dataIndex: "name",
|
||||||
defaultSortOrder: "ascend",
|
defaultSortOrder: "ascend",
|
||||||
sorter: (a, b) => strcmp(a["name"], b["name"]),
|
sorter: (a, b) => strcmp(a["name"], b["name"]),
|
||||||
...(persist ? nameSearch : {}),
|
...nameSearch,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Assigned Host",
|
title: "Assigned Host",
|
||||||
@@ -128,15 +125,15 @@ export default function InstanceList(props: InstanceListProps) {
|
|||||||
columns.splice(1, 1);
|
columns.splice(1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const finalColumns = persist ? columns.map(tableState.applyColumn) : columns;
|
const finalColumns = columns.map(tableState.applyColumn);
|
||||||
|
|
||||||
return <Table
|
return <Table
|
||||||
size={props.size || "large"}
|
size={props.size || "large"}
|
||||||
columns={finalColumns}
|
columns={finalColumns}
|
||||||
dataSource={[...props.instances.values()]}
|
dataSource={[...props.instances.values()]}
|
||||||
rowKey={instance => instance["id"]}
|
rowKey={instance => instance["id"]}
|
||||||
pagination={persist ? tableState.pagination : false}
|
pagination={tableState.pagination}
|
||||||
onChange={persist ? tableState.onChange : undefined}
|
onChange={tableState.onChange}
|
||||||
onRow={(record, rowIndex) => ({
|
onRow={(record, rowIndex) => ({
|
||||||
onClick: event => {
|
onClick: event => {
|
||||||
navigate(`/instances/${record.id}/view`);
|
navigate(`/instances/${record.id}/view`);
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ export default function InstancesPage() {
|
|||||||
</Space>}
|
</Space>}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<InstanceList instances={instances} persistState />
|
<InstanceList instances={instances} />
|
||||||
<PluginExtra component="InstancesPage" />
|
<PluginExtra component="InstancesPage" />
|
||||||
</PageLayout>;
|
</PageLayout>;
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@ export default function OnlinePlayersList({ instanceId }: OnlinePlayersListProps
|
|||||||
return (
|
return (
|
||||||
<div style={{ marginTop: 16 }}>
|
<div style={{ marginTop: 16 }}>
|
||||||
<h4>Online Players ({onlineUsers.length})</h4>
|
<h4>Online Players ({onlineUsers.length})</h4>
|
||||||
<UsersTable instanceId={instanceId} onlyOnline size="small" persistState pagination={{
|
<UsersTable instanceId={instanceId} onlyOnline size="small" pagination={{
|
||||||
defaultPageSize: 10,
|
defaultPageSize: 10,
|
||||||
showSizeChanger: true,
|
showSizeChanger: true,
|
||||||
pageSizeOptions: ["10", "20", "50", "100", "200"],
|
pageSizeOptions: ["10", "20", "50", "100", "200"],
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ export default function UsersPage() {
|
|||||||
&& <BulkUserActionButton />}
|
&& <BulkUserActionButton />}
|
||||||
</Space>}
|
</Space>}
|
||||||
/>
|
/>
|
||||||
<UsersTable instanceId={instanceId ?? undefined} persistState/>
|
<UsersTable instanceId={instanceId ?? undefined}/>
|
||||||
<PluginExtra component="UsersPage" />
|
<PluginExtra component="UsersPage" />
|
||||||
</PageLayout>;
|
</PageLayout>;
|
||||||
}
|
}
|
||||||
@@ -26,14 +26,12 @@ export interface UsersTableProps {
|
|||||||
pagination?: false | object;
|
pagination?: false | object;
|
||||||
/** Ant Design size prop */
|
/** Ant Design size prop */
|
||||||
size?: "small" | "middle" | "large";
|
size?: "small" | "middle" | "large";
|
||||||
/** Persist sort/filter/pagination state in the URL (for the standalone Users page). */
|
|
||||||
persistState?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const strcmp = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" }).compare;
|
const strcmp = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" }).compare;
|
||||||
|
|
||||||
export default function UsersTable(
|
export default function UsersTable(
|
||||||
{ instanceId, onlyOnline = false, pagination, size, persistState }: UsersTableProps
|
{ instanceId, onlyOnline = false, pagination, size }: UsersTableProps
|
||||||
) {
|
) {
|
||||||
const [roles, rolesSynced] = useRoles();
|
const [roles, rolesSynced] = useRoles();
|
||||||
const [users, usersSynced] = useUsers();
|
const [users, usersSynced] = useUsers();
|
||||||
@@ -181,16 +179,14 @@ export default function UsersTable(
|
|||||||
let tablePagination: false | object;
|
let tablePagination: false | object;
|
||||||
if (pagination === false) {
|
if (pagination === false) {
|
||||||
tablePagination = false;
|
tablePagination = false;
|
||||||
} else if (persistState) {
|
} 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, ...callerPagination, ...(tableState.pagination || {}) };
|
||||||
} else {
|
|
||||||
tablePagination = { ...displayPagination, ...(callerPagination ?? { defaultPageSize: 50 }) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let tableColumns = persistState ? columns.map(tableState.applyColumn) : columns;
|
let tableColumns = columns.map(tableState.applyColumn);
|
||||||
// Seed the online-only default when nothing for the Last Seen column is in the URL yet.
|
// Seed the online-only default when nothing for the Last Seen column is in the URL yet.
|
||||||
if (persistState && onlyOnline && !("lastSeen" in tableState.filters)) {
|
if (onlyOnline && !("lastSeen" in tableState.filters)) {
|
||||||
tableColumns = tableColumns.map(column => (
|
tableColumns = tableColumns.map(column => (
|
||||||
column.key === "lastSeen" ? { ...column, filteredValue: ["online"] } : column
|
column.key === "lastSeen" ? { ...column, filteredValue: ["online"] } : column
|
||||||
));
|
));
|
||||||
@@ -202,7 +198,7 @@ export default function UsersTable(
|
|||||||
dataSource={data}
|
dataSource={data}
|
||||||
rowKey={(user) => user.name}
|
rowKey={(user) => user.name}
|
||||||
pagination={tablePagination}
|
pagination={tablePagination}
|
||||||
onChange={persistState ? tableState.onChange : undefined}
|
onChange={tableState.onChange}
|
||||||
size={size}
|
size={size}
|
||||||
scroll={{ x: "max-content" }}
|
scroll={{ x: "max-content" }}
|
||||||
loading={!usersSynced || !rolesSynced}
|
loading={!usersSynced || !rolesSynced}
|
||||||
|
|||||||
Reference in new issue
Block a user