Allow custom versions to be selected as a target

Add a custom version input field which can be used to enter any version number.
This commit is contained in:
Cooldude2606 committed 2026-04-12 23:18:13 +01:00
1 parent fc05b229f1
commit 7e87201c24
2 files changed
+66 -2

No files matched your search

@@ -1,5 +1,5 @@
import React, { useContext, useEffect, useState } from "react";
import { TreeSelect } from "antd";
import { Button, Divider, Input, TreeSelect } from "antd";
import * as lib from "@clusterio/lib";
import { InputComponentProps } from "../BaseWebPlugin";
@@ -16,6 +16,7 @@ export default function InputPartialVersion (
) {
const fieldDefinition = props.fieldDefinition || defaultFieldDefinition;
const [versions, setVersions] = useState<readonly lib.PartialVersion[]>(lib.ApiVersions);
const [customVersion, setCustomVersion] = useState("");
const control = useContext(ControlContext);
const account = useAccount();
@@ -64,5 +65,36 @@ export default function InputPartialVersion (
allowClear={fieldDefinition.optional}
className={props.className}
disabled={props.disabled}
popupRender={(menu) => {
const isValid = lib.isPartialVersion(customVersion);
return (
<>
{menu}
<Divider style={{ margin: "8px 0" }} />
<div style={{ display: "flex", gap: 8, padding: "0 8px 4px" }}>
<Input
style={{ flex: 1 }}
placeholder="Custom X.Y.Z"
value={customVersion}
status={
customVersion && !isValid ? "error" : undefined
}
onChange={(e) => setCustomVersion(e.target.value)}
/>
<Button
type="primary"
disabled={!customVersion || !isValid}
onClick={() => {
props.onChange(customVersion);
setCustomVersion("");
}}
>
Use
</Button>
</div>
</>
);
}}
/>;
}
@@ -1,5 +1,5 @@
import React, { useContext, useEffect, useState } from "react";
import { TreeSelect } from "antd";
import { Button, Divider, Input, TreeSelect } from "antd";
import * as lib from "@clusterio/lib";
import { InputComponentProps } from "../BaseWebPlugin";
@@ -16,6 +16,7 @@ export default function InputTargetVersion (
) {
const fieldDefinition = props.fieldDefinition || defaultFieldDefinition;
const [versions, setVersions] = useState<readonly lib.TargetVersion[]>(lib.ApiVersions);
const [customVersion, setCustomVersion] = useState("");
const control = useContext(ControlContext);
const account = useAccount();
@@ -67,5 +68,36 @@ export default function InputTargetVersion (
allowClear={fieldDefinition.optional}
className={props.className}
disabled={props.disabled}
popupRender={(menu) => {
const isValid = lib.isPartialVersion(customVersion);
return (
<>
{menu}
<Divider style={{ margin: "8px 0" }} />
<div style={{ display: "flex", gap: 8, padding: "0 8px 4px" }}>
<Input
style={{ flex: 1 }}
placeholder="Custom X.Y.Z"
value={customVersion}
status={
customVersion && !isValid ? "error" : undefined
}
onChange={(e) => setCustomVersion(e.target.value)}
/>
<Button
type="primary"
disabled={!customVersion || !isValid}
onClick={() => {
props.onChange(customVersion);
setCustomVersion("");
}}
>
Use
</Button>
</div>
</>
);
}}
/>;
}