+
Type {groupTaskParameter.type} not implemented. Was specified in: {groupTaskParameter.displayName}
diff --git a/src/Pages/GroupTasks/Overview/GroupTypeSelectionModal.js b/src/Pages/GroupTasks/Overview/GroupTypeSelectionModal.js index f7af506..3d1b1e3 100644 --- a/src/Pages/GroupTasks/Overview/GroupTypeSelectionModal.js +++ b/src/Pages/GroupTasks/Overview/GroupTypeSelectionModal.js @@ -32,8 +32,6 @@ export default function GroupTypeSelectionModal({ const groupTasksContext = useGroupTasksContext(); const { t } = useTranslation(); const handleCancel = () => setIsOpen(false); - const groupTypeDescriptionRef = useRef(""); - const groupGlobalInputsRef = useRef({}); const isStartTaskPossible = () => { if ( @@ -60,21 +58,77 @@ export default function GroupTypeSelectionModal({ const handleStartTask = () => { let canTaskBeStarted = true; - if (groupTypeDescriptionRef.current === "") { + const groupTaskDescription = document.getElementById( + "fitem-grouptypedescription" + ).value; + + if (groupTaskDescription === "") { canTaskBeStarted = false; } - // checking if there is some global input with empty value - const globalInputsKeys = Object.keys(groupGlobalInputsRef.current); + const userSpecifiedGlobalInputForm = document.getElementById( + "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; } else { - Object.keys(groupGlobalInputsRef.current).forEach((key) => { - if (groupGlobalInputsRef.current[key].value === "") { - canTaskBeStarted = false; - return; - } + selectInputsObjectKeys.forEach((key) => { + globalInputs.push({ + parameterName: key, + value: groupTasksContext.selectInputs[key].value, + data: groupTasksContext.selectInputs[key].data, + }); }); } @@ -112,15 +166,14 @@ export default function GroupTypeSelectionModal({ category: categoryGroup.category, id: currentSelectedModalGroupType, groupName: groupName, - description: groupTypeDescriptionRef.current, + description: groupTaskDescription, 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 }); - // reset - groupTypeDescriptionRef.current = ""; - groupGlobalInputsRef.current = {}; + // reset select inputs + groupTasksContext.setSelectInputs({}); }; return ( @@ -180,11 +233,7 @@ export default function GroupTypeSelectionModal({ }} required > - - (groupTypeDescriptionRef.current = e.nativeEvent.target.value) - } - /> + )} @@ -193,18 +242,43 @@ export default function GroupTypeSelectionModal({ categoryGroup={categoryGroup} currentSelectedModalGroupType={currentSelectedModalGroupType} notificationApi={notificationApi} - groupGlobalInputsRef={groupGlobalInputsRef} + groupGlobalInputs={groupTasksContext.groupGlobalInputs} + setGroupGlobalInputs={groupTasksContext.setGroupGlobalInputs} /> ); } -function SelectMachineComponent({ t, globalInput, groupGlobalInputsRef }) { +export function SelectMachineComponent({ + t, + notificationApi, + globalInput, + onSelectChange, + disabled, +}) { + const groupTasksContext = useGroupTasksContext(); const [loading, setLoading] = useState(false); const [options, setOptions] = useState([]); const responseData = useRef([]); 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); myFetch("/machines", "POST", globalInput.options).then((data) => { @@ -228,11 +302,17 @@ function SelectMachineComponent({ t, globalInput, groupGlobalInputsRef }) { processedOptions[partName].push({ key: index + item.part_detail.Name, label: + // testing if Notes is empty string or if displayName is undefined parsedNotes === "" ? t("groupTasks.groupTypeSelectionModal.noNotesSpecified") + : parsedNotes.displayName === undefined + ? t( + "groupTasks.groupTypeSelectionModal.noNotesDisplayNameSpecified" + ) : parsedNotes.displayName, 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 (