From 8c3431a60d8ed8a9480569f06a21358669bb4395 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 9 Sep 2023 11:34:24 +0200 Subject: [PATCH] dynamic machines --- public/locales/de/translation.json | 11 +- public/locales/en/translation.json | 11 +- src/Contexts/GroupTasksContext.js | 5 + src/Handlers/WebSocketMessageHandler.js | 37 +++- .../Overview/GroupTasksViewModal.js | 161 +++++++++++----- .../Overview/GroupTypeSelectionModal.js | 181 ++++++++++++------ src/Pages/GroupTasks/Overview/index.js | 5 + 7 files changed, 290 insertions(+), 121 deletions(-) diff --git a/public/locales/de/translation.json b/public/locales/de/translation.json index ef5a4f2..5b03429 100644 --- a/public/locales/de/translation.json +++ b/public/locales/de/translation.json @@ -59,6 +59,10 @@ "globalInputTypeNotImplemented": { "message": "Typ {{globalInputType}} nicht implementiert", "description": "Wurde festgelegt in: {{globalInputDisplayName}}" + }, + "globalInputOptionsMissing": { + "message": "Optionen für Maschinenauswahl fehlen", + "description": "Wurde festgelegt in {{globalInputParamterName}}" } }, "title": "Wählen Sie einen Gruppentyp", @@ -76,7 +80,8 @@ } }, "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", "groupTasksViewModal": { @@ -85,9 +90,7 @@ "inputsCannotBeEmpty": { "message": "Eingaben können nicht leer sein", "description": "Bitte füllen Sie alle Felder aus" - }, - "groupTaskParameterNotImplemented.message": "Typ {{groupTaskParameterType}} nicht implementiert", - "groupTaskParameterNotImplemented.description": "Wurde festgelegt in: {{groupTaskParameterDisplayName}}" + } }, "startedAt": "Gestartet am", "endedAt": "Beendet am", diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 4d45741..e0ed619 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -59,6 +59,10 @@ "globalInputTypeNotImplemented": { "message": "Type {{globalInputType}} not implemented", "description": "Defined in: {{globalInputDisplayName}}" + }, + "globalInputOptionsMissing": { + "message": "Options for machine select missing", + "description": "Defined in {{globalInputParamterName}}" } }, "title": "Select a Group Type", @@ -76,7 +80,8 @@ } }, "h3": "Fill in the global values", - "noNotesSpecified": "No notes specified" + "noNotesSpecified": "No notes specified", + "noNotesDisplayNameSpecified": "No notes display name specified" }, "tag.global": "Global", "groupTasksViewModal": { @@ -85,9 +90,7 @@ "inputsCannotBeEmpty": { "message": "Inputs cannot be empty", "description": "Please fill in all fields" - }, - "groupTaskParameterNotImplemented.message": "Type {{groupTaskParameterType}} not implemented", - "groupTaskParameterNotImplemented.description": "Defined in: {{groupTaskParameterDisplayName}}" + } }, "startedAt": "Started at", "endedAt": "Ended at", diff --git a/src/Contexts/GroupTasksContext.js b/src/Contexts/GroupTasksContext.js index afeefce..38176c9 100644 --- a/src/Contexts/GroupTasksContext.js +++ b/src/Contexts/GroupTasksContext.js @@ -9,6 +9,7 @@ const preview = { totalPages: 0, previousParamCategory: null, paginationPageRef: null, + selectInputs: {}, }; const GroupTasksContext = createContext(preview); @@ -28,6 +29,8 @@ export function GroupTasksProvider({ children }) { const paginationPageRef = useRef(paginationPage); const [totalPages, setTotalPages] = useState(0); const previousParamCategory = useRef(null); + // this is used for the - (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 ( - (groupGlobalInputsRef.current[globalInput.parameterName] = - { - value: e.nativeEvent.target.value, - }) - } - /> + ); break; @@ -335,10 +412,6 @@ function GroupGlobalInputs({ style={{ width: "100%" }} max={Number.MAX_SAFE_INTEGER} id={globalInput.parameterName} - onInput={(value) => - (groupGlobalInputsRef.current[globalInput.parameterName] = - { value: value }) - } /> ); @@ -350,15 +423,7 @@ function GroupGlobalInputs({ label={getLabel(globalInput.displayName)} required > -