Search: Support filtering by tag in folder view (#49221)

This commit is contained in:
kay delaney 2022-05-19 22:16:25 +01:00 committed by GitHub
parent e8b498fe8b
commit 64aedb78ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 8 deletions

View File

@ -29,6 +29,7 @@ interface SectionHeaderProps {
onTagSelected: (tag: string) => void; onTagSelected: (tag: string) => void;
section: DashboardSection; section: DashboardSection;
renderStandaloneBody?: boolean; // render the body on its own renderStandaloneBody?: boolean; // render the body on its own
tags?: string[];
} }
export const FolderSection: FC<SectionHeaderProps> = ({ export const FolderSection: FC<SectionHeaderProps> = ({
@ -37,6 +38,7 @@ export const FolderSection: FC<SectionHeaderProps> = ({
onTagSelected, onTagSelected,
selection, selection,
renderStandaloneBody, renderStandaloneBody,
tags,
}) => { }) => {
const editable = selectionToggle != null; const editable = selectionToggle != null;
const theme = useTheme(); const theme = useTheme();
@ -74,7 +76,7 @@ export const FolderSection: FC<SectionHeaderProps> = ({
folderUid = undefined; folderUid = undefined;
folderTitle = undefined; folderTitle = undefined;
} }
const raw = await getGrafanaSearcher().search(query); const raw = await getGrafanaSearcher().search({ ...query, tags });
const v = raw.view.map( const v = raw.view.map(
(item) => (item) =>
({ ({
@ -91,7 +93,7 @@ export const FolderSection: FC<SectionHeaderProps> = ({
} as DashboardSectionItem) } as DashboardSectionItem)
); );
return v; return v;
}, [sectionExpanded, section]); }, [sectionExpanded, section, tags]);
const onSectionExpand = () => { const onSectionExpand = () => {
setSectionExpanded(!sectionExpanded); setSectionExpanded(!sectionExpanded);

View File

@ -12,11 +12,8 @@ import { SearchResultsProps } from '../components/SearchResultsTable';
import { DashboardSection, FolderSection } from './FolderSection'; import { DashboardSection, FolderSection } from './FolderSection';
export const FolderView = ({ type Props = Pick<SearchResultsProps, 'selection' | 'selectionToggle' | 'onTagSelected'> & { tags?: string[] };
selection, export const FolderView = ({ selection, selectionToggle, onTagSelected, tags }: Props) => {
selectionToggle,
onTagSelected,
}: Pick<SearchResultsProps, 'selection' | 'selectionToggle' | 'onTagSelected'>) => {
const styles = useStyles2(getStyles); const styles = useStyles2(getStyles);
const results = useAsync(async () => { const results = useAsync(async () => {
@ -59,6 +56,7 @@ export const FolderView = ({
selectionToggle={selectionToggle} selectionToggle={selectionToggle}
onTagSelected={onTagSelected} onTagSelected={onTagSelected}
section={section} section={section}
tags={tags}
/> />
)} )}
</div> </div>

View File

@ -131,7 +131,9 @@ export const SearchView = ({ showManage, folderDTO, queryText }: SearchViewProps
/> />
); );
} }
return <FolderView selection={selection} selectionToggle={toggleSelection} onTagSelected={onTagAdd} />; return (
<FolderView selection={selection} selectionToggle={toggleSelection} tags={query.tag} onTagSelected={onTagAdd} />
);
} }
return ( return (