mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-09-21 17:04:00 +00:00
Clusterio #984 converted its packages to ESM, so a CommonJS plugin can no longer import @clusterio/lib and plugin entrypoints must name the full file. Every package gets "type": "module", entrypoints and relative imports carry the .js extension, and the webpack configs become .cjs as webpack-cli loads them with require. tsconfig.node.json moves from node16 to nodenext to match clusterio, which needs it for the JSON import attributes in its sources. The tap tests and the shared test helpers use import and import.meta.dirname. The test scripts pass --type-strip-only so tap leaves lib's .ts subpath imports to Node's own type stripping, as its TypeScript loader compiled them without a default export. The lua runner resolves fengari from the test file it is given, since a bare import from the shared test directory does not reach the plugin's devDependencies. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
107 lines
2.8 KiB
TypeScript
107 lines
2.8 KiB
TypeScript
import React, { useContext, useEffect } from "react";
|
|
import { Modal, Form, Select, InputNumber, Switch, Alert } from "antd";
|
|
|
|
import { ControlContext, useRoles } from "@clusterio/web_ui";
|
|
import { RoleMappingRecord, RoleMappingCreateRequest, RoleMappingUpdateRequest } from "../../messages.js";
|
|
import type { WebPlugin } from "..";
|
|
|
|
export default function RoleMappingForm({ open, setOpen, initial }: {
|
|
open: boolean,
|
|
setOpen: (open: boolean) => void,
|
|
initial?: RoleMappingRecord,
|
|
}) {
|
|
const control = useContext(ControlContext);
|
|
const plugin = control.plugins.get("exp_groups") as WebPlugin;
|
|
|
|
const [groups] = plugin.useGroups();
|
|
const [roles] = useRoles();
|
|
|
|
const [form] = Form.useForm();
|
|
|
|
function submit(values: any) {
|
|
if (initial) {
|
|
control.send(new RoleMappingUpdateRequest(
|
|
new RoleMappingRecord(
|
|
initial.id,
|
|
new Set(values.roleIds),
|
|
values.groupId,
|
|
values.priority,
|
|
values.enabled,
|
|
)
|
|
));
|
|
} else {
|
|
control.send(new RoleMappingCreateRequest(
|
|
values.roleIds,
|
|
values.groupId,
|
|
values.priority,
|
|
values.enabled,
|
|
));
|
|
}
|
|
|
|
setOpen(false);
|
|
}
|
|
|
|
useEffect(() => {
|
|
if (open) {
|
|
form.resetFields();
|
|
form.setFieldsValue({
|
|
...initial,
|
|
roleIds: initial ? [...initial.roleIds] : [],
|
|
});
|
|
}
|
|
}, [open, initial]);
|
|
|
|
return <Modal
|
|
title={initial ? "Edit Role Mapping" : "Create Role Mapping"}
|
|
open={open}
|
|
onCancel={() => setOpen(false)}
|
|
onOk={() => form.submit()}
|
|
>
|
|
<Alert
|
|
type="info"
|
|
showIcon
|
|
message="How role mappings work"
|
|
style={{ marginBottom: 16 }}
|
|
description={
|
|
<ul style={{ paddingLeft: 16, margin: 0 }}>
|
|
<li>Manual assignments always take priority.</li>
|
|
<li>Mappings are checked in priority order (highest first).</li>
|
|
<li>A mapping applies only if the user has <b>all listed roles</b>.</li>
|
|
<li>The first matching mapping assigns the group.</li>
|
|
<li>If none match, the player is given all permissions.</li>
|
|
</ul>
|
|
}
|
|
/>
|
|
|
|
<Form form={form} onFinish={submit}>
|
|
<Form.Item name="groupId" label="Group" rules={[{ required: true }]}>
|
|
<Select>
|
|
{[...groups.values()].map(g => (
|
|
<Select.Option key={g.id} value={g.id}>
|
|
{g.name}
|
|
</Select.Option>
|
|
))}
|
|
</Select>
|
|
</Form.Item>
|
|
|
|
<Form.Item name="roleIds" label="Roles" rules={[{ required: true }]}>
|
|
<Select mode="multiple">
|
|
{[...roles.values()].map(r => (
|
|
<Select.Option key={r.id} value={r.id}>
|
|
{r.name}
|
|
</Select.Option>
|
|
))}
|
|
</Select>
|
|
</Form.Item>
|
|
|
|
<Form.Item name="priority" label="Priority" initialValue={100}>
|
|
<InputNumber style={{ width: "100%" }} />
|
|
</Form.Item>
|
|
|
|
<Form.Item name="enabled" label="Enabled" valuePropName="checked" initialValue={true}>
|
|
<Switch />
|
|
</Form.Item>
|
|
</Form>
|
|
</Modal>;
|
|
}
|