From b2c4d5fd33499384319de23a66a08b99fc8f913b Mon Sep 17 00:00:00 2001 From: NestorEncinas Date: Tue, 17 Dec 2024 12:08:01 +0100 Subject: [PATCH] fix: validate custom date filter config granularities risk: low JIRA: LX-706 --- .../DateFilterConfigurationConverter.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libs/sdk-backend-tiger/src/convertors/fromBackend/DateFilterConfigurationConverter.ts b/libs/sdk-backend-tiger/src/convertors/fromBackend/DateFilterConfigurationConverter.ts index 3f8f973b8b3..b167584b795 100644 --- a/libs/sdk-backend-tiger/src/convertors/fromBackend/DateFilterConfigurationConverter.ts +++ b/libs/sdk-backend-tiger/src/convertors/fromBackend/DateFilterConfigurationConverter.ts @@ -12,6 +12,14 @@ import { idRef, } from "@gooddata/sdk-model"; +const dateFilterGranularity: DateFilterGranularity[] = [ + "GDC.time.date", + "GDC.time.week_us", + "GDC.time.month", + "GDC.time.quarter", + "GDC.time.year", +]; + export const DefaultDateFilterConfig: IDateFilterConfig = { ref: idRef("defaultDateFilterProjectConfig"), selectedOption: "THIS_MONTH", @@ -310,9 +318,18 @@ const convertAbsoluteForm = (absoluteForm: IDateFilterBase): IAbsoluteDateFilter const convertRelativeForm = (relativeForm: IDateFilterRelativeForm): IRelativeDateFilterForm => { const { granularities: availableGranularities, ...other } = relativeForm; + + if (!availableGranularities) { + return DefaultDateFilterConfig.relativeForm!; + } + + const validGranularities: DateFilterGranularity[] = availableGranularities.filter( + (availableGranularity) => dateFilterGranularity.includes(availableGranularity), + ); + return { type: "relativeForm", - availableGranularities, + availableGranularities: validGranularities, ...other, }; };