diff --git a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/app_context.mock.ts b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/app_context.mock.ts index 4cd2570f1d393..7550055d8242d 100644 --- a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/app_context.mock.ts +++ b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/app_context.mock.ts @@ -10,13 +10,23 @@ import { docLinksServiceMock, notificationServiceMock, applicationServiceMock, + httpServiceMock, + coreMock, + scopedHistoryMock, } from 'src/core/public/mocks'; import { sharePluginMock } from 'src/plugins/share/public/mocks'; -import { HttpSetup } from 'src/core/public'; import { mockKibanaSemverVersion } from '../../../common/constants'; import { apiService } from '../../../public/application/lib/api'; import { breadcrumbService } from '../../../public/application/lib/breadcrumbs'; +import { dataPluginMock } from '../../../../../../src/plugins/data/public/mocks'; +import { cloudMock } from '../../../../../../x-pack/plugins/cloud/public/mocks'; + +const servicesMock = { + api: apiService, + breadcrumbs: breadcrumbService, + data: dataPluginMock.createStartContract(), +}; // We'll mock these values to avoid testing the locators themselves. const idToUrlMap = { @@ -32,19 +42,30 @@ shareMock.url.locators.get = (id) => ({ getUrl: (): string | undefined => idToUrlMap[id], }); -export const getAppContextMock = (mockHttpClient: HttpSetup) => ({ - http: mockHttpClient, - docLinks: docLinksServiceMock.createStartContract(), +export const getAppContextMock = () => ({ + isReadOnlyMode: false, kibanaVersionInfo: { currentMajor: mockKibanaSemverVersion.major, prevMajor: mockKibanaSemverVersion.major - 1, nextMajor: mockKibanaSemverVersion.major + 1, }, - notifications: notificationServiceMock.createStartContract(), - isReadOnlyMode: false, - api: apiService, - breadcrumbs: breadcrumbService, - getUrlForApp: applicationServiceMock.createStartContract().getUrlForApp, - deprecations: deprecationsServiceMock.createStartContract(), - share: shareMock, + services: { + ...servicesMock, + core: { + ...coreMock.createStart(), + http: httpServiceMock.createSetupContract(), + deprecations: deprecationsServiceMock.createStartContract(), + notifications: notificationServiceMock.createStartContract(), + docLinks: docLinksServiceMock.createStartContract(), + history: scopedHistoryMock.create(), + application: applicationServiceMock.createStartContract(), + }, + }, + plugins: { + share: shareMock, + cloud: { + ...cloudMock.createSetup(), + isCloudEnabled: false, + }, + }, }); diff --git a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/kibana_context.mock.ts b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/kibana_context.mock.ts deleted file mode 100644 index 043e141f4a360..0000000000000 --- a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/kibana_context.mock.ts +++ /dev/null @@ -1,14 +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 - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { dataPluginMock } from '../../../../../../src/plugins/data/public/mocks'; -import { applicationServiceMock } from '../../../../../../src/core/public/application/application_service.mock'; - -export const kibanaContextMock = { - data: dataPluginMock.createStartContract(), - application: applicationServiceMock.createStartContract(), -}; diff --git a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/setup_environment.tsx b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/setup_environment.tsx index cbc21697651fb..2152b6adf8684 100644 --- a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/setup_environment.tsx +++ b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/setup_environment.tsx @@ -7,19 +7,19 @@ import React from 'react'; import axios from 'axios'; +import { merge } from 'lodash'; // @ts-ignore import axiosXhrAdapter from 'axios/lib/adapters/xhr'; import { HttpSetup } from 'src/core/public'; -import { KibanaContextProvider } from '../../../public/shared_imports'; import { AppContextProvider } from '../../../public/application/app_context'; import { apiService } from '../../../public/application/lib/api'; import { breadcrumbService } from '../../../public/application/lib/breadcrumbs'; import { GlobalFlyout } from '../../../public/shared_imports'; -import { kibanaContextMock } from './kibana_context.mock'; import { getAppContextMock } from './app_context.mock'; import { init as initHttpRequests } from './http_requests'; +import { AppDependencies } from '../../../public/types'; const { GlobalFlyoutProvider } = GlobalFlyout; @@ -31,18 +31,14 @@ export const WithAppDependencies = (Comp: any, overrides: Record ''); - const appContextMock = getAppContextMock((mockHttpClient as unknown) as HttpSetup); - - const { kibanaContextOverrides, ...appContextOverrides } = overrides; + const appContextMock = (getAppContextMock() as unknown) as AppDependencies; return ( - - - - - - - + + + + + ); }; diff --git a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/kibana_deprecations/kibana_deprecations.test.ts b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/kibana_deprecations/kibana_deprecations.test.ts index bc6bd47cf37d9..183d0ff6ab53e 100644 --- a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/kibana_deprecations/kibana_deprecations.test.ts +++ b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/kibana_deprecations/kibana_deprecations.test.ts @@ -44,7 +44,11 @@ describe('Kibana deprecations', () => { .mockReturnValue(kibanaDeprecationsMockResponse); testBed = await setupKibanaPage({ - deprecations: deprecationService, + services: { + core: { + deprecations: deprecationService, + }, + }, }); }); @@ -176,7 +180,11 @@ describe('Kibana deprecations', () => { .mockRejectedValue(new Error('Internal Server Error')); testBed = await setupKibanaPage({ - deprecations: deprecationService, + services: { + core: { + deprecations: deprecationService, + }, + }, }); }); @@ -208,7 +216,11 @@ describe('Kibana deprecations', () => { .mockReturnValue(kibanaDeprecationsMockResponse); testBed = await setupKibanaPage({ - deprecations: deprecationService, + services: { + core: { + deprecations: deprecationService, + }, + }, }); }); diff --git a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/fix_issues_step/fix_issues_step.test.tsx b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/fix_issues_step/fix_issues_step.test.tsx index 581e80e7c290a..e39f0da488205 100644 --- a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/fix_issues_step/fix_issues_step.test.tsx +++ b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/fix_issues_step/fix_issues_step.test.tsx @@ -26,7 +26,11 @@ describe('Overview - Fix deprecation issues step', () => { .mockReturnValue(mockedResponses.kibanaDeprecations); testBed = await setupOverviewPage({ - deprecations: deprecationService, + services: { + core: { + deprecations: deprecationService, + }, + }, }); }); @@ -172,7 +176,11 @@ describe('Overview - Fix deprecation issues step', () => { deprecationService.getAllDeprecations = jest.fn().mockRejectedValue([]); testBed = await setupOverviewPage({ - deprecations: deprecationService, + services: { + core: { + deprecations: deprecationService, + }, + }, }); }); @@ -201,7 +209,11 @@ describe('Overview - Fix deprecation issues step', () => { .mockRejectedValue(new Error('Internal Server Error')); testBed = await setupOverviewPage({ - deprecations: deprecationService, + services: { + core: { + deprecations: deprecationService, + }, + }, }); }); diff --git a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/upgrade_step/upgrade_step.test.tsx b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/upgrade_step/upgrade_step.test.tsx index 61fc6b45fa4c7..7135c5849fb73 100644 --- a/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/upgrade_step/upgrade_step.test.tsx +++ b/x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/upgrade_step/upgrade_step.test.tsx @@ -36,7 +36,7 @@ describe('Overview - Upgrade Step', () => { test('Shows upgrade CTA and link to docs', async () => { await act(async () => { testBed = await setupOverviewPage({ - kibanaContextOverrides: { + plugins: { cloud: { isCloudEnabled: true, deploymentUrl: diff --git a/x-pack/plugins/upgrade_assistant/public/application/app.tsx b/x-pack/plugins/upgrade_assistant/public/application/app.tsx index 8a1ee9a91cabb..cc921bdaefc15 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/app.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/app.tsx @@ -7,26 +7,19 @@ import React from 'react'; import { Router, Switch, Route, Redirect } from 'react-router-dom'; -import { I18nStart, ScopedHistory } from 'src/core/public'; -import { ApplicationStart } from 'kibana/public'; +import { ScopedHistory } from 'src/core/public'; import { GlobalFlyout } from '../shared_imports'; -import { KibanaContextProvider, APP_WRAPPER_CLASS } from '../shared_imports'; -import { AppServicesContext } from '../types'; -import { AppContextProvider, ContextValue, useAppContext } from './app_context'; +import { APP_WRAPPER_CLASS } from '../shared_imports'; +import { AppContextProvider, useAppContext } from './app_context'; import { ComingSoonPrompt } from './components/coming_soon_prompt'; import { EsDeprecations } from './components/es_deprecations'; import { KibanaDeprecationsContent } from './components/kibana_deprecations'; import { Overview } from './components/overview'; import { RedirectAppLinks } from '../../../../../src/plugins/kibana_react/public'; +import { AppDependencies } from '../types'; const { GlobalFlyoutProvider } = GlobalFlyout; -export interface AppDependencies extends ContextValue { - i18n: I18nStart; - history: ScopedHistory; - application: ApplicationStart; - services: AppServicesContext; -} const App: React.FunctionComponent = () => { const { isReadOnlyMode } = useAppContext(); @@ -54,23 +47,20 @@ export const AppWithRouter = ({ history }: { history: ScopedHistory }) => { ); }; -export const RootComponent = ({ - i18n, - history, - services, - application, - ...contextValue -}: AppDependencies) => { +export const RootComponent = (dependencies: AppDependencies) => { + const { + history, + core: { i18n, application }, + } = dependencies.services; + return ( - - - - - - - + + + + + ); diff --git a/x-pack/plugins/upgrade_assistant/public/application/app_context.tsx b/x-pack/plugins/upgrade_assistant/public/application/app_context.tsx index 9543c1c4db385..8b11b20ed1853 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/app_context.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/app_context.tsx @@ -6,44 +6,16 @@ */ import React, { createContext, useContext } from 'react'; -import { - CoreStart, - DeprecationsServiceStart, - DocLinksStart, - HttpSetup, - NotificationsStart, -} from 'src/core/public'; -import { SharePluginSetup } from 'src/plugins/share/public'; -import { ApiService } from './lib/api'; -import { BreadcrumbService } from './lib/breadcrumbs'; +import { AppDependencies } from '../types'; -export interface KibanaVersionContext { - currentMajor: number; - prevMajor: number; - nextMajor: number; -} - -export interface ContextValue { - http: HttpSetup; - docLinks: DocLinksStart; - kibanaVersionInfo: KibanaVersionContext; - notifications: NotificationsStart; - isReadOnlyMode: boolean; - api: ApiService; - breadcrumbs: BreadcrumbService; - getUrlForApp: CoreStart['application']['getUrlForApp']; - deprecations: DeprecationsServiceStart; - share: SharePluginSetup; -} - -export const AppContext = createContext({} as any); +export const AppContext = createContext(undefined); export const AppContextProvider = ({ children, value, }: { children: React.ReactNode; - value: ContextValue; + value: AppDependencies; }) => { return {children}; }; diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/coming_soon_prompt.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/coming_soon_prompt.tsx index 14627f0b138b0..883a8675e0ce0 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/coming_soon_prompt.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/coming_soon_prompt.tsx @@ -11,7 +11,13 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { useAppContext } from '../app_context'; export const ComingSoonPrompt: React.FunctionComponent = () => { - const { kibanaVersionInfo, docLinks } = useAppContext(); + const { + kibanaVersionInfo, + services: { + core: { docLinks }, + }, + } = useAppContext(); + const { nextMajor, currentMajor } = kibanaVersionInfo; const { ELASTIC_WEBSITE_URL } = docLinks; diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/index_settings/table_row.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/index_settings/table_row.tsx index 3a1706b08c0ee..3ce85a9345aeb 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/index_settings/table_row.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/index_settings/table_row.tsx @@ -33,7 +33,9 @@ export const IndexSettingsTableRow: React.FunctionComponent = ({ details?: ResponseError; }>({ statusType: 'idle' }); - const { api } = useAppContext(); + const { + services: { api }, + } = useAppContext(); const { addContent: addContentToGlobalFlyout, diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/ml_snapshots/table_row.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/ml_snapshots/table_row.tsx index 73921b235d88c..0815be4a1f956 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/ml_snapshots/table_row.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/ml_snapshots/table_row.tsx @@ -78,7 +78,9 @@ export const MlSnapshotsTableRowCells: React.FunctionComponent = }; export const MlSnapshotsTableRow: React.FunctionComponent = (props) => { - const { api } = useAppContext(); + const { + services: { api }, + } = useAppContext(); return ( = ({ }) => { const { status, reindexWarnings } = reindexState; const { index, correctiveAction } = deprecation; - const { docLinks } = useAppContext(); + const { + services: { + core: { docLinks }, + }, + } = useAppContext(); // If there are any warnings and we haven't started reindexing, show the warnings step first. const [currentFlyoutStep, setCurrentFlyoutStep] = useState( reindexWarnings && reindexWarnings.length > 0 && status === undefined diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warning_step.test.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warning_step.test.tsx index ff11b9f1a8450..1247257019412 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warning_step.test.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warning_step.test.tsx @@ -22,11 +22,10 @@ jest.mock('../../../../../app_context', () => { return { useAppContext: () => { return { - docLinks: docLinksServiceMock.createStartContract(), - kibanaVersionInfo: { - currentMajor: mockKibanaSemverVersion.major, - prevMajor: mockKibanaSemverVersion.major - 1, - nextMajor: mockKibanaSemverVersion.major + 1, + services: { + core: { + docLinks: docLinksServiceMock.createStartContract(), + }, }, }; }, diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warnings_step.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warnings_step.tsx index 4415811f6bf38..9e3755bfa8a35 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warnings_step.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/warnings_step.tsx @@ -56,7 +56,11 @@ export const WarningsFlyoutStep: React.FunctionComponent { - const { docLinks } = useAppContext(); + const { + services: { + core: { docLinks }, + }, + } = useAppContext(); const { links } = docLinks; const [checkedIds, setCheckedIds] = useState( diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/table_row.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/table_row.tsx index 95d65f1e77771..12680831e7f75 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/table_row.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/table_row.tsx @@ -29,7 +29,9 @@ const ReindexTableRowCells: React.FunctionComponent = ({ }) => { const [showFlyout, setShowFlyout] = useState(false); const reindexState = useReindexContext(); - const { api } = useAppContext(); + const { + services: { api }, + } = useAppContext(); const { addContent: addContentToGlobalFlyout, @@ -94,7 +96,9 @@ const ReindexTableRowCells: React.FunctionComponent = ({ }; export const ReindexTableRow: React.FunctionComponent = (props) => { - const { api } = useAppContext(); + const { + services: { api }, + } = useAppContext(); return ( diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/es_deprecations.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/es_deprecations.tsx index b714ae2ca2fd1..52722a52be6d3 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/es_deprecations.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/es_deprecations.tsx @@ -71,7 +71,9 @@ const i18nTexts = { }; export const EsDeprecations = withRouter(({ history }: RouteComponentProps) => { - const { api, breadcrumbs } = useAppContext(); + const { + services: { api, breadcrumbs }, + } = useAppContext(); const { data: esDeprecations, diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/kibana_deprecations/kibana_deprecations.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/kibana_deprecations/kibana_deprecations.tsx index 56d6e23d9d4f3..90f8936d0e38d 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/kibana_deprecations/kibana_deprecations.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/kibana_deprecations/kibana_deprecations.tsx @@ -64,7 +64,13 @@ export const KibanaDeprecationsContent = withRouter(({ history }: RouteComponent >(undefined); const [isResolvingDeprecation, setIsResolvingDeprecation] = useState(false); - const { deprecations, breadcrumbs, docLinks, api, notifications } = useAppContext(); + const { + services: { + core: { deprecations, docLinks, notifications }, + breadcrumbs, + api, + }, + } = useAppContext(); const getAllDeprecations = useCallback(async () => { setIsLoading(true); diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/on_prem_backup.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/on_prem_backup.tsx index 7982a1248b289..2e2e2bd5ce48e 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/on_prem_backup.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/overview/backup_step/on_prem_backup.tsx @@ -13,7 +13,9 @@ import { EuiText, EuiButton, EuiSpacer } from '@elastic/eui'; import { useAppContext } from '../../../app_context'; const SnapshotRestoreAppLink: React.FunctionComponent = () => { - const { share } = useAppContext(); + const { + plugins: { share }, + } = useAppContext(); const snapshotRestoreUrl = share.url.locators .get('SNAPSHOT_RESTORE_LOCATOR') diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_issues_step/es_stats/es_stats.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_issues_step/es_stats/es_stats.tsx index ef0b3f438da03..9526f5bc2316c 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_issues_step/es_stats/es_stats.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_issues_step/es_stats/es_stats.tsx @@ -62,7 +62,9 @@ const i18nTexts = { export const ESDeprecationStats: FunctionComponent = () => { const history = useHistory(); - const { api } = useAppContext(); + const { + services: { api }, + } = useAppContext(); const { data: esDeprecations, isLoading, error } = api.useLoadEsDeprecations(); diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_issues_step/kibana_stats/kibana_stats.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_issues_step/kibana_stats/kibana_stats.tsx index d7b820aa4a484..9388ee52f57a1 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_issues_step/kibana_stats/kibana_stats.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_issues_step/kibana_stats/kibana_stats.tsx @@ -70,7 +70,11 @@ const i18nTexts = { export const KibanaDeprecationStats: FunctionComponent = () => { const history = useHistory(); - const { deprecations } = useAppContext(); + const { + services: { + core: { deprecations }, + }, + } = useAppContext(); const [kibanaDeprecations, setKibanaDeprecations] = useState< DomainDeprecationDetails[] | undefined diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_logs_step/deprecations_count_checkpoint/deprecations_count_checkpoint.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_logs_step/deprecations_count_checkpoint/deprecations_count_checkpoint.tsx index 5187e13d210bd..58b7b7ca11ebd 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_logs_step/deprecations_count_checkpoint/deprecations_count_checkpoint.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_logs_step/deprecations_count_checkpoint/deprecations_count_checkpoint.tsx @@ -65,7 +65,9 @@ const getPreviousCheckpointDate = () => { }; export const DeprecationsCountCheckpoint: FunctionComponent = () => { - const { api } = useAppContext(); + const { + services: { api }, + } = useAppContext(); const [previousCheck, setPreviousCheck] = useState(getPreviousCheckpointDate()); const { data, error, isLoading, resendRequest, isInitialRequest } = api.getDeprecationLogsCount( previousCheck diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_logs_step/external_links.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_logs_step/external_links.tsx index 7ddd1c562ac3f..5afd1dba32c3a 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_logs_step/external_links.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_logs_step/external_links.tsx @@ -11,7 +11,7 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { EuiLink, EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiPanel, EuiText } from '@elastic/eui'; import { useAppContext } from '../../../app_context'; -import { useKibana, DataPublicPluginStart } from '../../../../shared_imports'; +import { DataPublicPluginStart } from '../../../../shared_imports'; import { DEPRECATION_LOGS_INDEX_PATTERN, DEPRECATION_LOGS_SOURCE_ID, @@ -39,8 +39,10 @@ const getDeprecationIndexPatternId = async (dataService: DataPublicPluginStart) }; const DiscoverAppLink: FunctionComponent = () => { - const { share } = useAppContext(); - const { data: dataService } = useKibana().services; + const { + services: { data: dataService }, + plugins: { share }, + } = useAppContext(); const [discoveryUrl, setDiscoveryUrl] = useState(); @@ -61,7 +63,7 @@ const DiscoverAppLink: FunctionComponent = () => { }, [dataService, share.url.locators]); return ( - + { }; const ObservabilityAppLink: FunctionComponent = () => { - const { http } = useAppContext(); + const { + services: { + core: { http }, + }, + } = useAppContext(); const logStreamUrl = http?.basePath?.prepend( `/app/logs/stream?sourceId=${DEPRECATION_LOGS_SOURCE_ID}` ); return ( - + { - const { api, notifications } = useAppContext(); + const { + services: { + api, + core: { notifications }, + }, + } = useAppContext(); const { data, error: fetchError, isLoading, resendRequest } = api.useLoadDeprecationLogging(); const [isDeprecationLogIndexingEnabled, setIsDeprecationLogIndexingEnabled] = useState(false); diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/overview/overview.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/overview/overview.tsx index cd5f9a4c74343..4ab5109bd996c 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/overview/overview.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/overview/overview.tsx @@ -20,7 +20,6 @@ import { import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import { useKibana } from '../../../shared_imports'; import { useAppContext } from '../../app_context'; import { getBackupStep } from './backup_step'; import { getFixIssuesStep } from './fix_issues_step'; @@ -29,10 +28,14 @@ import { getUpgradeStep } from './upgrade_step'; export const Overview: FunctionComponent = () => { const { - services: { cloud }, - } = useKibana(); - const { kibanaVersionInfo, breadcrumbs, docLinks, api } = useAppContext(); - const { nextMajor } = kibanaVersionInfo; + kibanaVersionInfo: { nextMajor }, + services: { + breadcrumbs, + api, + core: { docLinks }, + }, + plugins: { cloud }, + } = useAppContext(); useEffect(() => { async function sendTelemetryData() { diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/overview/upgrade_step/upgrade_step.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/overview/upgrade_step/upgrade_step.tsx index 49c81a117d612..cb8c88b9d2af2 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/overview/upgrade_step/upgrade_step.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/overview/upgrade_step/upgrade_step.tsx @@ -18,7 +18,7 @@ import { import { i18n } from '@kbn/i18n'; import type { EuiStepProps } from '@elastic/eui/src/components/steps/step'; import type { DocLinksStart } from 'src/core/public'; -import { useKibana } from '../../../../shared_imports'; +import { useAppContext } from '../../../app_context'; const i18nTexts = { upgradeStepTitle: (nextMajor: number) => @@ -49,7 +49,9 @@ const i18nTexts = { }; const UpgradeStep = ({ docLinks }: { docLinks: DocLinksStart }) => { - const { cloud } = useKibana().services; + const { + plugins: { cloud }, + } = useAppContext(); const isCloudEnabled: boolean = Boolean(cloud?.isCloudEnabled); let callToAction; diff --git a/x-pack/plugins/upgrade_assistant/public/application/mount_management_section.tsx b/x-pack/plugins/upgrade_assistant/public/application/mount_management_section.tsx index 938b43672a4d1..6ab764ddcba6d 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/mount_management_section.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/mount_management_section.tsx @@ -7,61 +7,26 @@ import React from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; -import { CoreSetup } from 'src/core/public'; -import { ManagementAppMountParams } from 'src/plugins/management/public'; -import { SharePluginSetup } from 'src/plugins/share/public'; -import { KibanaVersionContext } from './app_context'; -import { AppDependencies, RootComponent } from './app'; +import type { ManagementAppMountParams } from 'src/plugins/management/public'; +import { RootComponent } from './app'; +import { AppDependencies } from '../types'; + import { apiService } from './lib/api'; import { breadcrumbService } from './lib/breadcrumbs'; -import { AppServicesContext } from '../types'; - -interface BootDependencies extends AppDependencies { - element: HTMLElement; -} - -const renderApp = (deps: BootDependencies) => { - const { element, ...appDependencies } = deps; - render(, element); - return () => { - unmountComponentAtNode(element); - }; -}; -export async function mountManagementSection( - coreSetup: CoreSetup, +export function mountManagementSection( params: ManagementAppMountParams, - kibanaVersionInfo: KibanaVersionContext, - readonly: boolean, - share: SharePluginSetup, - services: AppServicesContext + dependencies: AppDependencies ) { - const [ - { i18n, docLinks, notifications, application, deprecations }, - ] = await coreSetup.getStartServices(); - - const { element, history, setBreadcrumbs } = params; - const { http } = coreSetup; + const { element, setBreadcrumbs } = params; - apiService.setup(http); + apiService.setup(dependencies.services.core.http); breadcrumbService.setup(setBreadcrumbs); - return renderApp({ - element, - http, - i18n, - docLinks, - kibanaVersionInfo, - notifications, - isReadOnlyMode: readonly, - history, - api: apiService, - breadcrumbs: breadcrumbService, - getUrlForApp: application.getUrlForApp, - deprecations, - application, - share, - services, - }); + render(, element); + + return () => { + unmountComponentAtNode(element); + }; } diff --git a/x-pack/plugins/upgrade_assistant/public/plugin.ts b/x-pack/plugins/upgrade_assistant/public/plugin.ts index 1b083caca0418..05c6a74b79661 100644 --- a/x-pack/plugins/upgrade_assistant/public/plugin.ts +++ b/x-pack/plugins/upgrade_assistant/public/plugin.ts @@ -9,7 +9,9 @@ import SemVer from 'semver/classes/semver'; import { i18n } from '@kbn/i18n'; import { Plugin, CoreSetup, PluginInitializerContext } from 'src/core/public'; -import { SetupDependencies, StartDependencies, AppServicesContext } from './types'; +import { apiService } from './application/lib/api'; +import { breadcrumbService } from './application/lib/breadcrumbs'; +import { SetupDependencies, StartDependencies, AppDependencies } from './types'; import { Config } from '../common/config'; export class UpgradeAssistantUIPlugin @@ -41,8 +43,7 @@ export class UpgradeAssistantUIPlugin title: pluginName, order: 1, async mount(params) { - const [coreStart, { data }] = await coreSetup.getStartServices(); - const services: AppServicesContext = { data, cloud }; + const [coreStart, { discover, data }] = await coreSetup.getStartServices(); const { chrome: { docTitle }, @@ -50,15 +51,25 @@ export class UpgradeAssistantUIPlugin docTitle.change(pluginName); - const { mountManagementSection } = await import('./application/mount_management_section'); - const unmountAppCallback = await mountManagementSection( - coreSetup, - params, + const appDependencies: AppDependencies = { kibanaVersionInfo, - readonly, - share, - services - ); + isReadOnlyMode: readonly, + plugins: { + cloud, + share, + }, + services: { + core: coreStart, + data, + history: params.history, + discover, + api: apiService, + breadcrumbs: breadcrumbService, + }, + }; + + const { mountManagementSection } = await import('./application/mount_management_section'); + const unmountAppCallback = mountManagementSection(params, appDependencies); return () => { docTitle.reset(); diff --git a/x-pack/plugins/upgrade_assistant/public/shared_imports.ts b/x-pack/plugins/upgrade_assistant/public/shared_imports.ts index 0b606bba4fc55..706732aa0027b 100644 --- a/x-pack/plugins/upgrade_assistant/public/shared_imports.ts +++ b/x-pack/plugins/upgrade_assistant/public/shared_imports.ts @@ -5,9 +5,6 @@ * 2.0. */ -import { useKibana as _useKibana } from '../../../../src/plugins/kibana_react/public'; -import { AppServicesContext } from './types'; - export { sendRequest, SendRequestConfig, @@ -26,5 +23,3 @@ export { KibanaContextProvider } from '../../../../src/plugins/kibana_react/publ export { DataPublicPluginStart } from '../../../../src/plugins/data/public'; export { APP_WRAPPER_CLASS } from '../../../../src/core/public'; - -export const useKibana = () => _useKibana(); diff --git a/x-pack/plugins/upgrade_assistant/public/types.ts b/x-pack/plugins/upgrade_assistant/public/types.ts index 5a9ece6de5006..db04e59ccd362 100644 --- a/x-pack/plugins/upgrade_assistant/public/types.ts +++ b/x-pack/plugins/upgrade_assistant/public/types.ts @@ -5,16 +5,21 @@ * 2.0. */ +import { ScopedHistory } from 'kibana/public'; import { DiscoverStart } from 'src/plugins/discover/public'; import { ManagementSetup } from 'src/plugins/management/public'; import { DataPublicPluginStart } from 'src/plugins/data/public'; import { SharePluginSetup } from 'src/plugins/share/public'; +import { CoreStart } from 'src/core/public'; import { CloudSetup } from '../../cloud/public'; import { LicensingPluginStart } from '../../licensing/public'; +import { BreadcrumbService } from './application/lib/breadcrumbs'; +import { ApiService } from './application/lib/api'; -export interface AppServicesContext { - data: DataPublicPluginStart; - cloud?: CloudSetup; +export interface KibanaVersionContext { + currentMajor: number; + prevMajor: number; + nextMajor: number; } export interface SetupDependencies { @@ -28,3 +33,20 @@ export interface StartDependencies { discover: DiscoverStart; data: DataPublicPluginStart; } + +export interface AppDependencies { + isReadOnlyMode: boolean; + kibanaVersionInfo: KibanaVersionContext; + plugins: { + cloud?: CloudSetup; + share: SharePluginSetup; + }; + services: { + core: CoreStart; + discover: DiscoverStart; + data: DataPublicPluginStart; + breadcrumbs: BreadcrumbService; + history: ScopedHistory; + api: ApiService; + }; +}