mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 16:23:12 +09:00
Add InputRole as a drop down selector
This commit is contained in:
3 files changed
+33
No files matched your search
@@ -157,6 +157,7 @@ export class ControllerConfig extends classes.Config<ControllerConfigFields> {
|
|||||||
"controller.default_role_id": {
|
"controller.default_role_id": {
|
||||||
title: "Default role",
|
title: "Default role",
|
||||||
description: "ID of role assigned by default to new users.",
|
description: "ID of role assigned by default to new users.",
|
||||||
|
inputComponent: "role",
|
||||||
type: "number",
|
type: "number",
|
||||||
optional: true,
|
optional: true,
|
||||||
initialValue: 1,
|
initialValue: 1,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import * as lib from "@clusterio/lib";
|
|||||||
|
|
||||||
import App from "./components/App";
|
import App from "./components/App";
|
||||||
import BaseWebPlugin, { InputComponent } from "./BaseWebPlugin";
|
import BaseWebPlugin, { InputComponent } from "./BaseWebPlugin";
|
||||||
|
import InputRole from "./components/InputRole";
|
||||||
import InputModPack from "./components/InputModPack";
|
import InputModPack from "./components/InputModPack";
|
||||||
import { Control, ControlConnector } from "./util/websocket";
|
import { Control, ControlConnector } from "./util/websocket";
|
||||||
|
|
||||||
@@ -109,6 +110,7 @@ async function loadPlugins(pluginInfos: lib.PluginWebpackEnvInfo[], control: Con
|
|||||||
function inputComponentsFromPlugins(plugins: Map<string, BaseWebPlugin>) {
|
function inputComponentsFromPlugins(plugins: Map<string, BaseWebPlugin>) {
|
||||||
const inputComponents: Record<string, InputComponent> = {
|
const inputComponents: Record<string, InputComponent> = {
|
||||||
"mod_pack": InputModPack,
|
"mod_pack": InputModPack,
|
||||||
|
"role": InputRole,
|
||||||
};
|
};
|
||||||
for (let [pluginName, plugin] of plugins) {
|
for (let [pluginName, plugin] of plugins) {
|
||||||
for (const [name, Component] of Object.entries(plugin.inputComponents)) {
|
for (const [name, Component] of Object.entries(plugin.inputComponents)) {
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import React, { useContext, useEffect, useState } from "react";
|
||||||
|
import { Select } from "antd";
|
||||||
|
|
||||||
|
import * as lib from "@clusterio/lib";
|
||||||
|
|
||||||
|
import ControlContext from "./ControlContext";
|
||||||
|
import { notifyErrorHandler } from "../util/notify";
|
||||||
|
import { InputComponentProps } from "../BaseWebPlugin";
|
||||||
|
|
||||||
|
export default function InputRole(props: InputComponentProps) {
|
||||||
|
let control = useContext(ControlContext);
|
||||||
|
let [roles, setRoles] = useState<lib.Role[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
control.send(new lib.RoleListRequest()).then(newRoles => {
|
||||||
|
setRoles(newRoles);
|
||||||
|
}).catch(notifyErrorHandler("Error fetching role list"));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return <Select
|
||||||
|
style={{ minWidth: 175 }}
|
||||||
|
onChange={(value) => props.onChange(value ?? null)}
|
||||||
|
value={props.value}
|
||||||
|
options={[...roles.values()].map(role => ({
|
||||||
|
label: role.name,
|
||||||
|
value: role.id,
|
||||||
|
}))}
|
||||||
|
allowClear={props.fieldDefinition.optional}
|
||||||
|
/>;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user