Skip to content

Commit

Permalink
[Upgrade Assistant] Use kibana version value from core context (#89774)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth authored Feb 1, 2021
1 parent 5c96da1 commit 6ea5889
Show file tree
Hide file tree
Showing 20 changed files with 267 additions and 141 deletions.
13 changes: 0 additions & 13 deletions x-pack/plugins/upgrade_assistant/common/version.ts

This file was deleted.

4 changes: 2 additions & 2 deletions x-pack/plugins/upgrade_assistant/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import React from 'react';
import { I18nStart } from 'src/core/public';
import { EuiPageHeader, EuiPageHeaderSection, EuiTitle } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { NEXT_MAJOR_VERSION } from '../../common/version';
import { UpgradeAssistantTabs } from './components/tabs';
import { AppContextProvider, ContextValue, AppContext } from './app_context';

Expand All @@ -17,6 +16,7 @@ export interface AppDependencies extends ContextValue {
}

export const RootComponent = ({ i18n, ...contextValue }: AppDependencies) => {
const { nextMajor } = contextValue.kibanaVersionInfo;
return (
<i18n.Context>
<AppContextProvider value={contextValue}>
Expand All @@ -28,7 +28,7 @@ export const RootComponent = ({ i18n, ...contextValue }: AppDependencies) => {
<FormattedMessage
id="xpack.upgradeAssistant.appTitle"
defaultMessage="{version} Upgrade Assistant"
values={{ version: `${NEXT_MAJOR_VERSION}.0` }}
values={{ version: `${nextMajor}.0` }}
/>
</h1>
</EuiTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@
import { DocLinksStart, HttpSetup } from 'src/core/public';
import React, { createContext, useContext } from 'react';

export interface KibanaVersionContext {
currentMajor: number;
prevMajor: number;
nextMajor: number;
}

export interface ContextValue {
http: HttpSetup;
isCloudEnabled: boolean;
docLinks: DocLinksStart;
kibanaVersionInfo: KibanaVersionContext;
}

export const AppContext = createContext<ContextValue>({} as any);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import React from 'react';
import { EuiCallOut, EuiLink } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';

import { CURRENT_MAJOR_VERSION, NEXT_MAJOR_VERSION } from '../../../common/version';
import { useAppContext } from '../app_context';

export const LatestMinorBanner: React.FunctionComponent = () => {
const { docLinks } = useAppContext();
const { docLinks, kibanaVersionInfo } = useAppContext();

const { ELASTIC_WEBSITE_URL } = docLinks;
const esDocBasePath = `${ELASTIC_WEBSITE_URL}guide/en/elasticsearch/reference`;

const { currentMajor, nextMajor } = kibanaVersionInfo;

return (
<EuiCallOut
title={
Expand Down Expand Up @@ -48,8 +49,8 @@ export const LatestMinorBanner: React.FunctionComponent = () => {
/>
</EuiLink>
),
nextEsVersion: `${NEXT_MAJOR_VERSION}.x`,
currentEsVersion: `${CURRENT_MAJOR_VERSION}.x`,
nextEsVersion: `${nextMajor}.x`,
currentEsVersion: `${currentMajor}.x`,
}}
/>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import React from 'react';
import SemVer from 'semver/classes/semver';
import { mountWithIntl } from '@kbn/test/jest';
import { httpServiceMock } from 'src/core/public/mocks';
import { UpgradeAssistantTabs } from './tabs';
Expand All @@ -16,6 +17,7 @@ import { OverviewTab } from './tabs/overview';
const promisesToResolve = () => new Promise((resolve) => setTimeout(resolve, 0));

const mockHttp = httpServiceMock.createSetupContract();
const mockKibanaVersion = new SemVer('8.0.0');

jest.mock('../app_context', () => {
return {
Expand All @@ -25,6 +27,11 @@ jest.mock('../app_context', () => {
DOC_LINK_VERSION: 'current',
ELASTIC_WEBSITE_URL: 'https://www.elastic.co/',
},
kibanaVersionInfo: {
currentMajor: mockKibanaVersion.major,
prevMajor: mockKibanaVersion.major - 1,
nextMajor: mockKibanaVersion.major + 1,
},
};
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { shallow } from 'enzyme';
import React from 'react';
import SemVer from 'semver/classes/semver';

import { LoadingState } from '../../types';
import AssistanceData from '../__fixtures__/checkup_api_response.json';
Expand All @@ -20,6 +21,8 @@ const defaultProps = {
setSelectedTabIndex: jest.fn(),
};

const mockKibanaVersion = new SemVer('8.0.0');

jest.mock('../../../app_context', () => {
return {
useAppContext: () => {
Expand All @@ -28,6 +31,11 @@ jest.mock('../../../app_context', () => {
DOC_LINK_VERSION: 'current',
ELASTIC_WEBSITE_URL: 'https://www.elastic.co/',
},
kibanaVersionInfo: {
currentMajor: mockKibanaVersion.major,
prevMajor: mockKibanaVersion.major - 1,
nextMajor: mockKibanaVersion.major + 1,
},
};
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';

import { NEXT_MAJOR_VERSION } from '../../../../../common/version';
import { LoadingErrorBanner } from '../../error_banner';
import { useAppContext } from '../../../app_context';
import {
Expand Down Expand Up @@ -53,11 +52,13 @@ export const CheckupTab: FunctionComponent<CheckupTabProps> = ({
const [search, setSearch] = useState<string>('');
const [currentGroupBy, setCurrentGroupBy] = useState<GroupByOption>(GroupByOption.message);

const { docLinks } = useAppContext();
const { docLinks, kibanaVersionInfo } = useAppContext();

const { DOC_LINK_VERSION, ELASTIC_WEBSITE_URL } = docLinks;
const esDocBasePath = `${ELASTIC_WEBSITE_URL}guide/en/elasticsearch/reference/${DOC_LINK_VERSION}`;

const { nextMajor } = kibanaVersionInfo;

const changeFilter = (filter: LevelFilterOption) => {
setCurrentFilter(filter);
};
Expand Down Expand Up @@ -99,7 +100,7 @@ export const CheckupTab: FunctionComponent<CheckupTabProps> = ({
defaultMessage="These {strongCheckupLabel} issues need your attention. Resolve them before upgrading to Elasticsearch {nextEsVersion}."
values={{
strongCheckupLabel: <strong>{checkupLabel}</strong>,
nextEsVersion: `${NEXT_MAJOR_VERSION}.x`,
nextEsVersion: `${nextMajor}.x`,
}}
/>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { Fragment, FunctionComponent } from 'react';
import React, { FunctionComponent } from 'react';

import {
EuiFlexGroup,
Expand All @@ -17,54 +17,59 @@ import {
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';

import { NEXT_MAJOR_VERSION } from '../../../../../common/version';
import { useAppContext } from '../../../app_context';
import { LoadingErrorBanner } from '../../error_banner';
import { LoadingState, UpgradeAssistantTabProps } from '../../types';
import { Steps } from './steps';

export const OverviewTab: FunctionComponent<UpgradeAssistantTabProps> = (props) => (
<Fragment>
<EuiSpacer />
export const OverviewTab: FunctionComponent<UpgradeAssistantTabProps> = (props) => {
const { kibanaVersionInfo } = useAppContext();
const { nextMajor } = kibanaVersionInfo;

<EuiText grow={false}>
<p>
<FormattedMessage
id="xpack.upgradeAssistant.overviewTab.tabDetail"
defaultMessage="This assistant helps you prepare your cluster and indices for Elasticsearch
return (
<>
<EuiSpacer />

<EuiText grow={false}>
<p>
<FormattedMessage
id="xpack.upgradeAssistant.overviewTab.tabDetail"
defaultMessage="This assistant helps you prepare your cluster and indices for Elasticsearch
{nextEsVersion} For other issues that need your attention, see the Elasticsearch logs."
values={{
nextEsVersion: `${NEXT_MAJOR_VERSION}.x`,
}}
/>
</p>
</EuiText>
values={{
nextEsVersion: `${nextMajor}.x`,
}}
/>
</p>
</EuiText>

<EuiSpacer />
<EuiSpacer />

{props.alertBanner && (
<Fragment>
{props.alertBanner}
{props.alertBanner && (
<>
{props.alertBanner}

<EuiSpacer />
</Fragment>
)}
<EuiSpacer />
</>
)}

<EuiPageContent>
<EuiPageContentBody>
{props.loadingState === LoadingState.Success && <Steps {...props} />}
<EuiPageContent>
<EuiPageContentBody>
{props.loadingState === LoadingState.Success && <Steps {...props} />}

{props.loadingState === LoadingState.Loading && (
<EuiFlexGroup justifyContent="center">
<EuiFlexItem grow={false}>
<EuiLoadingSpinner />
</EuiFlexItem>
</EuiFlexGroup>
)}
{props.loadingState === LoadingState.Loading && (
<EuiFlexGroup justifyContent="center">
<EuiFlexItem grow={false}>
<EuiLoadingSpinner />
</EuiFlexItem>
</EuiFlexGroup>
)}

{props.loadingState === LoadingState.Error && (
<LoadingErrorBanner loadingError={props.loadingError} />
)}
</EuiPageContentBody>
</EuiPageContent>
</Fragment>
);
{props.loadingState === LoadingState.Error && (
<LoadingErrorBanner loadingError={props.loadingError} />
)}
</EuiPageContentBody>
</EuiPageContent>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,37 @@ import {
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

import { CURRENT_MAJOR_VERSION, NEXT_MAJOR_VERSION } from '../../../../../common/version';
import { UpgradeAssistantTabProps } from '../../types';
import { DeprecationLoggingToggle } from './deprecation_logging_toggle';
import { useAppContext } from '../../../app_context';

// Leaving these here even if unused so they are picked up for i18n static analysis
// Keep this until last minor release (when next major is also released).
const WAIT_FOR_RELEASE_STEP = {
const WAIT_FOR_RELEASE_STEP = (majorVersion: number, nextMajorVersion: number) => ({
title: i18n.translate('xpack.upgradeAssistant.overviewTab.steps.waitForReleaseStep.stepTitle', {
defaultMessage: 'Wait for the Elasticsearch {nextEsVersion} release',
values: {
nextEsVersion: `${NEXT_MAJOR_VERSION}.0`,
nextEsVersion: `${nextMajorVersion}.0`,
},
}),
children: (
<Fragment>
<>
<EuiText grow={false}>
<p>
<FormattedMessage
id="xpack.upgradeAssistant.overviewTab.steps.waitForReleaseStep.stepDetail"
defaultMessage="Once the release is out, upgrade to the latest {currentEsMajorVersion} version, and then
return here to proceed with your {nextEsMajorVersion} upgrade."
values={{
currentEsMajorVersion: `${CURRENT_MAJOR_VERSION}.x`, // use "0.x" notation to imply the last minor
nextEsMajorVersion: `${NEXT_MAJOR_VERSION}.0`,
currentEsMajorVersion: `${majorVersion}.x`, // use "0.x" notation to imply the last minor
nextEsMajorVersion: `${nextMajorVersion}.0`,
}}
/>
</p>
</EuiText>
</Fragment>
</>
),
};
});

// Swap in this step for the one above it on the last minor release.
// @ts-ignore
Expand Down Expand Up @@ -100,11 +99,13 @@ export const Steps: FunctionComponent<UpgradeAssistantTabProps> = ({
}, {} as { [checkupType: string]: number });

// Uncomment when START_UPGRADE_STEP is in use!
const { docLinks, http /* , isCloudEnabled */ } = useAppContext();
const { kibanaVersionInfo, docLinks, http /* , isCloudEnabled */ } = useAppContext();

const { DOC_LINK_VERSION, ELASTIC_WEBSITE_URL } = docLinks;
const esDocBasePath = `${ELASTIC_WEBSITE_URL}guide/en/elasticsearch/reference/${DOC_LINK_VERSION}`;

const { currentMajor, nextMajor } = kibanaVersionInfo;

return (
<EuiSteps
className="upgSteps"
Expand Down Expand Up @@ -254,7 +255,7 @@ export const Steps: FunctionComponent<UpgradeAssistantTabProps> = ({
/>
</EuiLink>
),
nextEsVersion: `${NEXT_MAJOR_VERSION}.0`,
nextEsVersion: `${nextMajor}.0`,
}}
/>
</p>
Expand All @@ -278,7 +279,7 @@ export const Steps: FunctionComponent<UpgradeAssistantTabProps> = ({
},

// Swap in START_UPGRADE_STEP on the last minor release.
WAIT_FOR_RELEASE_STEP,
WAIT_FOR_RELEASE_STEP(currentMajor, nextMajor),
// START_UPGRADE_STEP(isCloudEnabled, esDocBasePath),
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import { CoreSetup } from 'src/core/public';
import { ManagementAppMountParams } from '../../../../../src/plugins/management/public';
import { renderApp } from './render_app';
import { KibanaVersionContext } from './app_context';

export async function mountManagementSection(
coreSetup: CoreSetup,
isCloudEnabled: boolean,
params: ManagementAppMountParams
params: ManagementAppMountParams,
kibanaVersionInfo: KibanaVersionContext
) {
const [{ i18n, docLinks }] = await coreSetup.getStartServices();
return renderApp({
Expand All @@ -19,5 +21,6 @@ export async function mountManagementSection(
http: coreSetup.http,
i18n,
docLinks,
kibanaVersionInfo,
});
}
Loading

0 comments on commit 6ea5889

Please sign in to comment.