From a0a0f557aec61c526843804707697f7c21b0f019 Mon Sep 17 00:00:00 2001 From: Chukwudumebi Onwuli <37223065+deeonwuli@users.noreply.github.com> Date: Fri, 8 Nov 2024 08:41:04 +0100 Subject: [PATCH] feat: persist eventTrackerType data on form reload --- src/webapp/pages/form-page/useForm.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/webapp/pages/form-page/useForm.ts b/src/webapp/pages/form-page/useForm.ts index f5aad7b1..9d4a69ac 100644 --- a/src/webapp/pages/form-page/useForm.ts +++ b/src/webapp/pages/form-page/useForm.ts @@ -23,6 +23,7 @@ import { import { useExistingEventTrackerTypes } from "../../contexts/existing-event-tracker-types-context"; import { useCheckWritePermission } from "../../hooks/useHasCurrentUserCaptureAccess"; import { useSnackbar } from "@eyeseetea/d2-ui-components"; +import { usePerformanceOverview } from "../dashboard/usePerformanceOverview"; export type GlobalMessage = { text: string; @@ -67,9 +68,18 @@ export function useForm(formType: FormType, id?: Id): State { const [isLoading, setIsLoading] = useState(false); const currentEventTracker = getCurrentEventTracker(); const { existingEventTrackerTypes } = useExistingEventTrackerTypes(); + const { dataPerformanceOverview } = usePerformanceOverview(); useCheckWritePermission(formType); const snackbar = useSnackbar(); + const allDataPerformanceEvents = dataPerformanceOverview?.map( + event => event.hazardType || event.suspectedDisease + ); + const existingEventTrackers = + existingEventTrackerTypes.length === 0 + ? allDataPerformanceEvents + : existingEventTrackerTypes; + useEffect(() => { compositionRoot.getConfigurableForm .execute(formType, currentEventTracker, configurations, id) @@ -79,7 +89,7 @@ export function useForm(formType: FormType, id?: Id): State { setFormLabels(formData.labels); setFormState({ kind: "loaded", - data: mapEntityToFormState(formData, !!id, existingEventTrackerTypes), + data: mapEntityToFormState(formData, !!id, existingEventTrackers), }); }, error => { @@ -99,7 +109,7 @@ export function useForm(formType: FormType, id?: Id): State { id, currentEventTracker, configurations, - existingEventTrackerTypes, + existingEventTrackers, snackbar, goTo, ]);