1
- import React , { PropsWithChildren , ReactElement , useMemo } from 'react' ;
1
+ import { css } from '@emotion/css' ;
2
+ import React , { CSSProperties , FunctionComponent , PropsWithChildren , ReactElement , useMemo } from 'react' ;
3
+ // eslint-disable-next-line no-restricted-imports
4
+ import { useSelector } from 'react-redux' ;
2
5
3
6
import { selectors } from '@grafana/e2e-selectors' ;
4
7
import { Tooltip } from '@grafana/ui' ;
8
+ import { FnGlobalState } from 'app/core/reducers/fn-slice' ;
9
+ import type { StoreState } from 'app/types' ;
5
10
6
11
import { variableAdapters } from '../adapters' ;
7
- import { VARIABLE_PREFIX } from '../constants' ;
8
12
import { VariableHide , VariableModel } from '../types' ;
9
13
10
14
interface Props {
11
15
variable : VariableModel ;
12
16
readOnly ?: boolean ;
13
17
}
14
18
15
- export const PickerRenderer = ( props : Props ) => {
19
+ const renderWrapperStyle = css `
20
+ & button ,
21
+ & span ,
22
+ & label ,
23
+ & input {
24
+ height : 24px ;
25
+ font-size : 12px ;
26
+ line-height : 24px ;
27
+ }
28
+ ` ;
29
+
30
+ export const PickerRenderer : FunctionComponent < Props > = ( props ) => {
16
31
const PickerToRender = useMemo ( ( ) => variableAdapters . get ( props . variable . type ) . picker , [ props . variable ] ) ;
17
32
18
33
if ( ! props . variable ) {
@@ -23,41 +38,70 @@ export const PickerRenderer = (props: Props) => {
23
38
< div className = "gf-form" >
24
39
< PickerLabel variable = { props . variable } />
25
40
{ props . variable . hide !== VariableHide . hideVariable && PickerToRender && (
26
- < PickerToRender variable = { props . variable } readOnly = { props . readOnly ?? false } />
41
+ < div className = { renderWrapperStyle } >
42
+ < PickerToRender variable = { props . variable } readOnly = { props . readOnly ?? false } />
43
+ </ div >
27
44
) }
28
45
</ div >
29
46
) ;
30
47
} ;
31
48
49
+ const COMMON_PICKER_LABEL_STYLE : CSSProperties = {
50
+ borderRadius : '2px' ,
51
+ border : 'none' ,
52
+ fontWeight : 400 ,
53
+ fontSize : '12px' ,
54
+ padding : '3px 6px' ,
55
+ letterSpacing : '0.15px' ,
56
+ height : '24px' ,
57
+ marginTop : '2px' ,
58
+ } ;
59
+
32
60
function PickerLabel ( { variable } : PropsWithChildren < Props > ) : ReactElement | null {
33
61
const labelOrName = useMemo ( ( ) => variable . label || variable . name , [ variable ] ) ;
62
+ const { FNDashboard, mode } = useSelector < StoreState , FnGlobalState > ( ( { fnGlobalState } ) => fnGlobalState ) ;
63
+
64
+ const fnLabelStyle = useMemo (
65
+ ( ) => ( {
66
+ ...COMMON_PICKER_LABEL_STYLE ,
67
+ ...( FNDashboard
68
+ ? {
69
+ color : mode === 'light' ? '#2D333E' : '#DBD9D7' ,
70
+ backgroundColor : mode === 'light' ? '#E0E0E0' : '#56524D' ,
71
+ }
72
+ : { } ) ,
73
+ } ) ,
74
+ [ mode , FNDashboard ]
75
+ ) ;
34
76
35
77
if ( variable . hide !== VariableHide . dontHide ) {
36
78
return null ;
37
79
}
80
+ const fnLabelOrName = FNDashboard ? labelOrName . replace ( 'druid_adhoc_filters' , 'ad-hoc' ) : labelOrName ;
38
81
39
- const elementId = VARIABLE_PREFIX + variable . id ;
82
+ const elementId = `var- ${ variable . id } ` ;
40
83
if ( variable . description ) {
41
84
return (
42
85
< Tooltip content = { variable . description } placement = { 'bottom' } >
43
86
< label
44
87
className = "gf-form-label gf-form-label--variable"
88
+ style = { fnLabelStyle }
45
89
data-testid = { selectors . pages . Dashboard . SubMenu . submenuItemLabels ( labelOrName ) }
46
90
htmlFor = { elementId }
47
91
>
48
- { labelOrName }
92
+ { fnLabelOrName }
49
93
</ label >
50
94
</ Tooltip >
51
95
) ;
52
96
}
53
-
54
97
return (
55
98
< label
56
99
className = "gf-form-label gf-form-label--variable"
100
+ style = { fnLabelStyle }
57
101
data-testid = { selectors . pages . Dashboard . SubMenu . submenuItemLabels ( labelOrName ) }
58
102
htmlFor = { elementId }
59
103
>
60
- { labelOrName }
104
+ { fnLabelOrName }
61
105
</ label >
62
106
) ;
63
107
}
0 commit comments