Skip to content

Commit 75d25c0

Browse files
authored
filter label design fix (#92)
1 parent 4bcfeda commit 75d25c0

File tree

2 files changed

+59
-8
lines changed

2 files changed

+59
-8
lines changed

public/app/features/dashboard/components/SubMenu/SubMenuItems.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useEffect, useState } from 'react';
22

33
import { selectors } from '@grafana/e2e-selectors';
4+
import { useSelector } from 'app/types';
45

56
import { PickerRenderer } from '../../../variables/pickers/PickerRenderer';
67
import { VariableHide, VariableModel } from '../../../variables/types';
@@ -13,6 +14,8 @@ interface Props {
1314
export const SubMenuItems = ({ variables, readOnly }: Props) => {
1415
const [visibleVariables, setVisibleVariables] = useState<VariableModel[]>([]);
1516

17+
const hiddenVariables = useSelector((state) => state.fnGlobalState.hiddenVariables);
18+
1619
useEffect(() => {
1720
setVisibleVariables(variables.filter((state) => state.hide !== VariableHide.hideVariable));
1821
}, [variables]);
@@ -24,6 +27,10 @@ export const SubMenuItems = ({ variables, readOnly }: Props) => {
2427
return (
2528
<>
2629
{visibleVariables.map((variable) => {
30+
if (hiddenVariables?.includes(variable.id)) {
31+
return null;
32+
}
33+
2734
return (
2835
<div
2936
key={variable.id}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
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';
25

36
import { selectors } from '@grafana/e2e-selectors';
47
import { Tooltip } from '@grafana/ui';
8+
import { FnGlobalState } from 'app/core/reducers/fn-slice';
9+
import type { StoreState } from 'app/types';
510

611
import { variableAdapters } from '../adapters';
7-
import { VARIABLE_PREFIX } from '../constants';
812
import { VariableHide, VariableModel } from '../types';
913

1014
interface Props {
1115
variable: VariableModel;
1216
readOnly?: boolean;
1317
}
1418

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) => {
1631
const PickerToRender = useMemo(() => variableAdapters.get(props.variable.type).picker, [props.variable]);
1732

1833
if (!props.variable) {
@@ -23,41 +38,70 @@ export const PickerRenderer = (props: Props) => {
2338
<div className="gf-form">
2439
<PickerLabel variable={props.variable} />
2540
{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>
2744
)}
2845
</div>
2946
);
3047
};
3148

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+
3260
function PickerLabel({ variable }: PropsWithChildren<Props>): ReactElement | null {
3361
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+
);
3476

3577
if (variable.hide !== VariableHide.dontHide) {
3678
return null;
3779
}
80+
const fnLabelOrName = FNDashboard ? labelOrName.replace('druid_adhoc_filters', 'ad-hoc') : labelOrName;
3881

39-
const elementId = VARIABLE_PREFIX + variable.id;
82+
const elementId = `var-${variable.id}`;
4083
if (variable.description) {
4184
return (
4285
<Tooltip content={variable.description} placement={'bottom'}>
4386
<label
4487
className="gf-form-label gf-form-label--variable"
88+
style={fnLabelStyle}
4589
data-testid={selectors.pages.Dashboard.SubMenu.submenuItemLabels(labelOrName)}
4690
htmlFor={elementId}
4791
>
48-
{labelOrName}
92+
{fnLabelOrName}
4993
</label>
5094
</Tooltip>
5195
);
5296
}
53-
5497
return (
5598
<label
5699
className="gf-form-label gf-form-label--variable"
100+
style={fnLabelStyle}
57101
data-testid={selectors.pages.Dashboard.SubMenu.submenuItemLabels(labelOrName)}
58102
htmlFor={elementId}
59103
>
60-
{labelOrName}
104+
{fnLabelOrName}
61105
</label>
62106
);
63107
}

0 commit comments

Comments
 (0)