Search: Remember sorting preference between visits (#62248)

Search: Remember sort option between uses
This commit is contained in:
Josh Hunt 2023-01-27 11:00:28 +00:00 committed by GitHub
parent 4deb10888e
commit 960307e938
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -11,6 +11,7 @@ export const GENERAL_FOLDER_UID = 'general';
export const GENERAL_FOLDER_TITLE = 'General';
export const SEARCH_PANELS_LOCAL_STORAGE_KEY = 'grafana.search.include.panels';
export const SEARCH_SELECTED_LAYOUT = 'grafana.search.layout';
export const SEARCH_SELECTED_SORT = 'grafana.search.sort';
export const TYPE_KIND_MAP: { [key: string]: DashboardSearchItemType } = {
dashboard: DashboardSearchItemType.DashDB,
folder: DashboardSearchItemType.DashFolder,

View File

@ -6,7 +6,7 @@ import { TermCount } from 'app/core/components/TagFilter/TagFilter';
import { StateManagerBase } from 'app/core/services/StateManagerBase';
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 {
reportDashboardListViewed,
reportSearchFailedQueryInteraction,
@ -113,6 +113,10 @@ export class SearchStateManager extends StateManagerBase<SearchState> {
};
onSortChange = (sort: string | undefined) => {
if (sort) {
localStorage.setItem(SEARCH_SELECTED_SORT, sort);
}
if (this.state.layout === SearchLayout.Folders) {
this.setStateAndDoSearch({ sort, layout: SearchLayout.List });
} else {
@ -260,13 +264,14 @@ export function getSearchStateManager() {
if (!stateManager) {
const selectedLayout = localStorage.getItem(SEARCH_SELECTED_LAYOUT) as SearchLayout;
const layout = selectedLayout ?? initialState.layout;
const sort = localStorage.getItem(SEARCH_SELECTED_SORT) ?? undefined;
let includePanels = store.getBool(SEARCH_PANELS_LOCAL_STORAGE_KEY, true);
if (includePanels) {
includePanels = false;
}
stateManager = new SearchStateManager({ ...initialState, layout: layout, includePanels });
stateManager = new SearchStateManager({ ...initialState, layout, sort, includePanels });
}
return stateManager;