diff --git a/x-pack/legacy/plugins/apm/public/components/app/GlobalHelpExtension/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/GlobalHelpExtension/index.tsx index fb10a65d975bf..57a0e5ad9ddc4 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/GlobalHelpExtension/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/GlobalHelpExtension/index.tsx @@ -10,14 +10,14 @@ import React, { Fragment } from 'react'; import styled from 'styled-components'; import url from 'url'; import { px, units } from '../../../style/variables'; -import { useCore } from '../../../hooks/useCore'; +import { useKibanaCore } from '../../../../../observability/public'; const Container = styled.div` margin: ${px(units.minus)} 0; `; export const GlobalHelpExtension: React.SFC = () => { - const core = useCore(); + const core = useKibanaCore(); return ( diff --git a/x-pack/legacy/plugins/apm/public/components/app/Main/UpdateBreadcrumbs.tsx b/x-pack/legacy/plugins/apm/public/components/app/Main/UpdateBreadcrumbs.tsx index 5eb2626f44872..b94860c8fdd8f 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/Main/UpdateBreadcrumbs.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/Main/UpdateBreadcrumbs.tsx @@ -8,7 +8,7 @@ import { Location } from 'history'; import { last } from 'lodash'; import React from 'react'; import { InternalCoreStart } from 'src/core/public'; -import { useCore } from '../../../hooks/useCore'; +import { useKibanaCore } from '../../../../../observability/public'; import { getAPMHref } from '../../shared/Links/apm/APMLink'; import { Breadcrumb, ProvideBreadcrumbs } from './ProvideBreadcrumbs'; import { routes } from './route_config'; @@ -45,7 +45,7 @@ class UpdateBreadcrumbsComponent extends React.Component { } export function UpdateBreadcrumbs() { - const core = useCore(); + const core = useKibanaCore(); return ( { - const { chrome } = useCore(); + const { chrome } = useKibanaCore(); useEffect(() => { const uiCapabilities = capabilities.get(); diff --git a/x-pack/legacy/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/WatcherFlyout.tsx b/x-pack/legacy/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/WatcherFlyout.tsx index 134934ff8425e..f3497d1235e81 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/WatcherFlyout.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/WatcherFlyout.tsx @@ -32,11 +32,11 @@ import React, { Component } from 'react'; import styled from 'styled-components'; import { toastNotifications } from 'ui/notify'; import { InternalCoreStart } from 'src/core/public'; +import { KibanaCoreContext } from '../../../../../../observability/public'; import { IUrlParams } from '../../../../context/UrlParamsContext/types'; import { KibanaLink } from '../../../shared/Links/KibanaLink'; import { createErrorGroupWatch, Schedule } from './createErrorGroupWatch'; import { ElasticDocsLink } from '../../../shared/Links/ElasticDocsLink'; -import { CoreContext } from '../../../../context/CoreContext'; type ScheduleKey = keyof Schedule; @@ -83,7 +83,8 @@ export class WatcherFlyout extends Component< WatcherFlyoutProps, WatcherFlyoutState > { - static contextType = CoreContext; + static contextType = KibanaCoreContext; + context!: React.ContextType; public state: WatcherFlyoutState = { schedule: 'daily', threshold: 10, @@ -156,7 +157,7 @@ export class WatcherFlyout extends Component< }; public createWatch = () => { - const core: InternalCoreStart = this.context; + const core = this.context; const { serviceName } = this.props.urlParams; if (!serviceName) { @@ -278,7 +279,7 @@ export class WatcherFlyout extends Component< return null; } - const core: InternalCoreStart = this.context; + const core = this.context; const userTimezoneSetting = getUserTimezone(core); const dailyTime = this.state.daily; const inputTime = `${dailyTime}Z`; // Add tz to make into UTC diff --git a/x-pack/legacy/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/index.tsx index 513c58d7a834a..8a5d7ad10f22b 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/index.tsx @@ -13,13 +13,12 @@ import { import { i18n } from '@kbn/i18n'; import { memoize } from 'lodash'; import React, { Fragment } from 'react'; -import { InternalCoreStart } from 'src/core/public'; import { idx } from '@kbn/elastic-idx'; +import { KibanaCoreContext } from '../../../../../../observability/public'; import { IUrlParams } from '../../../../context/UrlParamsContext/types'; import { LicenseContext } from '../../../../context/LicenseContext'; import { MachineLearningFlyout } from './MachineLearningFlyout'; import { WatcherFlyout } from './WatcherFlyout'; -import { CoreContext } from '../../../../context/CoreContext'; interface Props { urlParams: IUrlParams; @@ -31,7 +30,9 @@ interface State { type FlyoutName = null | 'ML' | 'Watcher'; export class ServiceIntegrations extends React.Component { - static contextType = CoreContext; + static contextType = KibanaCoreContext; + context!: React.ContextType; + public state: State = { isPopoverOpen: false, activeFlyout: null }; public getPanelItems = memoize((mlAvailable: boolean | undefined) => { @@ -67,7 +68,7 @@ export class ServiceIntegrations extends React.Component { }; public getWatcherPanelItems = () => { - const core: InternalCoreStart = this.context; + const core = this.context; return [ { diff --git a/x-pack/legacy/plugins/apm/public/components/app/ServiceOverview/__test__/ServiceOverview.test.tsx b/x-pack/legacy/plugins/apm/public/components/app/ServiceOverview/__test__/ServiceOverview.test.tsx index b29428cc555ed..599f6c91e09e0 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/ServiceOverview/__test__/ServiceOverview.test.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/ServiceOverview/__test__/ServiceOverview.test.tsx @@ -11,7 +11,7 @@ import { toastNotifications } from 'ui/notify'; import * as callApmApi from '../../../../services/rest/callApmApi'; import { ServiceOverview } from '..'; import * as urlParamsHooks from '../../../../hooks/useUrlParams'; -import * as coreHooks from '../../../../hooks/useCore'; +import * as kibanaCore from '../../../../../../observability/public/context/kibana_core'; import { InternalCoreStart } from 'src/core/public'; import * as useLocalUIFilters from '../../../../hooks/useLocalUIFilters'; import { FETCH_STATUS } from '../../../../hooks/useFetcher'; @@ -39,7 +39,7 @@ describe('Service Overview -> View', () => { end: 'myEnd' } }); - spyOn(coreHooks, 'useCore').and.returnValue(coreMock); + spyOn(kibanaCore, 'useKibanaCore').and.returnValue(coreMock); jest.spyOn(useLocalUIFilters, 'useLocalUIFilters').mockReturnValue({ filters: [], diff --git a/x-pack/legacy/plugins/apm/public/components/app/ServiceOverview/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/ServiceOverview/index.tsx index 2fb81048a16f4..1e2fc98843d29 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/ServiceOverview/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/ServiceOverview/index.tsx @@ -15,7 +15,7 @@ import { NoServicesMessage } from './NoServicesMessage'; import { ServiceList } from './ServiceList'; import { useUrlParams } from '../../../hooks/useUrlParams'; import { useTrackPageview } from '../../../../../infra/public'; -import { useCore } from '../../../hooks/useCore'; +import { useKibanaCore } from '../../../../../observability/public'; import { PROJECTION } from '../../../../common/projections/typings'; import { LocalUIFilters } from '../../shared/LocalUIFilters'; import { callApmApi } from '../../../services/rest/callApmApi'; @@ -29,7 +29,7 @@ const initalData = { let hasDisplayedToast = false; export function ServiceOverview() { - const core = useCore(); + const core = useKibanaCore(); const { urlParams: { start, end }, uiFilters diff --git a/x-pack/legacy/plugins/apm/public/components/shared/KueryBar/index.tsx b/x-pack/legacy/plugins/apm/public/components/shared/KueryBar/index.tsx index 9fe8be856ece4..bc5d293220158 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/KueryBar/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/KueryBar/index.tsx @@ -27,7 +27,7 @@ import { useUrlParams } from '../../../hooks/useUrlParams'; import { history } from '../../../utils/history'; import { useMatchedRoutes } from '../../../hooks/useMatchedRoutes'; import { RouteName } from '../../app/Main/route_config/route_names'; -import { useCore } from '../../../hooks/useCore'; +import { useKibanaCore } from '../../../../../observability/public'; import { getAPMIndexPattern } from '../../../services/rest/savedObjects'; const Container = styled.div` @@ -86,7 +86,7 @@ function getSuggestions( } export function KueryBar() { - const core = useCore(); + const core = useKibanaCore(); const [state, setState] = useState({ indexPattern: null, suggestions: [], diff --git a/x-pack/legacy/plugins/apm/public/components/shared/Links/DiscoverLinks/DiscoverLink.tsx b/x-pack/legacy/plugins/apm/public/components/shared/Links/DiscoverLinks/DiscoverLink.tsx index 0673ab5e75cc6..17bb7373b6b9f 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/Links/DiscoverLinks/DiscoverLink.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/Links/DiscoverLinks/DiscoverLink.tsx @@ -11,7 +11,7 @@ import rison, { RisonValue } from 'rison-node'; import { useAPMIndexPattern } from '../../../../hooks/useAPMIndexPattern'; import { useLocation } from '../../../../hooks/useLocation'; import { getTimepickerRisonData } from '../rison_helpers'; -import { useCore } from '../../../../hooks/useCore'; +import { useKibanaCore } from '../../../../../../observability/public'; interface Props { query: { @@ -31,7 +31,7 @@ interface Props { } export function DiscoverLink({ query = {}, ...rest }: Props) { - const core = useCore(); + const core = useKibanaCore(); const apmIndexPattern = useAPMIndexPattern(); const location = useLocation(); diff --git a/x-pack/legacy/plugins/apm/public/components/shared/Links/DiscoverLinks/__test__/DiscoverLinks.integration.test.tsx b/x-pack/legacy/plugins/apm/public/components/shared/Links/DiscoverLinks/__test__/DiscoverLinks.integration.test.tsx index 80cecd8ea7f4d..d9ca32f78f4dc 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/Links/DiscoverLinks/__test__/DiscoverLinks.integration.test.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/Links/DiscoverLinks/__test__/DiscoverLinks.integration.test.tsx @@ -14,7 +14,7 @@ import { getRenderedHref } from '../../../../../utils/testHelpers'; import { DiscoverErrorLink } from '../DiscoverErrorLink'; import { DiscoverSpanLink } from '../DiscoverSpanLink'; import { DiscoverTransactionLink } from '../DiscoverTransactionLink'; -import * as hooks from '../../../../../hooks/useCore'; +import * as kibanaCore from '../../../../../../../observability/public/context/kibana_core'; import { InternalCoreStart } from 'src/core/public'; jest.mock('ui/kfetch'); @@ -34,7 +34,7 @@ beforeAll(() => { } } as unknown) as InternalCoreStart; - jest.spyOn(hooks, 'useCore').mockReturnValue(coreMock); + jest.spyOn(kibanaCore, 'useKibanaCore').mockReturnValue(coreMock); }); afterAll(() => { diff --git a/x-pack/legacy/plugins/apm/public/components/shared/Links/InfraLink.test.tsx b/x-pack/legacy/plugins/apm/public/components/shared/Links/InfraLink.test.tsx index 9925d87a159ca..d5518f6a96195 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/Links/InfraLink.test.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/Links/InfraLink.test.tsx @@ -8,7 +8,7 @@ import { Location } from 'history'; import React from 'react'; import { getRenderedHref } from '../../../utils/testHelpers'; import { InfraLink } from './InfraLink'; -import * as hooks from '../../../hooks/useCore'; +import * as kibanaCore from '../../../../../observability/public/context/kibana_core'; import { InternalCoreStart } from 'src/core/public'; const coreMock = ({ @@ -19,7 +19,7 @@ const coreMock = ({ } } as unknown) as InternalCoreStart; -jest.spyOn(hooks, 'useCore').mockReturnValue(coreMock); +jest.spyOn(kibanaCore, 'useKibanaCore').mockReturnValue(coreMock); test('InfraLink produces the correct URL', async () => { const href = await getRenderedHref( diff --git a/x-pack/legacy/plugins/apm/public/components/shared/Links/InfraLink.tsx b/x-pack/legacy/plugins/apm/public/components/shared/Links/InfraLink.tsx index eda64b4bbedb2..192fafadba4c0 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/Links/InfraLink.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/Links/InfraLink.tsx @@ -9,7 +9,7 @@ import { compact } from 'lodash'; import React from 'react'; import url from 'url'; import { fromQuery } from './url_helpers'; -import { useCore } from '../../../hooks/useCore'; +import { useKibanaCore } from '../../../../../observability/public'; interface InfraQueryParams { time?: number; @@ -24,7 +24,7 @@ interface Props extends EuiLinkAnchorProps { } export function InfraLink({ path, query = {}, ...rest }: Props) { - const core = useCore(); + const core = useKibanaCore(); const nextSearch = fromQuery(query); const href = url.format({ pathname: core.http.basePath.prepend('/app/infra'), diff --git a/x-pack/legacy/plugins/apm/public/components/shared/Links/KibanaLink.test.tsx b/x-pack/legacy/plugins/apm/public/components/shared/Links/KibanaLink.test.tsx index 24637f971bf3c..c01d198b65b5a 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/Links/KibanaLink.test.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/Links/KibanaLink.test.tsx @@ -8,7 +8,7 @@ import { Location } from 'history'; import React from 'react'; import { getRenderedHref } from '../../../utils/testHelpers'; import { KibanaLink } from './KibanaLink'; -import * as hooks from '../../../hooks/useCore'; +import * as kibanaCore from '../../../../../observability/public/context/kibana_core'; import { InternalCoreStart } from 'src/core/public'; describe('KibanaLink', () => { @@ -21,7 +21,7 @@ describe('KibanaLink', () => { } } as unknown) as InternalCoreStart; - jest.spyOn(hooks, 'useCore').mockReturnValue(coreMock); + jest.spyOn(kibanaCore, 'useKibanaCore').mockReturnValue(coreMock); }); afterEach(() => { diff --git a/x-pack/legacy/plugins/apm/public/components/shared/Links/KibanaLink.tsx b/x-pack/legacy/plugins/apm/public/components/shared/Links/KibanaLink.tsx index 53fe9da734644..de62d5e46070a 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/Links/KibanaLink.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/Links/KibanaLink.tsx @@ -7,7 +7,7 @@ import { EuiLink, EuiLinkAnchorProps } from '@elastic/eui'; import React from 'react'; import url from 'url'; -import { useCore } from '../../../hooks/useCore'; +import { useKibanaCore } from '../../../../../observability/public'; interface Props extends EuiLinkAnchorProps { path?: string; @@ -15,7 +15,7 @@ interface Props extends EuiLinkAnchorProps { } export function KibanaLink({ path, ...rest }: Props) { - const core = useCore(); + const core = useKibanaCore(); const href = url.format({ pathname: core.http.basePath.prepend('/app/kibana'), hash: path diff --git a/x-pack/legacy/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLJobLink.test.tsx b/x-pack/legacy/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLJobLink.test.tsx index c577a38029d29..524a2d225c84c 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLJobLink.test.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLJobLink.test.tsx @@ -8,7 +8,7 @@ import { Location } from 'history'; import React from 'react'; import { getRenderedHref } from '../../../../utils/testHelpers'; import { MLJobLink } from './MLJobLink'; -import * as hooks from '../../../../hooks/useCore'; +import * as kibanaCore from '../../../../../../observability/public/context/kibana_core'; import { InternalCoreStart } from 'src/core/public'; describe('MLJobLink', () => { @@ -21,7 +21,7 @@ describe('MLJobLink', () => { } } as unknown) as InternalCoreStart; - spyOn(hooks, 'useCore').and.returnValue(coreMock); + spyOn(kibanaCore, 'useKibanaCore').and.returnValue(coreMock); }); afterEach(() => { diff --git a/x-pack/legacy/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLLink.test.tsx b/x-pack/legacy/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLLink.test.tsx index 5f66cf8563260..73f8bb2c7a213 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLLink.test.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLLink.test.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { getRenderedHref } from '../../../../utils/testHelpers'; import { MLLink } from './MLLink'; import * as savedObjects from '../../../../services/rest/savedObjects'; -import * as hooks from '../../../../hooks/useCore'; +import * as kibanaCore from '../../../../../../observability/public/context/kibana_core'; import { InternalCoreStart } from 'src/core/public'; jest.mock('ui/kfetch'); @@ -22,7 +22,7 @@ const coreMock = ({ } } as unknown) as InternalCoreStart; -jest.spyOn(hooks, 'useCore').mockReturnValue(coreMock); +jest.spyOn(kibanaCore, 'useKibanaCore').mockReturnValue(coreMock); jest .spyOn(savedObjects, 'getAPMIndexPattern') diff --git a/x-pack/legacy/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLLink.tsx b/x-pack/legacy/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLLink.tsx index e0b9331d28496..0fe80b729f010 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLLink.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/Links/MachineLearningLinks/MLLink.tsx @@ -10,7 +10,7 @@ import url from 'url'; import rison, { RisonValue } from 'rison-node'; import { useLocation } from '../../../../hooks/useLocation'; import { getTimepickerRisonData, TimepickerRisonData } from '../rison_helpers'; -import { useCore } from '../../../../hooks/useCore'; +import { useKibanaCore } from '../../../../../../observability/public'; interface MlRisonData { ml?: { @@ -25,7 +25,7 @@ interface Props { } export function MLLink({ children, path = '', query = {} }: Props) { - const core = useCore(); + const core = useKibanaCore(); const location = useLocation(); const risonQuery: MlRisonData & TimepickerRisonData = getTimepickerRisonData( diff --git a/x-pack/legacy/plugins/apm/public/components/shared/TransactionActionMenu/TransactionActionMenu.tsx b/x-pack/legacy/plugins/apm/public/components/shared/TransactionActionMenu/TransactionActionMenu.tsx index 2e3382f71b204..317fac87eea5a 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/TransactionActionMenu/TransactionActionMenu.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/TransactionActionMenu/TransactionActionMenu.tsx @@ -24,7 +24,7 @@ import { DiscoverTransactionLink } from '../Links/DiscoverLinks/DiscoverTransact import { InfraLink } from '../Links/InfraLink'; import { useUrlParams } from '../../../hooks/useUrlParams'; import { fromQuery } from '../Links/url_helpers'; -import { useCore } from '../../../hooks/useCore'; +import { useKibanaCore } from '../../../../../observability/public'; function getInfraMetricsQuery(transaction: Transaction) { const plus5 = new Date(transaction['@timestamp']); @@ -66,7 +66,7 @@ export const TransactionActionMenu: FunctionComponent = ( ) => { const { transaction } = props; - const core = useCore(); + const core = useKibanaCore(); const [isOpen, setIsOpen] = useState(false); diff --git a/x-pack/legacy/plugins/apm/public/components/shared/TransactionActionMenu/__test__/TransactionActionMenu.test.tsx b/x-pack/legacy/plugins/apm/public/components/shared/TransactionActionMenu/__test__/TransactionActionMenu.test.tsx index 89adbd5c0d832..8442f300aa0fc 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/TransactionActionMenu/__test__/TransactionActionMenu.test.tsx +++ b/x-pack/legacy/plugins/apm/public/components/shared/TransactionActionMenu/__test__/TransactionActionMenu.test.tsx @@ -11,7 +11,7 @@ import { TransactionActionMenu } from '../TransactionActionMenu'; import { Transaction } from '../../../../../typings/es_schemas/ui/Transaction'; import * as Transactions from './mockData'; import * as apmIndexPatternHooks from '../../../../hooks/useAPMIndexPattern'; -import * as coreHoooks from '../../../../hooks/useCore'; +import * as kibanaCore from '../../../../../../observability/public/context/kibana_core'; import { ISavedObject } from '../../../../services/rest/savedObjects'; import { InternalCoreStart } from 'src/core/public'; @@ -40,7 +40,7 @@ describe('TransactionActionMenu component', () => { jest .spyOn(apmIndexPatternHooks, 'useAPMIndexPattern') .mockReturnValue({ id: 'foo' } as ISavedObject); - jest.spyOn(coreHoooks, 'useCore').mockReturnValue(coreMock); + jest.spyOn(kibanaCore, 'useKibanaCore').mockReturnValue(coreMock); }); afterEach(() => { diff --git a/x-pack/legacy/plugins/apm/public/context/CoreContext.tsx b/x-pack/legacy/plugins/apm/public/context/CoreContext.tsx deleted file mode 100644 index 0bf39e4d9dadb..0000000000000 --- a/x-pack/legacy/plugins/apm/public/context/CoreContext.tsx +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import React, { createContext } from 'react'; -import { InternalCoreStart } from 'src/core/public'; - -const CoreContext = createContext({} as InternalCoreStart); -const CoreProvider: React.SFC<{ core: InternalCoreStart }> = props => { - const { core, ...restProps } = props; - return ; -}; - -export { CoreContext, CoreProvider }; diff --git a/x-pack/legacy/plugins/apm/public/context/LicenseContext/InvalidLicenseNotification.tsx b/x-pack/legacy/plugins/apm/public/context/LicenseContext/InvalidLicenseNotification.tsx index ffd85412be0f4..1c340f4b4f3c7 100644 --- a/x-pack/legacy/plugins/apm/public/context/LicenseContext/InvalidLicenseNotification.tsx +++ b/x-pack/legacy/plugins/apm/public/context/LicenseContext/InvalidLicenseNotification.tsx @@ -6,10 +6,10 @@ import { EuiButton, EuiEmptyPrompt } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import React from 'react'; -import { useCore } from '../../hooks/useCore'; +import { useKibanaCore } from '../../../../observability/public'; export function InvalidLicenseNotification() { - const core = useCore(); + const core = useKibanaCore(); const manageLicenseURL = core.http.basePath.prepend( '/app/kibana#/management/elasticsearch/license_management' ); diff --git a/x-pack/legacy/plugins/apm/public/hooks/useCore.tsx b/x-pack/legacy/plugins/apm/public/hooks/useCore.tsx deleted file mode 100644 index 06942019d6530..0000000000000 --- a/x-pack/legacy/plugins/apm/public/hooks/useCore.tsx +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { useContext } from 'react'; -import { CoreContext } from '../context/CoreContext'; - -export function useCore() { - return useContext(CoreContext); -} diff --git a/x-pack/legacy/plugins/apm/public/index.tsx b/x-pack/legacy/plugins/apm/public/index.tsx index 20d111333e4e1..bc1e6f9e714ac 100644 --- a/x-pack/legacy/plugins/apm/public/index.tsx +++ b/x-pack/legacy/plugins/apm/public/index.tsx @@ -19,16 +19,16 @@ import { plugin } from './new-platform'; import { REACT_APP_ROOT_ID } from './new-platform/plugin'; import './style/global_overrides.css'; import template from './templates/index.html'; -import { CoreProvider } from './context/CoreContext'; +import { KibanaCoreContextProvider } from '../../observability/public'; const { core } = npStart; // render APM feedback link in global help menu core.chrome.setHelpExtension(domElement => { ReactDOM.render( - + - , + , domElement ); return () => { diff --git a/x-pack/legacy/plugins/apm/public/new-platform/plugin.tsx b/x-pack/legacy/plugins/apm/public/new-platform/plugin.tsx index abd793245cbb6..c9a1e583a3cb0 100644 --- a/x-pack/legacy/plugins/apm/public/new-platform/plugin.tsx +++ b/x-pack/legacy/plugins/apm/public/new-platform/plugin.tsx @@ -9,8 +9,8 @@ import ReactDOM from 'react-dom'; import { Router, Route, Switch } from 'react-router-dom'; import styled from 'styled-components'; import { InternalCoreStart } from 'src/core/public'; +import { KibanaCoreContextProvider } from '../../../observability/public'; import { history } from '../utils/history'; -import { CoreProvider } from '../context/CoreContext'; import { LocationProvider } from '../context/LocationContext'; import { UrlParamsProvider } from '../context/UrlParamsContext'; import { px, unit, units } from '../style/variables'; @@ -57,7 +57,7 @@ export class Plugin { public start(core: InternalCoreStart) { const { i18n } = core; ReactDOM.render( - + @@ -65,7 +65,7 @@ export class Plugin { - , + , document.getElementById(REACT_APP_ROOT_ID) ); } diff --git a/x-pack/legacy/plugins/observability/public/context/kibana_core.tsx b/x-pack/legacy/plugins/observability/public/context/kibana_core.tsx new file mode 100644 index 0000000000000..778e138c5fa6c --- /dev/null +++ b/x-pack/legacy/plugins/observability/public/context/kibana_core.tsx @@ -0,0 +1,25 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React, { createContext, useContext } from 'react'; +import { InternalCoreStart } from '../../../../../../src/core/public'; + +interface AppMountContext { + core: InternalCoreStart; +} + +// TODO: Replace CoreStart/CoreSetup with AppMountContext +// see: https://github.com/elastic/kibana/pull/41007 + +export const KibanaCoreContext = createContext({} as AppMountContext['core']); + +export const KibanaCoreContextProvider: React.FC<{ core: AppMountContext['core'] }> = props => ( + +); + +export function useKibanaCore() { + return useContext(KibanaCoreContext); +} diff --git a/x-pack/legacy/plugins/observability/public/index.tsx b/x-pack/legacy/plugins/observability/public/index.tsx index 8052f4a9c02e8..49e5a6d787a55 100644 --- a/x-pack/legacy/plugins/observability/public/index.tsx +++ b/x-pack/legacy/plugins/observability/public/index.tsx @@ -3,5 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ +import { KibanaCoreContext, KibanaCoreContextProvider, useKibanaCore } from './context/kibana_core'; +import { ExampleSharedComponent } from './components/example_shared_component'; -export { ExampleSharedComponent } from './components/example_shared_component'; +export { ExampleSharedComponent, KibanaCoreContext, KibanaCoreContextProvider, useKibanaCore };