7
7
isAllTimeDashboardDateFilter ,
8
8
isAllValuesDashboardAttributeFilter ,
9
9
isDashboardAttributeFilter ,
10
+ isDashboardCommonDateFilter ,
10
11
isDashboardDateFilterWithDimension ,
11
12
serializeObjRef ,
12
13
} from "@gooddata/sdk-model" ;
@@ -31,7 +32,16 @@ import {
31
32
import { useCommonDateFilterTitle } from "./useCommonDateFilterTitle.js" ;
32
33
import { useDateFiltersTitles } from "./useDateFiltersTitles.js" ;
33
34
34
- export function useFiltersNamings ( filtersToDisplay : FilterContextItem [ ] ) {
35
+ export type FilterNaming = {
36
+ type : "attributeFilter" | "dateFilter" ;
37
+ all : boolean ;
38
+ id : string ;
39
+ title : string ;
40
+ subtitle : string ;
41
+ common ?: true ;
42
+ } ;
43
+
44
+ export function useFiltersNamings ( filtersToDisplay : FilterContextItem [ ] ) : ( FilterNaming | undefined ) [ ] {
35
45
const intl = useIntl ( ) ;
36
46
const locale = useDashboardSelector ( selectLocale ) ;
37
47
const settings = useDashboardSelector ( selectSettings ) ;
@@ -95,24 +105,31 @@ export function useFiltersNamings(filtersToDisplay: FilterContextItem[]) {
95
105
) ;
96
106
const subtitle = DateFilterHelpers . getDateFilterTitle ( dateFilterOption , locale , dateFormat ) ;
97
107
98
- if ( isDashboardDateFilterWithDimension ( filter ) ) {
99
- const key = serializeObjRef ( filter . dateFilter . dataSet ! ) ;
108
+ const a = filter ;
109
+ if ( isDashboardDateFilterWithDimension ( a ) ) {
110
+ const key = serializeObjRef ( a . dateFilter . dataSet ! ) ;
100
111
return {
101
112
type : "dateFilter" ,
102
- all : isAllTimeDashboardDateFilter ( filter ) ,
103
- id : uuidv4 ( ) , // used just for React keys
113
+ all : isAllTimeDashboardDateFilter ( a ) ,
114
+ id : a . dateFilter . localIdentifier ?? uuidv4 ( ) ,
104
115
title : allDateFiltersTitlesObj [ key ] ,
105
116
subtitle,
106
117
} ;
107
- } else {
118
+ }
119
+
120
+ const b = filter ;
121
+ if ( isDashboardCommonDateFilter ( b ) ) {
108
122
return {
109
123
type : "dateFilter" ,
110
- all : isAllTimeDashboardDateFilter ( filter ) ,
111
- id : uuidv4 ( ) , // used just for React keys
124
+ common : true ,
125
+ all : isAllTimeDashboardDateFilter ( b ) ,
126
+ id : b . dateFilter . localIdentifier ?? uuidv4 ( ) ,
112
127
title : commonDateFilterTitle || intl . formatMessage ( { id : "dateFilterDropdown.title" } ) ,
113
128
subtitle,
114
129
} ;
115
130
}
131
+
132
+ return undefined ;
116
133
}
117
134
} ) ;
118
135
}
0 commit comments