mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 23:33:13 +09:00
Fix small web interface nits from the RC smoke test (#1215)
Fix the "Permamently" typo in the delete instance confirm. The Search Mod Portal dialog now opens on the default mod pack's Factorio version, or the newest known version when there is no default pack. It used to always start on 2.0. A version the user picks still sticks while the page is open. The mod portal cache key used request.hide_deprecated directly, and the web interface never sends it, so the controller logged "2.0-undefined". A missing value now counts as false, the same default fetchAllModsFromPortal already uses, so "2.1" and "2.1-false" share a cache entry. Closes #1209 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c6bc81b0df
commit
09d79d775f
4 files changed
+65
-20
No files matched your search
@@ -631,7 +631,8 @@ export default class ControlConnection extends BaseConnection {
|
|||||||
* @param request - The request object containing factorioVersion.
|
* @param request - The request object containing factorioVersion.
|
||||||
*/
|
*/
|
||||||
async handleModPortalGetAllRequest(request: lib.ModPortalGetAllRequest) {
|
async handleModPortalGetAllRequest(request: lib.ModPortalGetAllRequest) {
|
||||||
const cacheKey = `${request.factorioVersion}-${request.hide_deprecated}`;
|
const hideDeprecated = request.hide_deprecated ?? false;
|
||||||
|
const cacheKey = `${request.factorioVersion}-${hideDeprecated}`;
|
||||||
const cachedData = this._controller.modPortalCache.get(cacheKey);
|
const cachedData = this._controller.modPortalCache.get(cacheKey);
|
||||||
|
|
||||||
const cacheDuration = this._controller.config.get("controller.mod_portal_cache_duration_minutes") * 60 * 1000;
|
const cacheDuration = this._controller.config.get("controller.mod_portal_cache_duration_minutes") * 60 * 1000;
|
||||||
@@ -644,7 +645,7 @@ export default class ControlConnection extends BaseConnection {
|
|||||||
const mods = await lib.ModStore.fetchAllModsFromPortal(
|
const mods = await lib.ModStore.fetchAllModsFromPortal(
|
||||||
request.factorioVersion,
|
request.factorioVersion,
|
||||||
this._controller.config.get("controller.mod_portal_page_size"),
|
this._controller.config.get("controller.mod_portal_page_size"),
|
||||||
request.hide_deprecated
|
hideDeprecated
|
||||||
);
|
);
|
||||||
this._controller.modPortalCache.set(cacheKey, { timestamp: Date.now(), data: mods });
|
this._controller.modPortalCache.set(cacheKey, { timestamp: Date.now(), data: mods });
|
||||||
// The Response class is defined inline within the Request class
|
// The Response class is defined inline within the Request class
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ function InstanceButtons(props: { instance: lib.InstanceDetails }) {
|
|||||||
function confirmDelete() {
|
function confirmDelete() {
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
autoFocusButton: "cancel",
|
autoFocusButton: "cancel",
|
||||||
content: "Permamently delete instance and server saves?",
|
content: "Permanently delete instance and server saves?",
|
||||||
okText: "Delete",
|
okText: "Delete",
|
||||||
okButtonProps: { danger: true },
|
okButtonProps: { danger: true },
|
||||||
onOk: () => {
|
onOk: () => {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import * as lib from "@clusterio/lib";
|
|||||||
|
|
||||||
import { useAccount } from "../model/account";
|
import { useAccount } from "../model/account";
|
||||||
import { useMods } from "../model/mods";
|
import { useMods } from "../model/mods";
|
||||||
import { useModPacks } from "../model/mod_pack";
|
import { useDefaultModPack, useModPacks } from "../model/mod_pack";
|
||||||
import { notifyErrorHandler } from "../util/notify";
|
import { notifyErrorHandler } from "../util/notify";
|
||||||
import ControlContext from "./ControlContext";
|
import ControlContext from "./ControlContext";
|
||||||
import PageHeader from "./PageHeader";
|
import PageHeader from "./PageHeader";
|
||||||
@@ -143,6 +143,16 @@ function CreateModPackButton() {
|
|||||||
</>;
|
</>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function defaultSearchVersion(modPack?: lib.ModPack): lib.MajorMinorVersion {
|
||||||
|
if (modPack) {
|
||||||
|
const version = lib.normaliseMajorMinorVersion(modPack.factorioVersion);
|
||||||
|
if ((lib.ApiVersions as readonly string[]).includes(version)) {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lib.ApiVersions[lib.ApiVersions.length - 1];
|
||||||
|
}
|
||||||
|
|
||||||
function SearchModsButton() {
|
function SearchModsButton() {
|
||||||
const control = useContext(ControlContext);
|
const control = useContext(ControlContext);
|
||||||
const account = useAccount();
|
const account = useAccount();
|
||||||
@@ -150,7 +160,9 @@ function SearchModsButton() {
|
|||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const nameInputRef = useRef<InputRef>(null);
|
const nameInputRef = useRef<InputRef>(null);
|
||||||
const [searchText, setSearchText] = useState("");
|
const [searchText, setSearchText] = useState("");
|
||||||
const [factorioVersion, setFactorioVersion] = useState<lib.MajorMinorVersion>("2.0");
|
const defaultModPack = useDefaultModPack();
|
||||||
|
const [pickedVersion, setPickedVersion] = useState<lib.MajorMinorVersion>();
|
||||||
|
const factorioVersion = pickedVersion ?? defaultSearchVersion(defaultModPack);
|
||||||
|
|
||||||
// State for all mods fetched from backend
|
// State for all mods fetched from backend
|
||||||
const [allMods, setAllMods] = useState<ModPortalModType[]>([]);
|
const [allMods, setAllMods] = useState<ModPortalModType[]>([]);
|
||||||
@@ -274,22 +286,20 @@ function SearchModsButton() {
|
|||||||
return filtered.length;
|
return filtered.length;
|
||||||
}, [allMods, searchText]);
|
}, [allMods, searchText]);
|
||||||
|
|
||||||
// Update search text and factorio version from form
|
// Update search text from form
|
||||||
const handleSearch = (changedValues: any, allValues: any) => {
|
const handleSearch = (changedValues: any, allValues: any) => {
|
||||||
const nameValue = allValues.name;
|
const nameValue = allValues.name;
|
||||||
const versionValue = allValues.factorioVersion as lib.MajorMinorVersion | undefined;
|
|
||||||
|
|
||||||
// Only trigger state updates if values actually changed
|
|
||||||
if (nameValue !== searchText) {
|
if (nameValue !== searchText) {
|
||||||
setSearchText(nameValue || "");
|
setSearchText(nameValue || "");
|
||||||
|
setPage(1);
|
||||||
}
|
}
|
||||||
if (versionValue && versionValue !== factorioVersion) {
|
};
|
||||||
setFactorioVersion(versionValue);
|
|
||||||
|
const handleVersionChange = (version: lib.MajorMinorVersion) => {
|
||||||
|
if (version !== factorioVersion) {
|
||||||
|
setPickedVersion(version);
|
||||||
setAllMods([]); // Clear mods when version changes, useEffect will fetch new ones
|
setAllMods([]); // Clear mods when version changes, useEffect will fetch new ones
|
||||||
setLoading(true); // Show loading indicator immediately
|
setLoading(true); // Show loading indicator immediately
|
||||||
}
|
|
||||||
// Reset page only if search text or version changed
|
|
||||||
if (nameValue !== searchText || (versionValue && versionValue !== factorioVersion)) {
|
|
||||||
setPage(1);
|
setPage(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -349,16 +359,13 @@ function SearchModsButton() {
|
|||||||
labelCol={{ span: 6 }}
|
labelCol={{ span: 6 }}
|
||||||
wrapperCol={{ span: 18 }}
|
wrapperCol={{ span: 18 }}
|
||||||
onValuesChange={handleSearch}
|
onValuesChange={handleSearch}
|
||||||
initialValues={{ factorioVersion: factorioVersion, name: searchText }}
|
initialValues={{ name: searchText }}
|
||||||
>
|
>
|
||||||
<Form.Item name="name" label="Filter by Name or Title">
|
<Form.Item name="name" label="Filter by Name or Title">
|
||||||
<Input ref={nameInputRef} placeholder="Start typing to filter..." />
|
<Input ref={nameInputRef} placeholder="Start typing to filter..." />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item label="Factorio Version">
|
||||||
name="factorioVersion"
|
<Select value={factorioVersion} onChange={handleVersionChange}>
|
||||||
label="Factorio Version"
|
|
||||||
>
|
|
||||||
<Select>
|
|
||||||
{lib.ApiVersions.map(version => (
|
{lib.ApiVersions.map(version => (
|
||||||
<Select.Option key={version} value={version}>
|
<Select.Option key={version} value={version}>
|
||||||
{version}
|
{version}
|
||||||
|
|||||||
@@ -123,6 +123,43 @@ describe("controller/src/ControlConnection", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe(".handleModPortalGetAllRequest()", function() {
|
||||||
|
let mockController;
|
||||||
|
let _fetch;
|
||||||
|
let urls;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
mockController = {
|
||||||
|
config: new lib.ControllerConfig("controller"),
|
||||||
|
modPortalCache: new Map(),
|
||||||
|
};
|
||||||
|
urls = [];
|
||||||
|
_fetch = global.fetch;
|
||||||
|
global.fetch = async url => {
|
||||||
|
urls.push(new URL(url));
|
||||||
|
return { ok: true, json: async () => ({ results: [], pagination: { page_count: 1 } }) };
|
||||||
|
};
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
global.fetch = _fetch;
|
||||||
|
});
|
||||||
|
|
||||||
|
async function getAll(request) {
|
||||||
|
return await ControlConnection.prototype.handleModPortalGetAllRequest.call(
|
||||||
|
{ _controller: mockController }, request,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
it("treats a missing hide_deprecated as false", async function() {
|
||||||
|
await getAll(new lib.ModPortalGetAllRequest("2.1"));
|
||||||
|
assert.deepEqual([...mockController.modPortalCache.keys()], ["2.1-false"]);
|
||||||
|
assert.equal(urls[0].searchParams.get("hide_deprecated"), "false");
|
||||||
|
|
||||||
|
await getAll(new lib.ModPortalGetAllRequest("2.1", false));
|
||||||
|
assert.equal(urls.length, 1, "explicit false should hit the cache");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe(".handleInstanceCreateRequest()", function() {
|
describe(".handleInstanceCreateRequest()", function() {
|
||||||
let mockController;
|
let mockController;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user