Move exp_reports to ES modules and declare its permissions

Same changes the other packages got in #475 and #476. The permissions move
from definePermission calls into the plugin declaration, with the
Permissions augmentation in messages.ts so the web build sees it.
"type": "module", .js entrypoints and imports, webpack.config.cjs, and the
tap tests use import with --type-strip-only.

The web plugin now uses a default export function instead of the
deprecated BaseWebPlugin class, like exp_roles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-09-26 23:22:18 +00:00
1 parent 9ddb7b362b
commit 12ac7052a1
11 files changed
+91 -83

No files matched your search

+3 -4
View File
@@ -6,8 +6,8 @@ import {
useColumnSearch, useTableQueryState,
} from "@clusterio/web_ui";
import { ReportCreateRequest, ReportDeleteRequest, ReportRecord } from "../../messages";
import type { WebPlugin } from "..";
import { ReportCreateRequest, ReportDeleteRequest, ReportRecord } from "../../messages.js";
import { useReports } from "..";
const strcmp = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" }).compare;
@@ -50,8 +50,7 @@ function CreateReportButton() {
function ReportsTable() {
const control = useContext(ControlContext);
const account = useAccount();
const plugin = control.plugins.get("exp_reports") as WebPlugin;
const [reports, synced] = plugin.useReports();
const [reports, synced] = useReports();
const tableState = useTableQueryState<ReportRecord>({
namespace: "report",
+18 -18
View File
@@ -1,27 +1,27 @@
import React, { useCallback, useSyncExternalStore } from "react";
import { BaseWebPlugin } from "@clusterio/web_ui";
import { WebPluginContext } from "@clusterio/web_ui";
import * as lib from "@clusterio/lib";
import * as messages from "../messages";
import * as messages from "../messages.js";
import ReportsPage from "./components/ReportsPage";
export class WebPlugin extends BaseWebPlugin {
reports = new lib.MapSubscriber(messages.ReportUpdatedEvent, this.control);
let reports: lib.MapSubscriber<messages.ReportUpdatedEvent> | undefined;
async init() {
this.pages = [
{
path: "/reports",
sidebarName: "Reports",
permission: "exp_reports.report.list",
content: <ReportsPage />,
},
];
}
export function useReports() {
const subscribe = useCallback((cb: () => void) => reports!.subscribe(cb), []);
return useSyncExternalStore(subscribe, () => reports!.getSnapshot());
}
useReports() {
const subscribe = useCallback((cb: () => void) => this.reports.subscribe(cb), []);
return useSyncExternalStore(subscribe, () => this.reports.getSnapshot());
}
export default function registerPlugin(context: WebPluginContext) {
context.control.hooks.pages.attach("exp_reports", () => [
{
path: "/reports",
sidebarName: "Reports",
permission: "exp_reports.report.list",
content: <ReportsPage />,
},
]);
reports = new lib.MapSubscriber(messages.ReportUpdatedEvent, context.control);
}