BrowseDashboards: Update results when starred param changes (#89944)

* BrowseDashboards: Trigger update results when starred param changes

* Use LocationService

* Use locationService directly
This commit is contained in:
Alex Khomenko 2024-07-02 17:37:40 +03:00 committed by GitHub
parent e568b86ac0
commit 0500b596db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -3,7 +3,7 @@ import { memo, useEffect, useMemo } from 'react';
import AutoSizer from 'react-virtualized-auto-sizer';
import { GrafanaTheme2 } from '@grafana/data';
import { reportInteraction } from '@grafana/runtime';
import { locationService, reportInteraction } from '@grafana/runtime';
import { FilterInput, useStyles2 } from '@grafana/ui';
import { Page } from 'app/core/components/Page/Page';
import { GrafanaRouteComponentProps } from 'app/core/navigation/types';
@ -39,6 +39,7 @@ const BrowseDashboardsPage = memo(({ match }: Props) => {
const styles = useStyles2(getStyles);
const [searchState, stateManager] = useSearchStateManager();
const isSearching = stateManager.hasSearchFilters();
const search = locationService.getSearch();
useEffect(() => {
stateManager.initStateFromUrl(folderUID);
@ -52,6 +53,11 @@ const BrowseDashboardsPage = memo(({ match }: Props) => {
);
}, [dispatch, folderUID, stateManager]);
// Trigger search when "starred" query param changes
useEffect(() => {
stateManager.onSetStarred(search.has('starred'));
}, [search, stateManager]);
useEffect(() => {
// Clear the search results when we leave SearchView to prevent old results flashing
// when starting a new search

View File

@ -161,6 +161,12 @@ export class SearchStateManager extends StateManagerBase<SearchState> {
this.setStateAndDoSearch({ starred: false });
};
onSetStarred = (starred: boolean) => {
if (starred !== this.state.starred) {
this.setStateAndDoSearch({ starred });
}
};
onSortChange = (sort: string | undefined) => {
if (sort) {
localStorage.setItem(SEARCH_SELECTED_SORT, sort);