added select

main
alex 2023-10-29 16:34:53 +01:00
parent b5b8480726
commit 5d1b9bec2c
3 changed files with 72 additions and 6 deletions

View File

@ -85,7 +85,8 @@
},
"select": {
"placeholder": "Wählen Sie einen Gruppentyp",
"machinePlaceholder": "Wählen Sie eine Maschine"
"machinePlaceholder": "Wählen Sie eine Maschine",
"valuePlaceholder": "Wählen Sie einen Wert"
},
"form": {
"item": {

View File

@ -85,7 +85,8 @@
},
"select": {
"placeholder": "Select a Group Type",
"machinePlaceholder": "Select a Machine"
"machinePlaceholder": "Select a Machine",
"valuePlaceholder": "Select a Value"
},
"form": {
"item": {

View File

@ -9,9 +9,10 @@ import {
Select,
Space,
Tag,
Typography,
notification,
} from "antd";
import { GetUuid, myFetch } from "../../../utils";
import { AppStyle, Constants, GetUuid, myFetch } from "../../../utils";
import { InfoCircleOutlined } from "@ant-design/icons";
import TextArea from "antd/es/input/TextArea";
import { useTranslation } from "react-i18next";
@ -19,6 +20,7 @@ import { useWebSocketContext } from "../../../Contexts/WebSocketContext";
import { useGroupTasksContext } from "../../../Contexts/GroupTasksContext";
import { SentMessagesCommands } from "../../../Handlers/WebSocketMessageHandler";
import { useEffect, useRef, useState } from "react";
import Paragraph from "antd/es/skeleton/Paragraph";
export default function GroupTypeSelectionModal({
isOpen,
@ -80,7 +82,7 @@ export default function GroupTypeSelectionModal({
if (userSpecifiedGlobalInputs.length > 0) {
for (let i = 0; i < userSpecifiedGlobalInputs.length; i++) {
if (userSpecifiedGlobalInputs[i].type === "select") {
if (userSpecifiedGlobalInputs[i].type === "search") {
foundSelectInputs = foundSelectInputs + 1;
continue;
}
@ -258,6 +260,41 @@ export default function GroupTypeSelectionModal({
);
}
export function SelectComponent({ t, globalInput }) {
const groupTasksContext = useGroupTasksContext();
if (globalInput.options === null) {
return (
<Typography.Text type="danger">
Options for this input not specified in the index.json
</Typography.Text>
);
}
return (
<Select
placeholder={t(
"groupTasks.groupTypeSelectionModal.select.valuePlaceholder"
)}
style={{ width: "100%" }}
options={globalInput.options.map((option) => {
return {
label: option,
value: option,
};
})}
onChange={(value) => {
groupTasksContext.setSelectInputs((prevState) => ({
...prevState,
[globalInput.parameterName]: {
value: value,
},
}));
}}
/>
);
}
export function SelectMachineComponent({
t,
notificationApi,
@ -381,7 +418,13 @@ function GroupGlobalInputs({
const getLabel = (displayName) => {
return (
<>
{displayName}
{displayName === undefined || displayName === "" ? (
<Typography.Text type="danger">
DisplayName is missing
</Typography.Text>
) : (
displayName
)}
<Tag style={{ marginLeft: 6 }} color="purple">
{t("groupTasks.tag.global")}
</Tag>
@ -453,7 +496,17 @@ function GroupGlobalInputs({
break;
case "checkbox":
elements.push(
<Form.Item key={index} required>
<Form.Item
key={index}
required
style={{
marginBottom:
group.globalInputs.length > index &&
group.globalInputs[index + 1].type === "checkbox"
? 0
: 12,
}}
>
<Checkbox
id={globalInput.parameterName}
defaultChecked={
@ -468,6 +521,17 @@ function GroupGlobalInputs({
</Form.Item>
);
break;
case "select":
elements.push(
<Form.Item
key={index}
label={getLabel(globalInput.displayName)}
required
>
<SelectComponent t={t} globalInput={globalInput} />
</Form.Item>
);
break;
default:
notificationApi["error"]({