Skip to content

Commit dd8087b

Browse files
authored
Merge pull request #6243 from gooddata/jsc/f1
feat: date filter local identifiers followup
2 parents 0d0e813 + 516f8c4 commit dd8087b

File tree

19 files changed

+732
-412
lines changed

19 files changed

+732
-412
lines changed

libs/sdk-backend-base/api/sdk-backend-base.api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,9 @@ export type ExtractBuilderType<TBuilder> = TBuilder extends IBuilder<infer TItem
780780
export class FactMetadataObjectBuilder<T extends IFactMetadataObject = IFactMetadataObject> extends MetadataObjectBuilder<T> {
781781
}
782782

783+
// @internal
784+
export const generateDateFilterLocalIdentifier: (index: number, dateDatasetRef?: ObjRef) => string;
785+
783786
// @beta
784787
export class GroupableCatalogItemBuilder<T extends IGroupableCatalogItemBase = IGroupableCatalogItemBase> extends Builder<T> implements IGroupableCatalogItemBuilder<T> {
785788
// (undocumented)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// (C) 2025 GoodData Corporation
2+
3+
import { ObjRef, objRefToString } from "@gooddata/sdk-model";
4+
5+
/**
6+
* Date filter local identifier generator.
7+
*
8+
* The identifiers are predictable.
9+
*
10+
* @param index - The index of the date filter in the list of filters.
11+
* @param dateDatasetRef - Optional reference to the date dataset.
12+
* @returns A string representing the generated local identifier.
13+
*
14+
* @internal
15+
*/
16+
export const generateDateFilterLocalIdentifier = (index: number, dateDatasetRef?: ObjRef): string => {
17+
return dateDatasetRef ? `${objRefToString(dateDatasetRef)}_${index}_dateFilter` : `${index}_dateFilter`;
18+
};

libs/sdk-backend-base/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// (C) 2019-2024 GoodData Corporation
1+
// (C) 2019-2025 GoodData Corporation
22
/**
33
* This package provides foundational reusable code useful for building new or decorating existing Analytical Backend implementations.
44
*
@@ -153,3 +153,5 @@ export {
153153

154154
export type { ResultHeaderTransformer } from "./convertors/fromBackend/afm/result.js";
155155
export { transformResultHeaders } from "./convertors/fromBackend/afm/result.js";
156+
157+
export { generateDateFilterLocalIdentifier } from "./generators/dateFilterLocalIdentifier.js";

libs/sdk-backend-tiger/src/utils/filterLocalidentifier.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
// (C) 2025 GoodData Corporation
22

3-
import {
4-
FilterContextItem,
5-
IDashboardDateFilter,
6-
isDashboardDateFilter,
7-
isDashboardDateFilterWithDimension,
8-
objRefToString,
9-
} from "@gooddata/sdk-model";
10-
11-
const generateDateFilterLocalIdentifier = (filter: IDashboardDateFilter, index: number): string => {
12-
if (isDashboardDateFilterWithDimension(filter)) {
13-
const ref = filter.dateFilter.dataSet;
14-
return ref ? `${objRefToString(ref)}_${index}_dateFilter` : `${index}_dateFilter`;
15-
}
16-
17-
return `common_${index}_dateFilter`;
18-
};
3+
import { generateDateFilterLocalIdentifier } from "@gooddata/sdk-backend-base";
4+
import { FilterContextItem, isDashboardDateFilter } from "@gooddata/sdk-model";
195

206
export const addFilterLocalIdentifier = (filter: FilterContextItem, index: number): FilterContextItem => {
217
if (isDashboardDateFilter(filter) && !filter.dateFilter.localIdentifier) {
228
return {
239
...filter,
2410
dateFilter: {
2511
...filter.dateFilter,
26-
localIdentifier: generateDateFilterLocalIdentifier(filter, index),
12+
localIdentifier: generateDateFilterLocalIdentifier(index, filter.dateFilter.dataSet),
2713
},
2814
};
2915
} else {

libs/sdk-model/api/sdk-model.api.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4605,16 +4605,16 @@ export function modifyPreviousPeriodMeasure(measure: IMeasure<IPreviousPeriodMea
46054605
export function modifySimpleMeasure(measure: IMeasure<IMeasureDefinition>, modifications?: MeasureModifications<MeasureBuilder>): IMeasure<IMeasureDefinition>;
46064606

46074607
// @alpha
4608-
export function newAbsoluteDashboardDateFilter(from: DateString, to: DateString, dataSet?: ObjRef): IDashboardDateFilter;
4608+
export function newAbsoluteDashboardDateFilter(from: DateString, to: DateString, dataSet?: ObjRef, localIdentifier?: string): IDashboardDateFilter;
46094609

46104610
// @public
46114611
export function newAbsoluteDateFilter(dateDataSet: ObjRef | Identifier, from: string, to: string, localIdentifier?: string): IAbsoluteDateFilter;
46124612

46134613
// @alpha
4614-
export function newAllTimeDashboardDateFilter(dataSet?: ObjRef): IDashboardDateFilter;
4614+
export function newAllTimeDashboardDateFilter(dataSet?: ObjRef, localIdentifier?: string): IDashboardDateFilter;
46154615

46164616
// @public
4617-
export function newAllTimeFilter(dateDataSet: ObjRef | Identifier): IRelativeDateFilter;
4617+
export function newAllTimeFilter(dateDataSet: ObjRef | Identifier, localIdentifier?: string): IRelativeDateFilter;
46184618

46194619
// @public
46204620
export function newArithmeticMeasure(measuresOrIds: ReadonlyArray<MeasureOrLocalId>, operator: ArithmeticMeasureOperator, modifications?: MeasureModifications<ArithmeticMeasureBuilder>): IMeasure<IArithmeticMeasureDefinition>;
@@ -4686,7 +4686,7 @@ export function newRankingFilter(measureOrRef: IMeasure | ObjRefInScope | string
46864686
export function newRankingFilter(measureOrRef: IMeasure | ObjRefInScope | string, operator: RankingFilterOperator, value: number): IRankingFilter;
46874687

46884688
// @alpha
4689-
export function newRelativeDashboardDateFilter(granularity: DateFilterGranularity, from: number, to: number, dataSet?: ObjRef): IDashboardDateFilter;
4689+
export function newRelativeDashboardDateFilter(granularity: DateFilterGranularity, from: number, to: number, dataSet?: ObjRef, localIdentifier?: string): IDashboardDateFilter;
46904690

46914691
// @public
46924692
export function newRelativeDateFilter(dateDataSet: ObjRef | Identifier, granularity: DateAttributeGranularity, from: number, to: number, localIdentifier?: string): IRelativeDateFilter;

libs/sdk-model/src/dashboard/filterContext.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ export function newRelativeDashboardDateFilter(
263263
from: number,
264264
to: number,
265265
dataSet?: ObjRef,
266+
localIdentifier?: string,
266267
): IDashboardDateFilter {
267268
return {
268269
dateFilter: {
@@ -271,6 +272,7 @@ export function newRelativeDashboardDateFilter(
271272
from,
272273
to,
273274
dataSet,
275+
...(localIdentifier ? { localIdentifier } : {}),
274276
},
275277
};
276278
}
@@ -286,6 +288,7 @@ export function newAbsoluteDashboardDateFilter(
286288
from: DateString,
287289
to: DateString,
288290
dataSet?: ObjRef,
291+
localIdentifier?: string,
289292
): IDashboardDateFilter {
290293
return {
291294
dateFilter: {
@@ -294,6 +297,7 @@ export function newAbsoluteDashboardDateFilter(
294297
from,
295298
to,
296299
dataSet,
300+
...(localIdentifier ? { localIdentifier } : {}),
297301
},
298302
};
299303
}
@@ -303,12 +307,16 @@ export function newAbsoluteDashboardDateFilter(
303307
*
304308
* @alpha
305309
*/
306-
export function newAllTimeDashboardDateFilter(dataSet?: ObjRef): IDashboardDateFilter {
310+
export function newAllTimeDashboardDateFilter(
311+
dataSet?: ObjRef,
312+
localIdentifier?: string,
313+
): IDashboardDateFilter {
307314
return {
308315
dateFilter: {
309316
type: "relative",
310317
granularity: "GDC.time.date",
311318
dataSet,
319+
...(localIdentifier ? { localIdentifier } : {}),
312320
},
313321
};
314322
}

libs/sdk-model/src/execution/filter/factory.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,18 @@ export function newRelativeDateFilter(
176176
* @param dateDataSet - ref or identifier of the date data set to filter on
177177
* @public
178178
*/
179-
export function newAllTimeFilter(dateDataSet: ObjRef | Identifier): IRelativeDateFilter {
179+
export function newAllTimeFilter(
180+
dateDataSet: ObjRef | Identifier,
181+
localIdentifier?: string,
182+
): IRelativeDateFilter {
180183
const dataSet = isObjRef(dateDataSet) ? dateDataSet : idRef(dateDataSet);
181184
return {
182185
relativeDateFilter: {
183186
dataSet,
184187
granularity: "ALL_TIME_GRANULARITY",
185188
from: 0,
186189
to: 0,
190+
...(localIdentifier ? { localIdentifier } : {}),
187191
},
188192
};
189193
}

libs/sdk-ui-dashboard/api/sdk-ui-dashboard.api.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ export interface ChangeDateFilterSelection extends IDashboardCommand {
748748
}
749749

750750
// @public
751-
export function changeDateFilterSelection(type: DateFilterType, granularity: DateFilterGranularity, from?: DateString | number, to?: DateString | number, dateFilterOptionLocalId?: string, correlationId?: string, dataSet?: ObjRef, isWorkingSelectionChange?: boolean): ChangeDateFilterSelection;
751+
export function changeDateFilterSelection(type: DateFilterType, granularity: DateFilterGranularity, from?: DateString | number, to?: DateString | number, dateFilterOptionLocalId?: string, correlationId?: string, dataSet?: ObjRef, isWorkingSelectionChange?: boolean, localIdentifier?: string): ChangeDateFilterSelection;
752752

753753
// @alpha (undocumented)
754754
export interface ChangeDrillableItems extends IDashboardCommand {
@@ -1126,7 +1126,7 @@ export interface ChangeSharingPayload {
11261126
export function changeWorkingAttributeFilterSelection(filterLocalId: string, elements: IAttributeElements, selectionType: AttributeFilterSelectionType, correlationId?: string): ChangeAttributeFilterSelection;
11271127

11281128
// @public
1129-
export function clearDateFilterSelection(correlationId?: string, dataSet?: ObjRef, isWorkingSelectionChange?: boolean): ChangeDateFilterSelection;
1129+
export function clearDateFilterSelection(correlationId?: string, dataSet?: ObjRef, isWorkingSelectionChange?: boolean, localIdentifier?: string): ChangeDateFilterSelection;
11301130

11311131
// @alpha
11321132
export function commandFailedEventHandler<TCommand extends IDashboardCommand>(type: TCommand["type"], handler: DashboardEventHandler<DashboardCommandFailed<TCommand>>["handler"]): DashboardEventHandler<DashboardCommandFailed<TCommand>>;
@@ -3333,6 +3333,7 @@ export interface DateFilterSelection {
33333333
readonly from?: DateString | number;
33343334
readonly granularity: DateFilterGranularity;
33353335
readonly isWorkingSelectionChange?: boolean;
3336+
readonly localIdentifier?: string;
33363337
readonly to?: DateString | number;
33373338
readonly type: DateFilterType;
33383339
}

libs/sdk-ui-dashboard/src/model/commandHandlers/filterContext/changeFilterContextSelectionHandler.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// (C) 2021-2024 GoodData Corporation
1+
// (C) 2021-2025 GoodData Corporation
22
import { all, call, put, SagaReturnType, select } from "redux-saga/effects";
33
import { SagaIterator } from "redux-saga";
44
import { DashboardContext } from "../../types/commonTypes.js";
@@ -46,6 +46,7 @@ import {
4646
IDashboardAttributeFilterConfig,
4747
areObjRefsEqual,
4848
ObjRef,
49+
filterLocalIdentifier,
4950
} from "@gooddata/sdk-model";
5051
import { NotSupported } from "@gooddata/sdk-backend-spi";
5152
import {
@@ -70,22 +71,28 @@ function dashboardFilterToFilterContextItem(
7071
displayForm: filterObjRef(filter),
7172
attributeElements: filterAttributeElements(filter),
7273
selectionMode: "multi",
74+
localIdentifier: filterLocalIdentifier(filter),
7375
},
7476
};
7577
} else if (isAbsoluteDateFilter(filter)) {
7678
return newAbsoluteDashboardDateFilter(
7779
filter.absoluteDateFilter.from,
7880
filter.absoluteDateFilter.to,
7981
keepDatasets ? filter.absoluteDateFilter.dataSet : undefined,
82+
filter.absoluteDateFilter.localIdentifier,
8083
);
8184
} else if (isAllTimeDateFilter(filter)) {
82-
return newAllTimeDashboardDateFilter(keepDatasets ? filter.relativeDateFilter.dataSet : undefined);
85+
return newAllTimeDashboardDateFilter(
86+
keepDatasets ? filter.relativeDateFilter.dataSet : undefined,
87+
filter.relativeDateFilter.localIdentifier,
88+
);
8389
} else if (isRelativeDateFilter(filter)) {
8490
return newRelativeDashboardDateFilter(
8591
filter.relativeDateFilter.granularity as DateFilterGranularity,
8692
filter.relativeDateFilter.from,
8793
filter.relativeDateFilter.to,
8894
keepDatasets ? filter.relativeDateFilter.dataSet : undefined,
95+
filter.relativeDateFilter.localIdentifier,
8996
);
9097
}
9198

libs/sdk-ui-dashboard/src/model/commandHandlers/filterContext/dateFilter/changeDateFilterSelectionHandler.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,26 @@ export function* changeDateFilterSelectionHandler(
4747
const enableDashboardFiltersApplyModes: ReturnType<typeof selectEnableDashboardFiltersApplyModes> =
4848
yield select(selectEnableDashboardFiltersApplyModes);
4949
const isWorkingSelectionChange = cmd.payload.isWorkingSelectionChange && enableDashboardFiltersApplyModes;
50+
const localIdentifierObj = cmd.payload.localIdentifier
51+
? { localIdentifier: cmd.payload.localIdentifier }
52+
: {};
5053
yield put(
5154
filterContextActions.upsertDateFilter(
5255
isAllTime
53-
? { type: "allTime", dataSet: cmd.payload.dataSet, isWorkingSelectionChange }
56+
? {
57+
type: "allTime",
58+
dataSet: cmd.payload.dataSet,
59+
isWorkingSelectionChange,
60+
...localIdentifierObj,
61+
}
5462
: {
5563
type: cmd.payload.type,
5664
granularity: cmd.payload.granularity,
5765
from: cmd.payload.from,
5866
to: cmd.payload.to,
5967
dataSet: cmd.payload.dataSet,
6068
isWorkingSelectionChange,
69+
...localIdentifierObj,
6170
},
6271
),
6372
);
@@ -85,19 +94,23 @@ function dateFilterSelectionToDateFilter(dateFilterSelection: DateFilterSelectio
8594
return newAbsoluteDashboardDateFilter(
8695
dateFilterSelection.from.toString(),
8796
dateFilterSelection.to.toString(),
97+
undefined,
98+
dateFilterSelection.localIdentifier,
8899
);
89100
} else if (
90101
dateFilterSelection.type === "relative" &&
91102
dateFilterSelection.granularity === "GDC.time.date" &&
92103
dateFilterSelection.from === undefined &&
93104
dateFilterSelection.to === undefined
94105
) {
95-
return newAllTimeDashboardDateFilter();
106+
return newAllTimeDashboardDateFilter(undefined, dateFilterSelection.localIdentifier);
96107
} else {
97108
return newRelativeDashboardDateFilter(
98109
dateFilterSelection.granularity,
99110
toNumber(dateFilterSelection.from),
100111
toNumber(dateFilterSelection.to),
112+
undefined,
113+
dateFilterSelection.localIdentifier,
101114
);
102115
}
103116
}

0 commit comments

Comments
 (0)