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>
75 lines
1.8 KiB
TypeScript
75 lines
1.8 KiB
TypeScript
import React, { useContext, useEffect } from "react";
|
|
import { Modal, Form, Select } from "antd";
|
|
|
|
import { ControlContext, useUsers } from "@clusterio/web_ui";
|
|
import * as messages from "../../messages.js";
|
|
import type { WebPlugin } from "..";
|
|
|
|
export default function AssignmentForm({ open, setOpen, initial }: {
|
|
open: boolean,
|
|
setOpen: (open: boolean) => void,
|
|
initial?: messages.AssignmentRecord,
|
|
}) {
|
|
const control = useContext(ControlContext);
|
|
const plugin = control.plugins.get("exp_groups") as WebPlugin;
|
|
|
|
const [groups] = plugin.useGroups();
|
|
const [users] = useUsers();
|
|
|
|
const [form] = Form.useForm();
|
|
|
|
function submit(values: any) {
|
|
if (initial) {
|
|
control.send(new messages.AssignmentUpdateRequest(
|
|
new messages.AssignmentRecord(
|
|
values.name,
|
|
values.groupId,
|
|
)
|
|
));
|
|
} else {
|
|
control.send(new messages.AssignmentCreateRequest(
|
|
values.name,
|
|
values.groupId,
|
|
));
|
|
}
|
|
|
|
setOpen(false);
|
|
}
|
|
|
|
useEffect(() => {
|
|
if (open) {
|
|
form.resetFields();
|
|
form.setFieldsValue(initial);
|
|
}
|
|
}, [open, initial]);
|
|
|
|
return <Modal
|
|
title={initial ? "Edit Assignment" : "Create Assignment"}
|
|
open={open}
|
|
onCancel={() => setOpen(false)}
|
|
onOk={() => form.submit()}
|
|
>
|
|
<Form form={form} onFinish={submit}>
|
|
<Form.Item name="name" label="Player" rules={[{ required: true }]}>
|
|
<Select disabled={Boolean(initial)} showSearch>
|
|
{[...users.values()].map(u => (
|
|
<Select.Option key={u.name} value={u.name}>
|
|
{u.name}
|
|
</Select.Option>
|
|
))}
|
|
</Select>
|
|
</Form.Item>
|
|
|
|
<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>
|
|
</Modal>;
|
|
}
|