mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 00:23:12 +09:00
Fix react errors in factorio version selector
This commit is contained in:
1 parent
01f6397983
commit
264a32431e
2 files changed
+22
-16
No files matched your search
@@ -18,15 +18,16 @@ export default function InputPartialVersion (
|
|||||||
const [versions, setVersions] = useState<readonly lib.PartialVersion[]>(lib.ApiVersions);
|
const [versions, setVersions] = useState<readonly lib.PartialVersion[]>(lib.ApiVersions);
|
||||||
const control = useContext(ControlContext);
|
const control = useContext(ControlContext);
|
||||||
const account = useAccount();
|
const account = useAccount();
|
||||||
|
const hasPermission = account.hasPermission("core.external.get_factorio_versions");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
if (account.hasPermission("core.external.get_factorio_versions")) {
|
if (hasPermission) {
|
||||||
const res = await control.factorioVersions.get(5 * 60 * 1000);
|
const res = await control.factorioVersions.get(5 * 60 * 1000);
|
||||||
setVersions(res.map(v => v.version));
|
setVersions(res.map(v => v.version));
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}, [control]);
|
}, [control, hasPermission]);
|
||||||
|
|
||||||
// Split the versions into groups based on major minor
|
// Split the versions into groups based on major minor
|
||||||
const groups = new Map<lib.PartialVersion, lib.PartialVersion[]>();
|
const groups = new Map<lib.PartialVersion, lib.PartialVersion[]>();
|
||||||
@@ -42,18 +43,20 @@ export default function InputPartialVersion (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Construct the tree to be disabled
|
// Construct the tree to be disabled
|
||||||
const tree = [...groups.entries()].map(([majorMinor, patchVersions]) => (
|
const tree = [...groups.entries()].map(([majorMinor, patchVersions]) => {
|
||||||
{
|
const groupKey = `group-${majorMinor}`;
|
||||||
|
|
||||||
|
return {
|
||||||
title: majorMinor,
|
title: majorMinor,
|
||||||
value: majorMinor,
|
value: groupKey,
|
||||||
key: majorMinor,
|
key: groupKey,
|
||||||
children: patchVersions.map((v) => ({
|
children: patchVersions.map((v) => ({
|
||||||
title: v,
|
title: v,
|
||||||
value: v,
|
value: v,
|
||||||
key: v,
|
key: v,
|
||||||
})),
|
})),
|
||||||
}
|
};
|
||||||
));
|
});
|
||||||
|
|
||||||
return <TreeSelect
|
return <TreeSelect
|
||||||
showSearch
|
showSearch
|
||||||
|
|||||||
@@ -18,15 +18,16 @@ export default function InputTargetVersion (
|
|||||||
const [versions, setVersions] = useState<readonly lib.TargetVersion[]>(lib.ApiVersions);
|
const [versions, setVersions] = useState<readonly lib.TargetVersion[]>(lib.ApiVersions);
|
||||||
const control = useContext(ControlContext);
|
const control = useContext(ControlContext);
|
||||||
const account = useAccount();
|
const account = useAccount();
|
||||||
|
const hasPermission = account.hasPermission("core.external.get_factorio_versions");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
if (account.hasPermission("core.external.get_factorio_versions")) {
|
if (hasPermission) {
|
||||||
const res = await control.factorioVersions.get(5 * 60 * 1000);
|
const res = await control.factorioVersions.get(5 * 60 * 1000);
|
||||||
setVersions(res.map(v => v.version));
|
setVersions(res.map(v => v.version));
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}, [control]);
|
}, [control, hasPermission]);
|
||||||
|
|
||||||
// Split the versions into groups based on major minor
|
// Split the versions into groups based on major minor
|
||||||
const groups = new Map<lib.TargetVersion, lib.TargetVersion[]>();
|
const groups = new Map<lib.TargetVersion, lib.TargetVersion[]>();
|
||||||
@@ -42,18 +43,20 @@ export default function InputTargetVersion (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Construct the tree to be disabled
|
// Construct the tree to be disabled
|
||||||
const tree = [...groups.entries()].map(([majorMinor, patchVersions]) => (
|
const tree = [...groups.entries()].map(([majorMinor, patchVersions]) => {
|
||||||
{
|
const groupKey = `group-${majorMinor}`;
|
||||||
|
|
||||||
|
return {
|
||||||
title: majorMinor,
|
title: majorMinor,
|
||||||
value: majorMinor,
|
value: groupKey,
|
||||||
key: majorMinor,
|
key: groupKey,
|
||||||
children: patchVersions.map((v) => ({
|
children: patchVersions.map((v) => ({
|
||||||
title: v,
|
title: v,
|
||||||
value: v,
|
value: v,
|
||||||
key: v,
|
key: v,
|
||||||
})),
|
})),
|
||||||
}
|
};
|
||||||
));
|
});
|
||||||
|
|
||||||
// Add "latest" option for TargetVersion
|
// Add "latest" option for TargetVersion
|
||||||
tree.unshift({ title: "latest", value: "latest", key: "latest", children: [] });
|
tree.unshift({ title: "latest", value: "latest", key: "latest", children: [] });
|
||||||
|
|||||||
Reference in new issue
Block a user