grafana/public/app/features/search/hooks/useSearchLayout.ts
Alex Khomenko fb8a555f19
Search/virtualize list (#23710)
* Search: Add FixedSizeList for result items

* Search: Move SectionHeader to a separate file

* Search: Add useListHeight hook

* Search: Fix horizontal scrollbar

* Search: Remove custom scrollbar

* Search: Do not fetch dashboard folder on route change

* Search: Update tests

* Search: Remove extra checkbox renders

* Search: Move wrapper ref outside search results

* Search: Fix param type

* Search: Fix merge conflicts

* Search: Virtualize dashboard list

* Search: Update layout

* Search: Pass wrapper to search results

* Search: Update dashboard redirect

* Search: Remove unused css

* Search: Revert config

* Search: Use AutoSizer

* Search: Remove redundant appEvents call

* Search: Use List layout in folder view
2020-04-24 11:08:06 +03:00

21 lines
641 B
TypeScript

import { useEffect, useState } from 'react';
import { DashboardQuery, SearchLayout } from '../types';
export const layoutOptions = [
{ label: 'Folders', value: SearchLayout.Folders, icon: 'folder' },
{ label: 'List', value: SearchLayout.List, icon: 'list-ul' },
];
export const useSearchLayout = (query: DashboardQuery, defaultLayout = SearchLayout.Folders) => {
const [layout, setLayout] = useState<string>(defaultLayout);
useEffect(() => {
if (query.sort) {
const list = layoutOptions.find(opt => opt.value === SearchLayout.List);
setLayout(list!.value);
}
}, [query]);
return { layout, setLayout };
};