Commit b9a40fc3 by Alex Khomenko Committed by GitHub

Search: Fix expanded folder icon (#23903)

parent 3bd9e1dd
import React, { FC, useCallback } from 'react';
import { css, cx } from 'emotion';
import { GrafanaTheme } from '@grafana/data';
import { Icon, IconButton, IconName, stylesFactory, useTheme } from '@grafana/ui';
import { Icon, IconButton, stylesFactory, useTheme } from '@grafana/ui';
import { DashboardSection, OnToggleChecked } from '../types';
import { SearchCheckbox } from './SearchCheckbox';
import { getSectionIcon } from '../utils';
interface SectionHeaderProps {
editable?: boolean;
......@@ -41,7 +42,7 @@ export const SectionHeader: FC<SectionHeaderProps> = ({
<SearchCheckbox editable={editable} checked={section.checked} onClick={onSectionChecked} />
<div className={styles.icon}>
<Icon name={section.icon as IconName} />
<Icon name={getSectionIcon(section)} />
</div>
<span className={styles.text}>{section.title}</span>
......
import { parse, SearchParserResult } from 'search-query-parser';
import { IconName } from '@grafana/ui';
import { DashboardQuery, DashboardSection, DashboardSectionItem, SearchAction, UidsToDelete } from './types';
import { NO_ID_SECTIONS } from './constants';
import { getDashboardSrv } from '../dashboard/services/DashboardSrv';
......@@ -194,9 +195,25 @@ export const getParsedQuery = (query: DashboardQuery, queryParsing = false) => {
return { ...parsedQuery, query: parseQuery(query.query).text as string, folderIds };
};
/**
* Check if search query has filters enabled. Excludes folderId
* @param query
*/
export const hasFilters = (query: DashboardQuery) => {
if (!query) {
return false;
}
return Boolean(query.query || query.tag?.length > 0 || query.starred || query.sort);
};
/**
* Get section icon depending on expanded state. Currently works for folder icons only
* @param section
*/
export const getSectionIcon = (section: DashboardSection): IconName => {
if (!hasId(section.title)) {
return section.icon as IconName;
}
return section.expanded ? 'folder-open' : 'folder';
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment