dynamic machines

main
alex 2023-09-09 11:34:24 +02:00
parent 7b0b7f7033
commit 8c3431a60d
7 changed files with 290 additions and 121 deletions

View File

@ -59,6 +59,10 @@
"globalInputTypeNotImplemented": { "globalInputTypeNotImplemented": {
"message": "Typ {{globalInputType}} nicht implementiert", "message": "Typ {{globalInputType}} nicht implementiert",
"description": "Wurde festgelegt in: {{globalInputDisplayName}}" "description": "Wurde festgelegt in: {{globalInputDisplayName}}"
},
"globalInputOptionsMissing": {
"message": "Optionen für Maschinenauswahl fehlen",
"description": "Wurde festgelegt in {{globalInputParamterName}}"
} }
}, },
"title": "Wählen Sie einen Gruppentyp", "title": "Wählen Sie einen Gruppentyp",
@ -76,7 +80,8 @@
} }
}, },
"h3": "Füllen Sie die globalen Werte aus", "h3": "Füllen Sie die globalen Werte aus",
"noNotesSpecified": "Keine Notizen angegeben" "noNotesSpecified": "Keine Notizen angegeben",
"noNotesDisplayNameSpecified": "Kein Anzeigename für Notizen angegeben"
}, },
"tag.global": "Global", "tag.global": "Global",
"groupTasksViewModal": { "groupTasksViewModal": {
@ -85,9 +90,7 @@
"inputsCannotBeEmpty": { "inputsCannotBeEmpty": {
"message": "Eingaben können nicht leer sein", "message": "Eingaben können nicht leer sein",
"description": "Bitte füllen Sie alle Felder aus" "description": "Bitte füllen Sie alle Felder aus"
}, }
"groupTaskParameterNotImplemented.message": "Typ {{groupTaskParameterType}} nicht implementiert",
"groupTaskParameterNotImplemented.description": "Wurde festgelegt in: {{groupTaskParameterDisplayName}}"
}, },
"startedAt": "Gestartet am", "startedAt": "Gestartet am",
"endedAt": "Beendet am", "endedAt": "Beendet am",

View File

@ -59,6 +59,10 @@
"globalInputTypeNotImplemented": { "globalInputTypeNotImplemented": {
"message": "Type {{globalInputType}} not implemented", "message": "Type {{globalInputType}} not implemented",
"description": "Defined in: {{globalInputDisplayName}}" "description": "Defined in: {{globalInputDisplayName}}"
},
"globalInputOptionsMissing": {
"message": "Options for machine select missing",
"description": "Defined in {{globalInputParamterName}}"
} }
}, },
"title": "Select a Group Type", "title": "Select a Group Type",
@ -76,7 +80,8 @@
} }
}, },
"h3": "Fill in the global values", "h3": "Fill in the global values",
"noNotesSpecified": "No notes specified" "noNotesSpecified": "No notes specified",
"noNotesDisplayNameSpecified": "No notes display name specified"
}, },
"tag.global": "Global", "tag.global": "Global",
"groupTasksViewModal": { "groupTasksViewModal": {
@ -85,9 +90,7 @@
"inputsCannotBeEmpty": { "inputsCannotBeEmpty": {
"message": "Inputs cannot be empty", "message": "Inputs cannot be empty",
"description": "Please fill in all fields" "description": "Please fill in all fields"
}, }
"groupTaskParameterNotImplemented.message": "Type {{groupTaskParameterType}} not implemented",
"groupTaskParameterNotImplemented.description": "Defined in: {{groupTaskParameterDisplayName}}"
}, },
"startedAt": "Started at", "startedAt": "Started at",
"endedAt": "Ended at", "endedAt": "Ended at",

View File

@ -9,6 +9,7 @@ const preview = {
totalPages: 0, totalPages: 0,
previousParamCategory: null, previousParamCategory: null,
paginationPageRef: null, paginationPageRef: null,
selectInputs: {},
}; };
const GroupTasksContext = createContext(preview); const GroupTasksContext = createContext(preview);
@ -28,6 +29,8 @@ export function GroupTasksProvider({ children }) {
const paginationPageRef = useRef(paginationPage); const paginationPageRef = useRef(paginationPage);
const [totalPages, setTotalPages] = useState(0); const [totalPages, setTotalPages] = useState(0);
const previousParamCategory = useRef(null); const previousParamCategory = useRef(null);
// this is used for the <Select /> inputs as there is no way to manipulate the select value via the DOM (like we do on the text inputs) as it is needed by the websocket
const [selectInputs, setSelectInputs] = useState({});
return ( return (
<GroupTasksContext.Provider <GroupTasksContext.Provider
@ -45,6 +48,8 @@ export function GroupTasksProvider({ children }) {
setTotalPages, setTotalPages,
previousParamCategory, previousParamCategory,
paginationPageRef, paginationPageRef,
selectInputs,
setSelectInputs,
}} }}
> >
{children} {children}

