Skip to content

Show filters icon only when there are some variables to show #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions public/app/features/dashboard/components/SubMenu/SubMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { css } from '@emotion/css';
import FilterListIcon from '@mui/icons-material/FilterList';
import { Box, styled } from '@mui/material';
import React, { FC, PureComponent } from 'react';
import React, { PureComponent } from 'react';
import { connect, MapStateToProps } from 'react-redux';

import { AnnotationQuery, DataQuery, GrafanaTheme2 } from '@grafana/data';
Expand Down Expand Up @@ -63,7 +61,6 @@ class SubMenuUnConnected extends PureComponent<Props> {
return (
<div className={styles.submenu}>
<form aria-label="Template variables" className={styles.formStyles} onSubmit={this.disableSubmitOnEnter}>
<FilterWithIcon />
<SubMenuItems variables={variables} readOnly={readOnlyVariables} />
</form>
<Annotations
Expand Down Expand Up @@ -112,20 +109,3 @@ const getStyles = stylesFactory((theme: GrafanaTheme2) => {
export const SubMenu = withTheme2(connect(mapStateToProps)(SubMenuUnConnected));

SubMenu.displayName = 'SubMenu';

const FilterWithIcon: FC = () => (
<FilterWithIconStyled>
<FilterListIcon sx={{ color: '#3A785E' }} />
FILTERS
</FilterWithIconStyled>
);

const FilterWithIconStyled = styled(Box)({
display: 'flex',
gap: 1,
alignItems: 'center',
color: '#3A785E',
fontWeight: 600,
lineHeight: '160%',
fontSize: 12,
});
32 changes: 25 additions & 7 deletions public/app/features/dashboard/components/SubMenu/SubMenuItems.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { useEffect, useState } from 'react';
import FilterListIcon from '@mui/icons-material/FilterList';
import { Box, styled } from '@mui/material';
import React, { FC, useEffect, useState } from 'react';

import { selectors } from '@grafana/e2e-selectors';
import { useSelector } from 'app/types';
Expand All @@ -17,20 +19,19 @@ export const SubMenuItems = ({ variables, readOnly }: Props) => {
const hiddenVariables = useSelector((state) => state.fnGlobalState.hiddenVariables);

useEffect(() => {
setVisibleVariables(variables.filter((state) => state.hide !== VariableHide.hideVariable));
}, [variables]);
setVisibleVariables(
variables.filter((state) => state.hide !== VariableHide.hideVariable && !hiddenVariables?.includes(state.id))
);
}, [variables, hiddenVariables]);

if (visibleVariables.length === 0) {
return null;
}

return (
<>
<FilterWithIcon />
{visibleVariables.map((variable) => {
if (hiddenVariables?.includes(variable.id)) {
return null;
}

return (
<div
key={variable.id}
Expand All @@ -44,3 +45,20 @@ export const SubMenuItems = ({ variables, readOnly }: Props) => {
</>
);
};

const FilterWithIcon: FC = () => (
<FilterWithIconStyled>
<FilterListIcon sx={{ color: '#3A785E' }} />
FILTERS
</FilterWithIconStyled>
);

const FilterWithIconStyled = styled(Box)({
display: 'flex',
gap: 1,
alignItems: 'center',
color: '#3A785E',
fontWeight: 600,
lineHeight: '160%',
fontSize: 12,
});