Merge pull request #664 from Cooldude2606/feature/role-drop-down

Add InputRole as a drop down selector
This commit is contained in:
Cooldude2606 authored and GitHub committed 2024-09-21 01:22:52 +01:00
commit 3e6806ff0e
4 files changed
+41 -1

No files matched your search

+8 -1
View File
@@ -31,6 +31,10 @@ Many thanks to the following for contributing to this release:
- Added clean script to speed up publishing and debugging of build steps [#640](https://github.com/clusterio/clusterio/pull/640).
- Added sub-tile option on plugin page headers [#642](https://github.com/clusterio/clusterio/pull/642).
- Greatly improved plugin and module template generation [#641](https://github.com/clusterio/clusterio/pull/641).
- Duplicate host connections from the same address will kill the older host process [#647](https://github.com/clusterio/clusterio/pull/647).
- Controller will refuse duplicate host connections from different addresses [#647](https://github.com/clusterio/clusterio/pull/647).
- Monorepos are now supported for external plugins [#654](https://github.com/clusterio/clusterio/pull/654).
- Changed default role selection to be a dropdown menu rather than id [#664](https://github.com/clusterio/clusterio/pull/664).
- Added credential option to config entries to allow writing sensitive data that can't be read back remotely.
### Changes
@@ -42,7 +46,7 @@ Many thanks to the following for contributing to this release:
- Fixed loopback routing for instances reporting the wrong error message [#625](https://github.com/clusterio/clusterio/pull/625).
- Fixed docs linking to non-existing js files after ts migration [#633](https://github.com/clusterio/clusterio/pull/633).
- Fixed CI workflows using deprecated version of nodejs [#637](https://github.com/clusterio/clusterio/pull/637).
- Fixed test running on windows that should be linux only [#628](https://github.com/clusterio/clusterio/pull/628).
- Fixed linux only tests to run on windows [#661](https://github.com/clusterio/clusterio/pull/661).
- Fixed log events being sent from a host over an invalid websocket [#639](https://github.com/clusterio/clusterio/pull/639).
- Bumped Typescript version to 5.5 and implemented `${configDir}` in base configs for "outDir" [#648](https://github.com/clusterio/clusterio/pull/648).
- Fixed spaces passed in arguments to the installer causing it to break [#620](https://github.com/clusterio/clusterio/issues/620)
@@ -51,6 +55,9 @@ Many thanks to the following for contributing to this release:
- Added instance version display [#573](https://github.com/clusterio/clusterio/pull/573)
- Added `factorio.shutdown_timeout` config to set the time the host will wait for a Factorio server to shut down befor killing it.
- Changed shutdown logic to prefer sending a /quit command via RCON instead of using diverging logic on Windows and Linux.
- Fixed issues with subscriptions which prevented them from working on instances or generic events [#655](https://github.com/clusterio/clusterio/pull/655).
- Fixed unreliable datastore tests [#662](https://github.com/clusterio/clusterio/pull/662).
- Added option for silent tests.
- Added `controller.factorio_username` and `controller.factorio_token` config to set Factorio credentials used for the whole cluster.
- Added `controller.share_factorio_credential_with_hosts` config to optionally require hosts to provide their own credentials.
- Added `host.factorio_username` and `host.factorio_token` config to set Factorio credentials used on a given host.
+1
View File
@@ -183,6 +183,7 @@ export class ControllerConfig extends classes.Config<ControllerConfigFields> {
"controller.default_role_id": {
title: "Default role",
description: "ID of role assigned by default to new users.",
inputComponent: "role",
type: "number",
optional: true,
initialValue: 1,
+2
View File
@@ -7,6 +7,7 @@ import * as lib from "@clusterio/lib";
import App from "./components/App";
import BaseWebPlugin, { InputComponent } from "./BaseWebPlugin";
import InputRole from "./components/InputRole";
import InputModPack from "./components/InputModPack";
import { Control, ControlConnector } from "./util/websocket";
@@ -109,6 +110,7 @@ async function loadPlugins(pluginInfos: lib.PluginWebpackEnvInfo[], control: Con
function inputComponentsFromPlugins(plugins: Map<string, BaseWebPlugin>) {
const inputComponents: Record<string, InputComponent> = {
"mod_pack": InputModPack,
"role": InputRole,
};
for (let [pluginName, plugin] of plugins) {
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}
/>;
}