diff --git a/src/plugins/discover/public/application/utils/state_management/index.ts b/src/plugins/discover/public/application/utils/state_management/index.ts index 9e0d5bc64ff..989b2662f0d 100644 --- a/src/plugins/discover/public/application/utils/state_management/index.ts +++ b/src/plugins/discover/public/application/utils/state_management/index.ts @@ -6,7 +6,6 @@ import { TypedUseSelectorHook } from 'react-redux'; import { RootState, - Store as StoreType, setIndexPattern as updateIndexPattern, useTypedDispatch, useTypedSelector, @@ -21,4 +20,4 @@ export interface DiscoverRootState extends RootState { export const useSelector: TypedUseSelectorHook = useTypedSelector; export const useDispatch = useTypedDispatch; -export { StoreType, updateIndexPattern }; +export { updateIndexPattern }; diff --git a/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts b/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts index 10a795abac3..e8a81234278 100644 --- a/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts +++ b/src/plugins/discover/public/application/view_components/utils/use_index_pattern.ts @@ -6,8 +6,8 @@ import { useEffect, useState } from 'react'; import { i18n } from '@osd/i18n'; import { IndexPattern } from '../../../../../data/public'; -import { useSelector, updateIndexPattern, StoreType } from '../../utils/state_management'; -import { DiscoverServices } from '../../../build_services'; +import { useSelector, updateIndexPattern } from '../../utils/state_management'; +import { DiscoverViewServices } from '../../../build_services'; import { getIndexPatternId } from '../../helpers/get_index_pattern_id'; /** @@ -24,10 +24,10 @@ import { getIndexPatternId } from '../../helpers/get_index_pattern_id'; * @param store - The redux store in data_explorer to dispatch actions. * @returns - The fetched index pattern. */ -export const useIndexPattern = (services: DiscoverServices, store: StoreType) => { +export const useIndexPattern = (services: DiscoverViewServices) => { const indexPatternIdFromState = useSelector((state) => state.metadata.indexPattern); const [indexPattern, setIndexPattern] = useState(undefined); - const { data, toastNotifications, uiSettings: config } = services; + const { data, toastNotifications, uiSettings: config, store } = services; useEffect(() => { let isMounted = true; diff --git a/src/plugins/discover/public/application/view_components/utils/use_search.ts b/src/plugins/discover/public/application/view_components/utils/use_search.ts index d8c25e1a98e..7e284ef6f44 100644 --- a/src/plugins/discover/public/application/view_components/utils/use_search.ts +++ b/src/plugins/discover/public/application/view_components/utils/use_search.ts @@ -70,8 +70,8 @@ export const useSearch = (services: DiscoverViewServices) => { const initalSearchComplete = useRef(false); const [savedSearch, setSavedSearch] = useState(undefined); const { savedSearch: savedSearchId, sort, interval } = useSelector((state) => state.discover); - const { data, filterManager, getSavedSearchById, core, toastNotifications, store } = services; - const indexPattern = useIndexPattern(services, store); + const { data, filterManager, getSavedSearchById, core, toastNotifications, chrome } = services; + const indexPattern = useIndexPattern(services); const timefilter = data.query.timefilter.timefilter; const fetchStateRef = useRef<{ abortController: AbortController | undefined; @@ -284,6 +284,14 @@ export const useSearch = (services: DiscoverViewServices) => { filterManager.setAppFilters(actualFilters); data.query.queryString.setQuery(query); + + if (savedSearchInstance?.id) { + chrome.recentlyAccessed.add( + savedSearchInstance.getFullPath(), + savedSearchInstance.title, + savedSearchInstance.id + ); + } })(); return () => {}; diff --git a/src/plugins/discover/public/saved_searches/_saved_search.ts b/src/plugins/discover/public/saved_searches/_saved_search.ts index 9b43e3a8920..835055c6560 100644 --- a/src/plugins/discover/public/saved_searches/_saved_search.ts +++ b/src/plugins/discover/public/saved_searches/_saved_search.ts @@ -80,7 +80,7 @@ export function createSavedSearchClass(services: SavedObjectOpenSearchDashboards }); this.showInRecentlyAccessed = true; this.id = id; - this.getFullPath = () => `/app/discover#/view/${String(id)}`; + this.getFullPath = () => `/app/discover#/view/${String(this.id)}`; } } diff --git a/src/plugins/discover/public/saved_searches/types.ts b/src/plugins/discover/public/saved_searches/types.ts index 112d7d998c9..f67df00a900 100644 --- a/src/plugins/discover/public/saved_searches/types.ts +++ b/src/plugins/discover/public/saved_searches/types.ts @@ -33,7 +33,10 @@ import { ISearchSource } from '../../../data/public'; export type SortOrder = [string, 'asc' | 'desc']; export interface SavedSearch - extends Pick { + extends Pick< + SavedObject, + 'id' | 'title' | 'copyOnSave' | 'destroy' | 'lastSavedTitle' | 'save' | 'getFullPath' + > { searchSource: ISearchSource; // This is optional in SavedObject, but required for SavedSearch description?: string; columns: string[];