View File

@ -325,6 +325,10 @@ export function handleWebSocketMessage(
}); });
// update input value // update input value
console.log("body", body);
if (body.inputType === "text") {
// html based DOM manipulation // html based DOM manipulation
const foundInput = document.getElementById(body.element); const foundInput = document.getElementById(body.element);
@ -332,6 +336,29 @@ export function handleWebSocketMessage(
// this timeout is needed because the previous useState for the lockedByUserId takes some milliseconds to complete // this timeout is needed because the previous useState for the lockedByUserId takes some milliseconds to complete
setTimeout(() => setNativeValue(foundInput, body.value), 50); setTimeout(() => setNativeValue(foundInput, body.value), 50);
} }
} else if (body.inputType === "select") {
groupTasksContext.setSelectInputs((prev) => {
const newInputs = { ...prev };
console.log("newInputs", newInputs);
if (newInputs[body.parameterName] === undefined) {
newInputs[body.parameterName] = {
value: body.value,
data: body.data,
};
} else {
newInputs[body.parameterName].value = body.value;
newInputs[body.parameterName].data = body.data;
}
//newInputs[body.parameterName].value = body.value;
return newInputs;
});
} else {
console.error("Unknown input type");
}
// update group task step as html based DOM manipulation only works if user has no other modal open // update group task step as html based DOM manipulation only works if user has no other modal open
groupTasksContext.setGroupTasksSteps((arr) => { groupTasksContext.setGroupTasksSteps((arr) => {

View File

@ -10,7 +10,7 @@ import {
Tag, Tag,
notification, notification,
} from "antd"; } from "antd";
import { useEffect, useRef, useState } from "react"; import { useEffect, useRef } from "react";
import { useNavigate, useParams } from "react-router-dom"; import { useNavigate, useParams } from "react-router-dom";
import { import {
Constants, Constants,
@ -26,7 +26,6 @@ import {
RetweetOutlined, RetweetOutlined,
UndoOutlined, UndoOutlined,
} from "@ant-design/icons"; } from "@ant-design/icons";
import TextArea from "antd/es/input/TextArea"; import TextArea from "antd/es/input/TextArea";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { MyAvatar } from "../../../Components/MyAvatar"; import { MyAvatar } from "../../../Components/MyAvatar";
@ -39,6 +38,7 @@ import {
GroupTasksStepsLockedAndUserUpdateInputValueRememberId, GroupTasksStepsLockedAndUserUpdateInputValueRememberId,
SentMessagesCommands, SentMessagesCommands,
} from "../../../Handlers/WebSocketMessageHandler"; } from "../../../Handlers/WebSocketMessageHandler";
import { SelectMachineComponent } from "./GroupTypeSelectionModal";
export default function GroupTasksViewModal({ isOpen }) { export default function GroupTasksViewModal({ isOpen }) {
const webSocketContext = useWebSocketContext(); const webSocketContext = useWebSocketContext();
@ -147,6 +147,7 @@ export default function GroupTasksViewModal({ isOpen }) {
let canTaskContinued = true; let canTaskContinued = true;
let taskInputs = []; let taskInputs = [];
let foundSelectInputs = 0;
if (groupTasksViewModalRequiredInputsForm !== null) { if (groupTasksViewModalRequiredInputsForm !== null) {
const specifiedTaskInputs = const specifiedTaskInputs =
@ -154,6 +155,11 @@ export default function GroupTasksViewModal({ isOpen }) {
if (specifiedTaskInputs.length > 0) { if (specifiedTaskInputs.length > 0) {
for (let i = 0; i < specifiedTaskInputs.length; i++) { for (let i = 0; i < specifiedTaskInputs.length; i++) {
if (specifiedTaskInputs[i].type !== "text") {
foundSelectInputs = foundSelectInputs + 1;
continue;
}
if (specifiedTaskInputs[i].value === "") { if (specifiedTaskInputs[i].value === "") {
canTaskContinued = false; canTaskContinued = false;
break; break;
@ -190,6 +196,24 @@ export default function GroupTasksViewModal({ isOpen }) {
} }
} }
const selectInputsObjectKeys = Object.keys(groupTasksContext.selectInputs);
// if there are select inputs, we need to check if they are all selected
if (
foundSelectInputs > 0 &&
foundSelectInputs !== selectInputsObjectKeys.length
) {
canTaskContinued = false;
} else {
selectInputsObjectKeys.forEach((key) => {
taskInputs.push({
parameterName: key,
value: groupTasksContext.selectInputs[key].value,
data: groupTasksContext.selectInputs[key].data,
});
});
}
if (!canTaskContinued) { if (!canTaskContinued) {
notificationApi["error"]({ notificationApi["error"]({
message: t( message: t(
@ -213,6 +237,9 @@ export default function GroupTasksViewModal({ isOpen }) {
taskInputs: taskInputs, taskInputs: taskInputs,
} }
); );
// reset the select inputs
groupTasksContext.setSelectInputs({});
}; };
const handleUserActionTaskStep = (action, taskStepId, step) => { const handleUserActionTaskStep = (action, taskStepId, step) => {
@ -583,8 +610,11 @@ export default function GroupTasksViewModal({ isOpen }) {
.find( .find(
(group) => group.id === currentGroupTask.current.GroupId (group) => group.id === currentGroupTask.current.GroupId
) )
.globalInputs.find((gI) => gI.parameterName === globalInput) .globalInputs.find(
.displayName (gI) =>
gI.parameterName ===
parsedGlobalInputs[globalInput].parameterName
).displayName
} }
:{" "} :{" "}
</span> </span>
@ -704,7 +734,7 @@ function InputRequiredHandler({
taskLockedByUserId, taskLockedByUserId,
}) { }) {
const { t } = useTranslation(); const { t } = useTranslation();
const [inputFields, setInputFields] = useState({}); //const [inputFields, setInputFields] = useState({});
const globalInputs = JSON.parse(currentGroupTask.GlobalInputs); const globalInputs = JSON.parse(currentGroupTask.GlobalInputs);
const stepInputs = JSON.parse(groupTaskStepInputs); const stepInputs = JSON.parse(groupTaskStepInputs);
@ -721,7 +751,7 @@ function InputRequiredHandler({
} }
} }
if (globalInputs === undefined || !groupTaskParameter.global) return null; if (globalInputs === undefined || !groupTaskParameter.global) return "";
const globalInputValue = globalInputs[groupTaskParameter.parameterName]; const globalInputValue = globalInputs[groupTaskParameter.parameterName];
@ -745,61 +775,71 @@ function InputRequiredHandler({
let typingTimer = useRef(); let typingTimer = useRef();
const sendTypingMessage = ( const sendTypingMessage = (
inputType,
currentGroupTaskId, currentGroupTaskId,
groupTaskParameterName, groupTaskParameterName,
inputValue inputValue,
notes
) => { ) => {
webSocketContext.SendSocketMessage(SentMessagesCommands.TaskLocking, { const data = {
category: currentGroupTask.Category, // needed for ws topic category: currentGroupTask.Category, // needed for ws topic
element: `${currentGroupTaskId}-${step}-${groupTaskParameterName}`,
lockedByUserId: appContext.userId.current, lockedByUserId: appContext.userId.current,
groupTaskId: currentGroupTaskId, groupTaskId: currentGroupTaskId,
parameterName: groupTaskParameterName, parameterName: groupTaskParameterName,
value: inputValue, value: inputValue,
step: step, step: step,
rememberId: GroupTasksStepsLockedAndUserUpdateInputValueRememberId, rememberId: GroupTasksStepsLockedAndUserUpdateInputValueRememberId,
}); inputType: inputType,
}; };
const onInputChange = ( if (inputType === "text") {
// element is only needed for text inputs for the DOM manipulation
data.element = `${currentGroupTaskId}-${step}-${groupTaskParameterName}`;
} else {
data.data = notes;
}
webSocketContext.SendSocketMessage(SentMessagesCommands.TaskLocking, data);
};
const handleInputChange = (
inputType,
inputValue, inputValue,
currentGroupTaskId, currentGroupTaskId,
groupTaskParameterName groupTaskParameterName,
notes
) => { ) => {
setInputFields((fields) => { const typingMessage = () => {
return ({ ...fields }[groupTaskParameterName] = sendTypingMessage(
inputValue === null ? "" : inputValue); inputType,
}); currentGroupTaskId,
groupTaskParameterName,
inputValue,
notes
);
};
if (taskLockedByUserId !== "") return; if (taskLockedByUserId !== "") return;
if (Date.now() >= lastChange.current || lastChange.current === undefined) { if (Date.now() >= lastChange.current || lastChange.current === undefined) {
lastChange.current = Date.now() + 1000; lastChange.current = Date.now() + 1000;
sendTypingMessage(currentGroupTaskId, groupTaskParameterName, inputValue); typingMessage();
} else { } else {
clearTimeout(typingTimer.current); clearTimeout(typingTimer.current);
} }
typingTimer.current = setTimeout( typingTimer.current = setTimeout(() => typingMessage(), 1000);
() =>
sendTypingMessage(
currentGroupTaskId,
groupTaskParameterName,
inputValue
),
1000
);
}; };
return ( return (
<Form layout="vertical" id="groupTasksViewModalRequiredInputsForm"> <Form layout="vertical" id="groupTasksViewModalRequiredInputsForm">
{groupTaskParameters.map((groupTaskParameter) => { {groupTaskParameters.map((groupTaskParameter, index) => {
switch (groupTaskParameter.type) { switch (groupTaskParameter.type) {
case "text": case "text":
return ( return (
<Form.Item <Form.Item
key={"fitem-" + groupTaskParameter.parameterName} key={index}
label={getLabel( label={getLabel(
groupTaskParameter.displayName, groupTaskParameter.displayName,
groupTaskParameter groupTaskParameter
@ -811,20 +851,21 @@ function InputRequiredHandler({
defaultValue={getDefaultValue(groupTaskParameter)} defaultValue={getDefaultValue(groupTaskParameter)}
disabled={taskLockedByUserId !== ""} disabled={taskLockedByUserId !== ""}
onChange={(e) => onChange={(e) =>
onInputChange( handleInputChange(
"text",
e.target.value, e.target.value,
currentGroupTask.Id, currentGroupTask.Id,
groupTaskParameter.parameterName groupTaskParameter.parameterName
) )
} }
value={inputFields[groupTaskParameter.parameterName]} //value={inputFields[groupTaskParameter.parameterName]}
/> />
</Form.Item> </Form.Item>
); );
case "number": case "number":
return ( return (
<Form.Item <Form.Item
key={"fitem-" + groupTaskParameter.parameterName} key={index}
label={getLabel( label={getLabel(
groupTaskParameter.displayName, groupTaskParameter.displayName,
groupTaskParameter groupTaskParameter
@ -838,20 +879,21 @@ function InputRequiredHandler({
disabled={taskLockedByUserId !== ""} disabled={taskLockedByUserId !== ""}
max={Number.MAX_SAFE_INTEGER} max={Number.MAX_SAFE_INTEGER}
onChange={(e) => onChange={(e) =>
onInputChange( handleInputChange(
"text",
e, e,
currentGroupTask.Id, currentGroupTask.Id,
groupTaskParameter.parameterName groupTaskParameter.parameterName
) )
} }
value={inputFields[groupTaskParameter.parameterName]} //value={inputFields[groupTaskParameter.parameterName]}
/> />
</Form.Item> </Form.Item>
); );
case "textarea": case "textarea":
return ( return (
<Form.Item <Form.Item
key={"fitem-" + groupTaskParameter.parameterName} key={index}
label={getLabel( label={getLabel(
groupTaskParameter.displayName, groupTaskParameter.displayName,
groupTaskParameter groupTaskParameter
@ -863,31 +905,50 @@ function InputRequiredHandler({
defaultValue={getDefaultValue(groupTaskParameter)} defaultValue={getDefaultValue(groupTaskParameter)}
disabled={taskLockedByUserId !== ""} disabled={taskLockedByUserId !== ""}
onChange={(e) => onChange={(e) =>
onInputChange( handleInputChange(
"text",
e.target.value, e.target.value,
currentGroupTask.Id, currentGroupTask.Id,
groupTaskParameter.parameterName groupTaskParameter.parameterName
) )
} }
value={inputFields[groupTaskParameter.parameterName]} //value={inputFields[groupTaskParameter.parameterName]}
/> />
</Form.Item> </Form.Item>
); );
default: case "select_machine":
notificationApi["error"]({
message: t(
"groupTasks.groupTasksViewModal.notification.groupTaskParameterNotImplemented.message",
{ groupTaskParameterType: groupTaskParameter.type }
),
description: t(
"groupTasks.groupTasksViewModal.notification.groupTaskParameterNotImplemented.description",
{
groupTaskParameterDisplayName: groupTaskParameter.displayName,
}
),
});
return ( return (
<p> <Form.Item
key={index}
label={getLabel(
groupTaskParameter.displayName,
groupTaskParameter
)}
required
>
<SelectMachineComponent
disabled={taskLockedByUserId !== ""}
t={t}
notificationApi={notificationApi}
globalInput={groupTaskParameter}
onSelectChange={(value, notes) => {
console.warn("onSelectChange", value, notes);
handleInputChange(
"select",
value,
currentGroupTask.Id,
groupTaskParameter.parameterName,
notes
);
}}
/>
</Form.Item>
);
default:
return (
<p key={index}>
Type <b>{groupTaskParameter.type}</b> not implemented. Was Type <b>{groupTaskParameter.type}</b> not implemented. Was
specified in: <b>{groupTaskParameter.displayName}</b> specified in: <b>{groupTaskParameter.displayName}</b>
</p> </p>

View File

@ -32,8 +32,6 @@ export default function GroupTypeSelectionModal({
const groupTasksContext = useGroupTasksContext(); const groupTasksContext = useGroupTasksContext();
const { t } = useTranslation(); const { t } = useTranslation();
const handleCancel = () => setIsOpen(false); const handleCancel = () => setIsOpen(false);
const groupTypeDescriptionRef = useRef("");
const groupGlobalInputsRef = useRef({});
const isStartTaskPossible = () => { const isStartTaskPossible = () => {
if ( if (
@ -60,21 +58,77 @@ export default function GroupTypeSelectionModal({
const handleStartTask = () => { const handleStartTask = () => {
let canTaskBeStarted = true; let canTaskBeStarted = true;
if (groupTypeDescriptionRef.current === "") { const groupTaskDescription = document.getElementById(
"fitem-grouptypedescription"
).value;
if (groupTaskDescription === "") {
canTaskBeStarted = false; canTaskBeStarted = false;
} }
// checking if there is some global input with empty value const userSpecifiedGlobalInputForm = document.getElementById(
const globalInputsKeys = Object.keys(groupGlobalInputsRef.current); "groupTypeSelectionUserSpecifiedGlobalInputForm"
);
if (globalInputsKeys.length === 0) { let globalInputs = [];
let foundSelectInputs = 0;
if (canTaskBeStarted && userSpecifiedGlobalInputForm !== null) {
const userSpecifiedGlobalInputs =
userSpecifiedGlobalInputForm.getElementsByTagName("input");
if (userSpecifiedGlobalInputs.length > 0) {
for (let i = 0; i < userSpecifiedGlobalInputs.length; i++) {
if (userSpecifiedGlobalInputs[i].type !== "text") {
foundSelectInputs = foundSelectInputs + 1;
continue;
}
if (userSpecifiedGlobalInputs[i].value === "") {
canTaskBeStarted = false;
break;
}
globalInputs.push({
parameterName: userSpecifiedGlobalInputs[i].id,
value: userSpecifiedGlobalInputs[i].value,
});
}
}
const userSpecifiedGlobalTextareas =
userSpecifiedGlobalInputForm.getElementsByTagName("textarea");
if (userSpecifiedGlobalTextareas.length > 0) {
for (let i = 0; i < userSpecifiedGlobalTextareas.length; i++) {
if (userSpecifiedGlobalTextareas[i].value === "") {
canTaskBeStarted = false;
break;
}
globalInputs.push({
parameterName: userSpecifiedGlobalTextareas[i].id,
value: userSpecifiedGlobalTextareas[i].value,
});
}
}
}
const selectInputsObjectKeys = Object.keys(groupTasksContext.selectInputs);
// if there are select inputs, we need to check if they are all selected
if (
foundSelectInputs > 0 &&
foundSelectInputs !== selectInputsObjectKeys.length
) {
canTaskBeStarted = false; canTaskBeStarted = false;
} else { } else {
Object.keys(groupGlobalInputsRef.current).forEach((key) => { selectInputsObjectKeys.forEach((key) => {
if (groupGlobalInputsRef.current[key].value === "") { globalInputs.push({
canTaskBeStarted = false; parameterName: key,
return; value: groupTasksContext.selectInputs[key].value,
} data: groupTasksContext.selectInputs[key].data,
});
}); });
} }
@ -112,15 +166,14 @@ export default function GroupTypeSelectionModal({
category: categoryGroup.category, category: categoryGroup.category,
id: currentSelectedModalGroupType, id: currentSelectedModalGroupType,
groupName: groupName, groupName: groupName,
description: groupTypeDescriptionRef.current, description: groupTaskDescription,
numberOfSteps: parseInt(numberOfSteps), numberOfSteps: parseInt(numberOfSteps),
globalInputs: groupGlobalInputsRef.current, globalInputs: globalInputs,
rememberId: rememberId, // used to open the modal when group task is started by backend and send via websocket back rememberId: rememberId, // used to open the modal when group task is started by backend and send via websocket back
}); });
// reset // reset select inputs
groupTypeDescriptionRef.current = ""; groupTasksContext.setSelectInputs({});
groupGlobalInputsRef.current = {};
}; };
return ( return (
@ -180,11 +233,7 @@ export default function GroupTypeSelectionModal({
}} }}
required required
> >
<Input <Input id="fitem-grouptypedescription" />
onInput={(e) =>
(groupTypeDescriptionRef.current = e.nativeEvent.target.value)
}
/>
</Form.Item> </Form.Item>
</Form> </Form>
)} )}
@ -193,18 +242,43 @@ export default function GroupTypeSelectionModal({
categoryGroup={categoryGroup} categoryGroup={categoryGroup}
currentSelectedModalGroupType={currentSelectedModalGroupType} currentSelectedModalGroupType={currentSelectedModalGroupType}
notificationApi={notificationApi} notificationApi={notificationApi}
groupGlobalInputsRef={groupGlobalInputsRef} groupGlobalInputs={groupTasksContext.groupGlobalInputs}
setGroupGlobalInputs={groupTasksContext.setGroupGlobalInputs}
/> />
</Modal> </Modal>
); );
} }
function SelectMachineComponent({ t, globalInput, groupGlobalInputsRef }) { export function SelectMachineComponent({
t,
notificationApi,
globalInput,
onSelectChange,
disabled,
}) {
const groupTasksContext = useGroupTasksContext();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [options, setOptions] = useState([]); const [options, setOptions] = useState([]);
const responseData = useRef([]); const responseData = useRef([]);
useEffect(() => { useEffect(() => {
// if globalInput.options is null, it means that user has not specified any options for this global input in the index.json
if (globalInput.options === null) {
notificationApi["error"]({
message: t(
"groupTasks.groupTypeSelectionModal.notification.globalInputOptionsMissing.message"
),
description: t(
"groupTasks.groupTypeSelectionModal.notification.globalInputOptionsMissing.description",
{
globalInputParamterName: globalInput.parameterName,
}
),
});
return;
}
setLoading(true); setLoading(true);
myFetch("/machines", "POST", globalInput.options).then((data) => { myFetch("/machines", "POST", globalInput.options).then((data) => {
@ -228,11 +302,17 @@ function SelectMachineComponent({ t, globalInput, groupGlobalInputsRef }) {
processedOptions[partName].push({ processedOptions[partName].push({
key: index + item.part_detail.Name, key: index + item.part_detail.Name,
label: label:
// testing if Notes is empty string or if displayName is undefined
parsedNotes === "" parsedNotes === ""
? t("groupTasks.groupTypeSelectionModal.noNotesSpecified") ? t("groupTasks.groupTypeSelectionModal.noNotesSpecified")
: parsedNotes.displayName === undefined
? t(
"groupTasks.groupTypeSelectionModal.noNotesDisplayNameSpecified"
)
: parsedNotes.displayName, : parsedNotes.displayName,
value: index, value: index,
disabled: parsedNotes === "", // disabling option if Notes is empty string or if displayName is undefined
disabled: parsedNotes === "" || parsedNotes.displayName === undefined,
}); });
}); });
@ -250,22 +330,33 @@ function SelectMachineComponent({ t, globalInput, groupGlobalInputsRef }) {
}); });
}, []); }, []);
const selectedInput =
groupTasksContext.selectInputs[globalInput.parameterName]?.value;
return ( return (
<Select <Select
disabled={disabled}
loading={loading} loading={loading}
placeholder={t( placeholder={t(
"groupTasks.groupTypeSelectionModal.select.machinePlaceholder" "groupTasks.groupTypeSelectionModal.select.machinePlaceholder"
)} )}
style={{ width: "100%" }} style={{ width: "100%" }}
id={globalInput.parameterName}
options={options} options={options}
value={selectedInput}
onSelect={(value) => { onSelect={(value) => {
const parsedNotes = JSON.parse(responseData.current[value].Notes); const parsedNotes = JSON.parse(responseData.current[value].Notes);
groupGlobalInputsRef.current[globalInput.parameterName] = { groupTasksContext.setSelectInputs((prevState) => ({
...prevState,
[globalInput.parameterName]: {
value: parsedNotes.displayName, value: parsedNotes.displayName,
data: parsedNotes, data: parsedNotes,
}; },
}));
if (onSelectChange !== undefined) {
onSelectChange(value, parsedNotes);
}
}} }}
/> />
); );
@ -275,7 +366,6 @@ function GroupGlobalInputs({
categoryGroup, categoryGroup,
currentSelectedModalGroupType, currentSelectedModalGroupType,
notificationApi, notificationApi,
groupGlobalInputsRef,
}) { }) {
const { t } = useTranslation(); const { t } = useTranslation();
@ -299,11 +389,6 @@ function GroupGlobalInputs({
group.globalInputs?.length > 0 group.globalInputs?.length > 0
) { ) {
group.globalInputs.forEach((globalInput, index) => { group.globalInputs.forEach((globalInput, index) => {
// this is needed for the check if user clicks on start task button and there is some global input with empty value
groupGlobalInputsRef.current[globalInput.parameterName] = {
value: "",
};
switch (globalInput.type) { switch (globalInput.type) {
case "text": case "text":
elements.push( elements.push(
@ -312,15 +397,7 @@ function GroupGlobalInputs({
label={getLabel(globalInput.displayName)} label={getLabel(globalInput.displayName)}
required required
> >
<Input <Input id={globalInput.parameterName} />
id={globalInput.parameterName}
onChange={(e) =>
(groupGlobalInputsRef.current[globalInput.parameterName] =
{
value: e.nativeEvent.target.value,
})
}
/>
</Form.Item> </Form.Item>
); );
break; break;
@ -335,10 +412,6 @@ function GroupGlobalInputs({
style={{ width: "100%" }} style={{ width: "100%" }}
max={Number.MAX_SAFE_INTEGER} max={Number.MAX_SAFE_INTEGER}
id={globalInput.parameterName} id={globalInput.parameterName}
onInput={(value) =>
(groupGlobalInputsRef.current[globalInput.parameterName] =
{ value: value })
}
/> />
</Form.Item> </Form.Item>
); );
@ -350,15 +423,7 @@ function GroupGlobalInputs({
label={getLabel(globalInput.displayName)} label={getLabel(globalInput.displayName)}
required required
> >
<TextArea <TextArea id={globalInput.parameterName} />
id={globalInput.parameterName}
onChange={(e) =>
(groupGlobalInputsRef.current[globalInput.parameterName] =
{
value: e.nativeEvent.target.value,
})
}
/>
</Form.Item> </Form.Item>
); );
break; break;
@ -371,8 +436,8 @@ function GroupGlobalInputs({
> >
<SelectMachineComponent <SelectMachineComponent
t={t} t={t}
notificationApi={notificationApi}
globalInput={globalInput} globalInput={globalInput}
groupGlobalInputsRef={groupGlobalInputsRef}
/> />
</Form.Item> </Form.Item>
); );

View File

@ -80,6 +80,11 @@ export default function GroupTasks({ isGroupTasksViewModalOpen }) {
[groupTasksContext.paginationPage] [groupTasksContext.paginationPage]
); );
useEffect(
() => groupTasksContext.setSelectInputs({}),
[currentSelectedModalGroupType]
);
return ( return (
<> <>
{groupTasksContext.categoryGroup.Category === "" || {groupTasksContext.categoryGroup.Category === "" ||