Skip to content

Commit

Permalink
fix: validate custom date filter config granularities
Browse files Browse the repository at this point in the history
risk: low
JIRA: LX-706
  • Loading branch information
NestorEncinas committed Dec 17, 2024
1 parent 15c768f commit b2c4d5f
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
};
};
Expand Down

0 comments on commit b2c4d5f

Please sign in to comment.