From 962d6505a6e40187d8c5cdc85d4cc808905983b9 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Thu, 16 Jan 2025 10:53:31 +0100 Subject: [PATCH] fix: type --- .../hooks/useClientDataElements.js | 43 ++++++++++--------- .../Stage/StageDetail/hooks/useEventList.js | 1 - 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/hooks/useClientDataElements.js b/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/hooks/useClientDataElements.js index 62d68a8d3b..a375bdd296 100644 --- a/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/hooks/useClientDataElements.js +++ b/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/hooks/useClientDataElements.js @@ -3,27 +3,30 @@ import { useMemo } from 'react'; import { convertValue } from 'capture-core/converters/serverToClient'; import type { StageDataElement, StageDataElementClient } from '../../../../types/common.types'; -const convertToClientDataElement = (dataElement: StageDataElement): StageDataElementClient => { - const { options, type, ...rest } = dataElement; - - const convertedOptions = options - ? Object.entries(options).map(([key, value]) => ({ - value: convertValue(key, type), - text: value, - })) - : []; - - return { - ...rest, - type, - options: convertedOptions, - }; -}; - export const useClientDataElements = (dataElements: Array) => - useMemo < Array>(() => { - if (!dataElements) { + useMemo(() => { + if (!dataElements || !Array.isArray(dataElements)) { return []; } - return dataElements.map(convertToClientDataElement); + + return dataElements.map ( + (dataElement: StageDataElement) => { + const { + options, + type, + ...rest + } = dataElement; + + const convertedOptions = options + ? Object.entries(options).map(([key, value]) => ({ + value: convertValue(key, type), + text: value, + })) : undefined; + + return { + ...rest, + type, + options: convertedOptions, + }; + }); }, [dataElements]); diff --git a/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/hooks/useEventList.js b/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/hooks/useEventList.js index 3f5a0e76e0..4b67933873 100644 --- a/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/hooks/useEventList.js +++ b/src/core_modules/capture-core/components/WidgetStagesAndEvents/Stages/Stage/StageDetail/hooks/useEventList.js @@ -166,7 +166,6 @@ const formatRowForView = (row: Object, dataElements: Array