Skip to content

Commit

Permalink
Fixes recently accessed (#5258) (#5263)
Browse files Browse the repository at this point in the history
(cherry picked from commit 5f45553)

Signed-off-by: Ashwin P Chandran <ashwinpc@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent f6016e0 commit 27f0834
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { TypedUseSelectorHook } from 'react-redux';
import {
RootState,
Store as StoreType,
setIndexPattern as updateIndexPattern,
useTypedDispatch,
useTypedSelector,
Expand All @@ -21,4 +20,4 @@ export interface DiscoverRootState extends RootState {

export const useSelector: TypedUseSelectorHook<DiscoverRootState> = useTypedSelector;
export const useDispatch = useTypedDispatch;
export { StoreType, updateIndexPattern };
export { updateIndexPattern };
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand All @@ -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<IndexPattern | undefined>(undefined);
const { data, toastNotifications, uiSettings: config } = services;
const { data, toastNotifications, uiSettings: config, store } = services;

useEffect(() => {
let isMounted = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export const useSearch = (services: DiscoverViewServices) => {
const initalSearchComplete = useRef(false);
const [savedSearch, setSavedSearch] = useState<SavedSearch | undefined>(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;
Expand Down Expand Up @@ -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 () => {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`;
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/plugins/discover/public/saved_searches/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ import { ISearchSource } from '../../../data/public';

export type SortOrder = [string, 'asc' | 'desc'];
export interface SavedSearch
extends Pick<SavedObject, 'id' | 'title' | 'copyOnSave' | 'destroy' | 'lastSavedTitle' | 'save'> {
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[];
Expand Down

0 comments on commit 27f0834

Please sign in to comment.