mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Search: Remember sorting preference between visits (#62248)
Search: Remember sort option between uses
This commit is contained in:
parent
4deb10888e
commit
960307e938
@ -11,6 +11,7 @@ export const GENERAL_FOLDER_UID = 'general';
|
|||||||
export const GENERAL_FOLDER_TITLE = 'General';
|
export const GENERAL_FOLDER_TITLE = 'General';
|
||||||
export const SEARCH_PANELS_LOCAL_STORAGE_KEY = 'grafana.search.include.panels';
|
export const SEARCH_PANELS_LOCAL_STORAGE_KEY = 'grafana.search.include.panels';
|
||||||
export const SEARCH_SELECTED_LAYOUT = 'grafana.search.layout';
|
export const SEARCH_SELECTED_LAYOUT = 'grafana.search.layout';
|
||||||
|
export const SEARCH_SELECTED_SORT = 'grafana.search.sort';
|
||||||
export const TYPE_KIND_MAP: { [key: string]: DashboardSearchItemType } = {
|
export const TYPE_KIND_MAP: { [key: string]: DashboardSearchItemType } = {
|
||||||
dashboard: DashboardSearchItemType.DashDB,
|
dashboard: DashboardSearchItemType.DashDB,
|
||||||
folder: DashboardSearchItemType.DashFolder,
|
folder: DashboardSearchItemType.DashFolder,
|
||||||
|
@ -6,7 +6,7 @@ import { TermCount } from 'app/core/components/TagFilter/TagFilter';
|
|||||||
import { StateManagerBase } from 'app/core/services/StateManagerBase';
|
import { StateManagerBase } from 'app/core/services/StateManagerBase';
|
||||||
import store from 'app/core/store';
|
import store from 'app/core/store';
|
||||||
|
|
||||||
import { SEARCH_PANELS_LOCAL_STORAGE_KEY, SEARCH_SELECTED_LAYOUT } from '../constants';
|
import { SEARCH_PANELS_LOCAL_STORAGE_KEY, SEARCH_SELECTED_LAYOUT, SEARCH_SELECTED_SORT } from '../constants';
|
||||||
import {
|
import {
|
||||||
reportDashboardListViewed,
|
reportDashboardListViewed,
|
||||||
reportSearchFailedQueryInteraction,
|
reportSearchFailedQueryInteraction,
|
||||||
@ -113,6 +113,10 @@ export class SearchStateManager extends StateManagerBase<SearchState> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
onSortChange = (sort: string | undefined) => {
|
onSortChange = (sort: string | undefined) => {
|
||||||
|
if (sort) {
|
||||||
|
localStorage.setItem(SEARCH_SELECTED_SORT, sort);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.state.layout === SearchLayout.Folders) {
|
if (this.state.layout === SearchLayout.Folders) {
|
||||||
this.setStateAndDoSearch({ sort, layout: SearchLayout.List });
|
this.setStateAndDoSearch({ sort, layout: SearchLayout.List });
|
||||||
} else {
|
} else {
|
||||||
@ -260,13 +264,14 @@ export function getSearchStateManager() {
|
|||||||
if (!stateManager) {
|
if (!stateManager) {
|
||||||
const selectedLayout = localStorage.getItem(SEARCH_SELECTED_LAYOUT) as SearchLayout;
|
const selectedLayout = localStorage.getItem(SEARCH_SELECTED_LAYOUT) as SearchLayout;
|
||||||
const layout = selectedLayout ?? initialState.layout;
|
const layout = selectedLayout ?? initialState.layout;
|
||||||
|
const sort = localStorage.getItem(SEARCH_SELECTED_SORT) ?? undefined;
|
||||||
|
|
||||||
let includePanels = store.getBool(SEARCH_PANELS_LOCAL_STORAGE_KEY, true);
|
let includePanels = store.getBool(SEARCH_PANELS_LOCAL_STORAGE_KEY, true);
|
||||||
if (includePanels) {
|
if (includePanels) {
|
||||||
includePanels = false;
|
includePanels = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
stateManager = new SearchStateManager({ ...initialState, layout: layout, includePanels });
|
stateManager = new SearchStateManager({ ...initialState, layout, sort, includePanels });
|
||||||
}
|
}
|
||||||
|
|
||||||
return stateManager;
|
return stateManager;
|
||||||
|
Loading…
Reference in New Issue
Block a user