mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 08:13:12 +09:00
Let plugins add actions to page dropdowns
Adds control.hooks.pageActions. A plugin returns a function per page (ControllerPage, HostViewPage, InstanceViewPage, UserViewPage) that is called during render and returns menu items. Keys are prefixed with the plugin name. Plugin items go after the built-in ones and before stop and delete. The user page and instance templates get a More dropdown only when a plugin adds actions. Closes #1243 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8692ea3941
commit
86befd1231
10 files changed
+180
-9
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { callPageActions, pageActionsFromHooks } from "../../packages/web_ui/src/util/plugin_actions.ts";
|
||||
|
||||
// BaseWebPlugin.ts uses parameter properties, which Node can't strip
|
||||
class WebHooks extends lib.AsyncHookCollection {
|
||||
pageActions = this.newHook();
|
||||
}
|
||||
|
||||
describe("web_ui/util/plugin_actions", function() {
|
||||
it("should prefix keys with the plugin name and keep plugin order", async function() {
|
||||
const hooks = new WebHooks(lib.logger);
|
||||
hooks.pageActions.attach("alpha", () => ({
|
||||
UserViewPage: ({ user }) => [{ key: "greet", label: `Hello ${user.name}` }],
|
||||
}));
|
||||
hooks.pageActions.attach("beta", () => ({
|
||||
UserViewPage: () => [{ key: "a", label: "A" }, { key: "b", label: "B", danger: true }],
|
||||
HostViewPage: () => [{ key: "c", label: "C" }],
|
||||
}));
|
||||
hooks.pageActions.attach("gamma", () => ({}));
|
||||
|
||||
const pageActions = await pageActionsFromHooks(hooks);
|
||||
assert.deepEqual(Object.keys(pageActions).sort(), ["HostViewPage", "UserViewPage"]);
|
||||
assert.deepEqual(callPageActions(pageActions.UserViewPage, { user: { name: "bob" } }), [
|
||||
{ key: "alpha.greet", label: "Hello bob" },
|
||||
{ key: "beta.a", label: "A" },
|
||||
{ key: "beta.b", label: "B", danger: true },
|
||||
]);
|
||||
assert.deepEqual(callPageActions(pageActions.InstanceViewPage, { instance: {} }), []);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user