From 5f45553344b70327da5514f10f417c05574aae60 Mon Sep 17 00:00:00 2001 From: Ashwin P Chandran Date: Tue, 10 Oct 2023 11:53:27 -0700 Subject: [PATCH] Fixes recently accessed (#5258) Signed-off-by: Ashwin P Chandran --- .../application/utils/state_management/index.ts | 3 +-- .../view_components/utils/use_index_pattern.ts | 8 ++++---- .../application/view_components/utils/use_search.ts | 12 ++++++++++-- .../discover/public/saved_searches/_saved_search.ts | 2 +- src/plugins/discover/public/saved_searches/types.ts | 5 ++++- 5 files changed, 20 insertions(+), 10 deletions(-) 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 9e0d5bc64ffd..989b2662f0d4 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 10a795abac37..e8a81234278e 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 d8c25e1a98e7..7e284ef6f443 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 9b43e3a89203..835055c65602 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 112d7d998c97..f67df00a900c 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[];