mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-11 15:54:52 +09:00
clusterio logs "using deprecated class export" for every node entrypoint that exports a Base*Plugin subclass, and the web UI logs "using deprecated class hooks" for WebPlugin classes. Every entrypoint now has a default export function, like exp_auto_restart and the exp_roles web plugin. The classes stay where they hold state, but no longer extend the base classes. The constructor takes the load context and init() attaches the hooks the base class used to attach from the on* methods, so the tests can still call those methods directly. exp_server_ups sends its RCON command through instance.sendRcon with the plugin name, which is what the removed BaseInstancePlugin.sendRcon did. The instance entrypoints of exp_commands, exp_gui, exp_legacy, exp_util and exp_scenario were empty classes, kept only so the host loads the plugin and patches its module into the save. An empty function does the same. The exp_groups web components read the subscriptions through exported useGroups, useAssignments and useRoleMappings hooks instead of looking the plugin up in control.plugins, which only holds class plugins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
111 lines
3.9 KiB
TypeScript
111 lines
3.9 KiB
TypeScript
import React, { useState, useCallback, useSyncExternalStore } from "react";
|
|
import { WebPluginContext, PageLayout, PageHeader, useAccount, SectionHeader } from "@clusterio/web_ui";
|
|
import { Button } from "antd";
|
|
|
|
import * as messages from "../messages.js";
|
|
import * as lib from "@clusterio/lib";
|
|
|
|
import GroupsTable from "./components/GroupsTable";
|
|
import AssignmentsTable from "./components/AssignmentsTable";
|
|
import RoleMappingsTable from "./components/RoleMappingsTable";
|
|
import GroupViewPage from "./components/GroupViewPage";
|
|
import GroupForm from "./components/GroupForm";
|
|
import RoleMappingForm from "./components/RoleMappingForm";
|
|
import AssignmentForm from "./components/AssignmentForm";
|
|
|
|
|
|
function ExpGroupsPage() {
|
|
const account = useAccount();
|
|
|
|
const [groupOpen, setGroupOpen] = useState(false);
|
|
const [assignmentOpen, setAssignmentOpen] = useState(false);
|
|
const [roleMappingOpen, setRoleMappingOpen] = useState(false);
|
|
|
|
return <PageLayout nav={[{ name: "Permission Groups" }]}>
|
|
<PageHeader title="Permission Groups" />
|
|
|
|
{account.hasPermission("exp_groups.group.list") && <>
|
|
<SectionHeader
|
|
title="Groups"
|
|
extra={
|
|
account.hasPermission("exp_groups.group.create")
|
|
? <Button type="primary" onClick={() => setGroupOpen(true)}>Create</Button>
|
|
: undefined
|
|
}
|
|
/>
|
|
<GroupsTable />
|
|
<GroupForm open={groupOpen} setOpen={setGroupOpen} />
|
|
</>}
|
|
|
|
{account.hasPermission("exp_groups.role_mapping.list") && <>
|
|
<SectionHeader
|
|
title="Role Mappings"
|
|
extra={
|
|
account.hasPermission("exp_groups.role_mapping.create")
|
|
? <Button type="primary" onClick={() => setRoleMappingOpen(true)}>Create</Button>
|
|
: undefined
|
|
}
|
|
/>
|
|
<RoleMappingsTable />
|
|
<RoleMappingForm open={roleMappingOpen} setOpen={setRoleMappingOpen} />
|
|
</>}
|
|
|
|
{account.hasPermission("exp_groups.assignment.list") && <>
|
|
<SectionHeader
|
|
title="Assignments"
|
|
extra={
|
|
account.hasPermission("exp_groups.assignment.create")
|
|
? <Button type="primary" onClick={() => setAssignmentOpen(true)}>Create</Button>
|
|
: undefined
|
|
}
|
|
/>
|
|
<AssignmentsTable />
|
|
<AssignmentForm open={assignmentOpen} setOpen={setAssignmentOpen} />
|
|
</>}
|
|
</PageLayout>;
|
|
}
|
|
|
|
let groups: lib.MapSubscriber<messages.GroupUpdatedEvent> | undefined;
|
|
let assignments: lib.MapSubscriber<messages.ManualAssignmentUpdatedEvent> | undefined;
|
|
let roleMappings: lib.MapSubscriber<messages.RoleMappingUpdatedEvent> | undefined;
|
|
|
|
export function useGroups() {
|
|
const subscribe = useCallback((cb: () => void) => groups!.subscribe(cb), []);
|
|
return useSyncExternalStore(subscribe, () => groups!.getSnapshot());
|
|
}
|
|
|
|
export function useAssignments() {
|
|
const subscribe = useCallback((cb: () => void) => assignments!.subscribe(cb), []);
|
|
return useSyncExternalStore(subscribe, () => assignments!.getSnapshot());
|
|
}
|
|
|
|
export function useRoleMappings() {
|
|
const subscribe = useCallback((cb: () => void) => roleMappings!.subscribe(cb), []);
|
|
return useSyncExternalStore(subscribe, () => roleMappings!.getSnapshot());
|
|
}
|
|
|
|
export default function registerPlugin(context: WebPluginContext) {
|
|
context.control.hooks.pages.attach("exp_groups", () => [
|
|
{
|
|
path: "/permission_groups",
|
|
sidebarName: "Permission Groups",
|
|
permission: (account => account.hasAnyPermission(
|
|
"exp_groups.group.list",
|
|
"exp_groups.assignment.list",
|
|
"exp_groups.role_mapping.list",
|
|
)),
|
|
content: <ExpGroupsPage />,
|
|
},
|
|
{
|
|
path: "/permission_groups/:id/view",
|
|
sidebarPath: "/permission_groups",
|
|
permission: "exp_groups.group.get",
|
|
content: <GroupViewPage />,
|
|
},
|
|
]);
|
|
|
|
groups = new lib.MapSubscriber(messages.GroupUpdatedEvent, context.control);
|
|
assignments = new lib.MapSubscriber(messages.ManualAssignmentUpdatedEvent, context.control);
|
|
roleMappings = new lib.MapSubscriber(messages.RoleMappingUpdatedEvent, context.control);
|
|
}
|