Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover] Fixes recently accessed #5258

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
});
this.showInRecentlyAccessed = true;
this.id = id;
this.getFullPath = () => `/app/discover#/view/${String(id)}`;
this.getFullPath = () => `/app/discover#/view/${String(this.id)}`;

Check warning on line 83 in src/plugins/discover/public/saved_searches/_saved_search.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/saved_searches/_saved_search.ts#L83

Added line #L83 was not covered by tests
}
}

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
Loading