From 0142d81fd49ac47f4a7d0d0f1421e22fa5962a03 Mon Sep 17 00:00:00 2001 From: ananzh Date: Tue, 3 Oct 2023 20:12:13 +0000 Subject: [PATCH] fix PR comments Signed-off-by: ananzh --- .../view_components/canvas/discover_table.tsx | 4 +--- .../view_components/context/index.tsx | 12 ++++-------- .../utils/use_index_pattern.ts | 19 +++++++++---------- .../view_components/utils/use_search.ts | 6 +++--- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/plugins/discover/public/application/view_components/canvas/discover_table.tsx b/src/plugins/discover/public/application/view_components/canvas/discover_table.tsx index c2545ed74445..e57a0b7c7668 100644 --- a/src/plugins/discover/public/application/view_components/canvas/discover_table.tsx +++ b/src/plugins/discover/public/application/view_components/canvas/discover_table.tsx @@ -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({ status: data$.getValue().status, rows: [], @@ -72,7 +71,6 @@ export const DiscoverTable = ({ history }: Props) => { ); const { rows } = fetchState || {}; - const { savedSearch } = useSearch(services, store); useEffect(() => { const subscription = data$.subscribe((next) => { diff --git a/src/plugins/discover/public/application/view_components/context/index.tsx b/src/plugins/discover/public/application/view_components/context/index.tsx index b6e05f86b6c6..7052ed2887f9 100644 --- a/src/plugins/discover/public/application/view_components/context/index.tsx +++ b/src/plugins/discover/public/application/view_components/context/index.tsx @@ -5,7 +5,6 @@ import React, { useEffect } from 'react'; import { DataExplorerServices, ViewProps } from '../../../../../data_explorer/public'; -import { DiscoverViewServices } from '../../../build_services'; import { OpenSearchDashboardsContextProvider, useOpenSearchDashboards, @@ -20,13 +19,10 @@ const SearchContext = React.createContext({} as SearchContex export default function DiscoverContext({ children }: React.PropsWithChildren) { const { services: deServices } = useOpenSearchDashboards(); const services = getServices(); - const searchParams = useSearch( - { - ...deServices, - ...services, - }, - store - ); + const searchParams = useSearch({ + ...deServices, + ...services, + }); const { osdUrlStateStorage } = deServices; 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 2be00368bd85..10a795abac37 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 @@ -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) => { @@ -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, }); 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 69b74698c340..d8c25e1a98e7 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 @@ -25,7 +25,7 @@ import { Chart, } from '../../components/chart/utils'; import { SavedSearch } from '../../../saved_searches'; -import { useSelector, StoreType } from '../../utils/state_management'; +import { useSelector } from '../../utils/state_management'; import { getRequestInspectorStats, getResponseInspectorStats, @@ -66,12 +66,12 @@ export type RefetchSubject = Subject; * return () => subscription.unsubscribe(); * }, [data$]); */ -export const useSearch = (services: DiscoverViewServices, store: StoreType) => { +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 } = services; const timefilter = data.query.timefilter.timefilter; const fetchStateRef = useRef<{ abortController: AbortController | undefined;