mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 23:04:52 +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>
|
||||
{account.hasPermission("core.instance.list") && <>
|
||||
<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") && <>
|
||||
<Flex justify="space-between" align="baseline">
|
||||
|
||||
@@ -23,8 +23,6 @@ type InstanceListProps = {
|
||||
instances: ReadonlyMap<number, Readonly<lib.InstanceDetails>>;
|
||||
size?: SizeType;
|
||||
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) {
|
||||
@@ -32,7 +30,6 @@ export default function InstanceList(props: InstanceListProps) {
|
||||
let navigate = useNavigate();
|
||||
let [hosts] = useHosts();
|
||||
const [systems] = useSystems();
|
||||
const persist = props.persistState ?? false;
|
||||
const tableState = useTableQueryState<lib.InstanceDetails>({
|
||||
namespace: "instance", defaultSortKey: "name", pagination: false,
|
||||
});
|
||||
@@ -58,7 +55,7 @@ export default function InstanceList(props: InstanceListProps) {
|
||||
dataIndex: "name",
|
||||
defaultSortOrder: "ascend",
|
||||
sorter: (a, b) => strcmp(a["name"], b["name"]),
|
||||
...(persist ? nameSearch : {}),
|
||||
...nameSearch,
|
||||
},
|
||||
{
|
||||
title: "Assigned Host",
|
||||
@@ -128,15 +125,15 @@ export default function InstanceList(props: InstanceListProps) {
|
||||
columns.splice(1, 1);
|
||||
}
|
||||
|
||||
const finalColumns = persist ? columns.map(tableState.applyColumn) : columns;
|
||||
const finalColumns = columns.map(tableState.applyColumn);
|
||||
|
||||
return <Table
|
||||
size={props.size || "large"}
|
||||
columns={finalColumns}
|
||||
dataSource={[...props.instances.values()]}
|
||||
rowKey={instance => instance["id"]}
|
||||
pagination={persist ? tableState.pagination : false}
|
||||
onChange={persist ? tableState.onChange : undefined}
|
||||
pagination={tableState.pagination}
|
||||
onChange={tableState.onChange}
|
||||
onRow={(record, rowIndex) => ({
|
||||
onClick: event => {
|
||||
navigate(`/instances/${record.id}/view`);
|
||||
|
||||
@@ -111,7 +111,7 @@ export default function InstancesPage() {
|
||||
</Space>}
|
||||
/>
|
||||
|
||||
<InstanceList instances={instances} persistState />
|
||||
<InstanceList instances={instances} />
|
||||
<PluginExtra component="InstancesPage" />
|
||||
</PageLayout>;
|
||||
}
|
||||
@@ -20,7 +20,7 @@ export default function OnlinePlayersList({ instanceId }: OnlinePlayersListProps
|
||||
return (
|
||||
<div style={{ marginTop: 16 }}>
|
||||
<h4>Online Players ({onlineUsers.length})</h4>
|
||||
<UsersTable instanceId={instanceId} onlyOnline size="small" persistState pagination={{
|
||||
<UsersTable instanceId={instanceId} onlyOnline size="small" pagination={{
|
||||
defaultPageSize: 10,
|
||||
showSizeChanger: true,
|
||||
pageSizeOptions: ["10", "20", "50", "100", "200"],
|
||||
|
||||
@@ -386,7 +386,7 @@ export default function UsersPage() {
|
||||
&& <BulkUserActionButton />}
|
||||
</Space>}
|
||||
/>
|
||||
<UsersTable instanceId={instanceId ?? undefined} persistState/>
|
||||
<UsersTable instanceId={instanceId ?? undefined}/>
|
||||
<PluginExtra component="UsersPage" />
|
||||
</PageLayout>;
|
||||
}
|
||||
@@ -26,14 +26,12 @@ export interface UsersTableProps {
|
||||
pagination?: false | object;
|
||||
/** Ant Design size prop */
|
||||
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;
|
||||
|
||||
export default function UsersTable(
|
||||
{ instanceId, onlyOnline = false, pagination, size, persistState }: UsersTableProps
|
||||
{ instanceId, onlyOnline = false, pagination, size }: UsersTableProps
|
||||
) {
|
||||
const [roles, rolesSynced] = useRoles();
|
||||
const [users, usersSynced] = useUsers();
|
||||
@@ -181,16 +179,14 @@ export default function UsersTable(
|
||||
let tablePagination: false | object;
|
||||
if (pagination === false) {
|
||||
tablePagination = false;
|
||||
} else if (persistState) {
|
||||
} else {
|
||||
// Controlled current/pageSize from the URL win over the caller's display props.
|
||||
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.
|
||||
if (persistState && onlyOnline && !("lastSeen" in tableState.filters)) {
|
||||
if (onlyOnline && !("lastSeen" in tableState.filters)) {
|
||||
tableColumns = tableColumns.map(column => (
|
||||
column.key === "lastSeen" ? { ...column, filteredValue: ["online"] } : column
|
||||
));
|
||||
@@ -202,7 +198,7 @@ export default function UsersTable(
|
||||
dataSource={data}
|
||||
rowKey={(user) => user.name}
|
||||
pagination={tablePagination}
|
||||
onChange={persistState ? tableState.onChange : undefined}
|
||||
onChange={tableState.onChange}
|
||||
size={size}
|
||||
scroll={{ x: "max-content" }}
|
||||
loading={!usersSynced || !rolesSynced}
|
||||
|
||||
Reference in new issue
Block a user