Skip to content

Commit

Permalink
fix PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: ananzh <[email protected]>
  • Loading branch information
ananzh committed Oct 3, 2023
1 parent 88c658e commit 9a6b86c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ export const DiscoverTable = ({ history }: Props) => {
data: {
query: { filterManager },
},
store,
} = services;
const { data$, refetch$, indexPattern } = useDiscoverContext();
const { data$, refetch$, indexPattern, savedSearch } = useDiscoverContext();
const [fetchState, setFetchState] = useState<SearchData>({
status: data$.getValue().status,
rows: [],
Expand Down Expand Up @@ -72,7 +71,6 @@ export const DiscoverTable = ({ history }: Props) => {
);

const { rows } = fetchState || {};
const { savedSearch } = useSearch(services, store);

useEffect(() => {
const subscription = data$.subscribe((next) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import React, { useEffect } from 'react';
import { DataExplorerServices, ViewProps } from '../../../../../data_explorer/public';
import { DiscoverViewServices } from '../../../build_services';
import {
OpenSearchDashboardsContextProvider,
useOpenSearchDashboards,
Expand All @@ -20,13 +19,10 @@ const SearchContext = React.createContext<SearchContextValue>({} as SearchContex
export default function DiscoverContext({ children }: React.PropsWithChildren<ViewProps>) {
const { services: deServices } = useOpenSearchDashboards<DataExplorerServices>();
const services = getServices();
const searchParams = useSearch(
{
...deServices,
...services,
},
store
);
const searchParams = useSearch({
...deServices,
...services,
});

const { osdUrlStateStorage } = deServices;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ export const useIndexPattern = (services: DiscoverServices, store: StoreType) =>
let isMounted = true;

const fetchIndexPatternDetails = (id: string) => {
const indexPatternMissingWarning = i18n.translate(
'discover.valueIsNotConfiguredIndexPatternIDWarningTitle',
{
defaultMessage: '{id} is not a configured index pattern ID',
values: {
id: `"${id}"`,
},
}
);

data.indexPatterns
.get(id)
.then((result) => {
Expand All @@ -52,6 +42,15 @@ export const useIndexPattern = (services: DiscoverServices, store: StoreType) =>
})
.catch(() => {
if (isMounted) {
const indexPatternMissingWarning = i18n.translate(
'discover.valueIsNotConfiguredIndexPatternIDWarningTitle',
{
defaultMessage: '{id} is not a configured index pattern ID',
values: {
id: `"${id}"`,
},
}
);
toastNotifications.addDanger({
title: indexPatternMissingWarning,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ export type RefetchSubject = Subject<SearchRefetch>;
* return () => subscription.unsubscribe();
* }, [data$]);
*/
export const useSearch = (services: DiscoverViewServices, store: StoreType) => {
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 } = services;
const timefilter = data.query.timefilter.timefilter;
const fetchStateRef = useRef<{
abortController: AbortController | undefined;
Expand Down

0 comments on commit 9a6b86c

Please sign in to comment.