From fce8ffdfa5ccd38d9c04e1e63772aba6ffec1ab9 Mon Sep 17 00:00:00 2001 From: Arnei Date: Thu, 7 Nov 2024 11:09:24 +0100 Subject: [PATCH 1/3] Set capture agent inputs to true per default When scheduling an event, ensures that all inputs for the capture agent are initially selected. Also fixes a potential source of bugs by cleaning up the selected inputs everytime the capture is changed. --- .../events/partials/ModalTabsAndPages/NewSourcePage.tsx | 8 ++++++++ src/configs/modalConfig.ts | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx b/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx index 6a1e3aa5c3..43a498f36f 100644 --- a/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx +++ b/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx @@ -740,6 +740,14 @@ const Schedule = { if (element) { + // Set inputs depending on location + let inputDevice = inputDevices.find( + ({ name }) => name === element.value + ); + if (inputDevice) { + formik.setFieldValue("deviceInputs", inputDevice.inputs.map(input => input.id)) + } + // Set location formik.setFieldValue("location", element.value) } }} diff --git a/src/configs/modalConfig.ts b/src/configs/modalConfig.ts index 1f155f8352..bdaf219ade 100644 --- a/src/configs/modalConfig.ts +++ b/src/configs/modalConfig.ts @@ -24,6 +24,7 @@ export const initialFormValuesNewEvents: { scheduleEndMinute: string, repeatOn: string[], location: string, + deviceInputs: string[], processingWorkflow: string, configuration: { [key: string]: string }, aclTemplate: string, @@ -42,7 +43,7 @@ export const initialFormValuesNewEvents: { scheduleEndMinute: "", repeatOn: [], location: "", - //deviceInputs: [], + deviceInputs: [], processingWorkflow: "", configuration: {}, aclTemplate: "", From 97a26773e02f34d50c73dccc78763813b13f189f Mon Sep 17 00:00:00 2001 From: Arnei Date: Mon, 11 Nov 2024 12:06:12 +0100 Subject: [PATCH 2/3] Validate capture agent inputs Validation should now take capture agent inputs into account. If inputs are present, at least one will have to be selected. --- .../partials/ModalTabsAndPages/NewSourcePage.tsx | 11 ++++++++--- .../events/partials/wizards/NewEventWizard.tsx | 2 ++ src/utils/validate.ts | 5 +++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx b/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx index 43a498f36f..46dfaff6a9 100644 --- a/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx +++ b/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx @@ -738,17 +738,22 @@ const Schedule = { + handleChange={async (element) => { if (element) { // Set inputs depending on location let inputDevice = inputDevices.find( ({ name }) => name === element.value ); if (inputDevice) { - formik.setFieldValue("deviceInputs", inputDevice.inputs.map(input => input.id)) + if (inputDevice.inputs.length > 0) { + await formik.setFieldValue("locationHasInputs", true) + } else { + await formik.setFieldValue("locationHasInputs", false) + } + await formik.setFieldValue("deviceInputs", inputDevice.inputs.map(input => input.id)) } // Set location - formik.setFieldValue("location", element.value) + await formik.setFieldValue("location", element.value) } }} placeholder={t( diff --git a/src/components/events/partials/wizards/NewEventWizard.tsx b/src/components/events/partials/wizards/NewEventWizard.tsx index 1cd2d4168c..a34fe4e6b8 100644 --- a/src/components/events/partials/wizards/NewEventWizard.tsx +++ b/src/components/events/partials/wizards/NewEventWizard.tsx @@ -308,6 +308,8 @@ const getInitialValues = ( }, ]; + initialValues["locationHasInputs"] = false + return initialValues; }; diff --git a/src/utils/validate.ts b/src/utils/validate.ts index 7d1829bdea..c335176e3f 100644 --- a/src/utils/validate.ts +++ b/src/utils/validate.ts @@ -132,6 +132,11 @@ export const NewEventSchema = [ value === "SCHEDULE_SINGLE" || value === "SCHEDULE_MULTIPLE", then: () => Yup.string().required("Required"), }), + deviceInputs: Yup.mixed().when(["sourceMode", "locationHasInputs"], { + is: (sourceMode: string, locationHasInputs: boolean) => + (sourceMode === "SCHEDULE_SINGLE" || sourceMode === "SCHEDULE_MULTIPLE") && locationHasInputs, + then: () => Yup.array().min(1).required("Required"), + }), }), Yup.object().shape({ processingWorkflow: Yup.string().required("Required"), From 7ab9014def1b2324327e7aa5c3b36d0351c35a6e Mon Sep 17 00:00:00 2001 From: Arnei Date: Tue, 12 Nov 2024 10:57:50 +0100 Subject: [PATCH 3/3] Render capture agent input names more nicely Currently were displaying the whole translation string for a capture agent input if a translation could not be found, which is rather likely. This commit display the input id in case there is no translation, which should be a reasonable value in most cases. (This is also how it worked in the old admin ui) --- .../partials/ModalTabsAndPages/EventDetailsSchedulingTab.tsx | 2 +- .../events/partials/ModalTabsAndPages/NewSourcePage.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/events/partials/ModalTabsAndPages/EventDetailsSchedulingTab.tsx b/src/components/events/partials/ModalTabsAndPages/EventDetailsSchedulingTab.tsx index c992d69bdb..aa136400fb 100644 --- a/src/components/events/partials/ModalTabsAndPages/EventDetailsSchedulingTab.tsx +++ b/src/components/events/partials/ModalTabsAndPages/EventDetailsSchedulingTab.tsx @@ -625,7 +625,7 @@ const EventDetailsSchedulingTab = ({ tabIndex={8 + key} value={inputMethod.id} /> - {t(inputMethod.value)} + {t(inputMethod.value, inputMethod.id)} ) ) diff --git a/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx b/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx index 46dfaff6a9..3705384d43 100644 --- a/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx +++ b/src/components/events/partials/ModalTabsAndPages/NewSourcePage.tsx @@ -420,7 +420,7 @@ const Schedule = - {t(input.value)} + {t(input.value, input.id)} )); }