Skip to content

Commit ebe1f1f

Browse files
[Upgrade Assistant] Disable UA and add prompt (#92834)
1 parent 67ca801 commit ebe1f1f

File tree

12 files changed

+263
-35
lines changed

12 files changed

+263
-35
lines changed

x-pack/plugins/upgrade_assistant/common/constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@ import SemVer from 'semver/classes/semver';
1313
*/
1414
export const mockKibanaVersion = '8.0.0';
1515
export const mockKibanaSemverVersion = new SemVer(mockKibanaVersion);
16+
17+
/*
18+
* This will be set to true up until the last minor before the next major.
19+
* In readonly mode, the user will not be able to perform any actions in the UI
20+
* and will be presented with a message indicating as such.
21+
*/
22+
export const UA_READONLY_MODE = true;

x-pack/plugins/upgrade_assistant/public/application/app.tsx

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,19 @@
77

88
import React from 'react';
99
import { I18nStart } from 'src/core/public';
10-
import { EuiPageHeader, EuiPageHeaderSection, EuiTitle } from '@elastic/eui';
11-
import { FormattedMessage } from '@kbn/i18n/react';
12-
import { UpgradeAssistantTabs } from './components/tabs';
13-
import { AppContextProvider, ContextValue, AppContext } from './app_context';
10+
import { AppContextProvider, ContextValue } from './app_context';
11+
import { PageContent } from './components/page_content';
1412

1513
export interface AppDependencies extends ContextValue {
1614
i18n: I18nStart;
1715
}
1816

1917
export const RootComponent = ({ i18n, ...contextValue }: AppDependencies) => {
20-
const { nextMajor } = contextValue.kibanaVersionInfo;
2118
return (
2219
<i18n.Context>
2320
<AppContextProvider value={contextValue}>
2421
<div data-test-subj="upgradeAssistantRoot">
25-
<EuiPageHeader>
26-
<EuiPageHeaderSection>
27-
<EuiTitle size="l">
28-
<h1>
29-
<FormattedMessage
30-
id="xpack.upgradeAssistant.appTitle"
31-
defaultMessage="{version} Upgrade Assistant"
32-
values={{ version: `${nextMajor}.0` }}
33-
/>
34-
</h1>
35-
</EuiTitle>
36-
</EuiPageHeaderSection>
37-
</EuiPageHeader>
38-
<AppContext.Consumer>
39-
{({ http }) => <UpgradeAssistantTabs http={http} />}
40-
</AppContext.Consumer>
22+
<PageContent />
4123
</div>
4224
</AppContextProvider>
4325
</i18n.Context>

x-pack/plugins/upgrade_assistant/public/application/app_context.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface ContextValue {
1919
isCloudEnabled: boolean;
2020
docLinks: DocLinksStart;
2121
kibanaVersionInfo: KibanaVersionContext;
22+
isReadOnlyMode: boolean;
2223
}
2324

2425
export const AppContext = createContext<ContextValue>({} as any);
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import React from 'react';
9+
import { EuiEmptyPrompt, EuiPageContent, EuiLink } from '@elastic/eui';
10+
import { FormattedMessage } from '@kbn/i18n/react';
11+
import { useAppContext } from '../app_context';
12+
13+
export const ComingSoonPrompt: React.FunctionComponent = () => {
14+
const { kibanaVersionInfo, docLinks } = useAppContext();
15+
const { nextMajor, currentMajor } = kibanaVersionInfo;
16+
const { ELASTIC_WEBSITE_URL } = docLinks;
17+
18+
return (
19+
<EuiPageContent>
20+
<EuiEmptyPrompt
21+
iconType="wrench"
22+
data-test-subj="comingSoonPrompt"
23+
title={
24+
<h2>
25+
<FormattedMessage
26+
id="xpack.upgradeAssistant.emptyPrompt.title"
27+
defaultMessage="{uaVersion} Upgrade Assistant"
28+
values={{ uaVersion: `${nextMajor}.0` }}
29+
/>
30+
</h2>
31+
}
32+
body={
33+
<>
34+
<p>
35+
<FormattedMessage
36+
id="xpack.upgradeAssistant.emptyPrompt.upgradeAssistantDescription"
37+
defaultMessage="The Upgrade Assistant identifies deprecated settings in your cluster and helps you
38+
resolve issues before you upgrade. Check back here when it's time to upgrade to Elastic {nextMajor}."
39+
values={{ nextMajor: `${nextMajor}.0` }}
40+
/>
41+
</p>
42+
43+
{currentMajor === 7 && (
44+
<p>
45+
<EuiLink
46+
external
47+
target="_blank"
48+
href={`${ELASTIC_WEBSITE_URL}guide/en/elasticsearch/reference/master/migrating-8.0.html`}
49+
>
50+
<FormattedMessage
51+
id="xpack.upgradeAssistant.emptyPrompt.learnMoreDescription"
52+
defaultMessage="Learn more about migrating to {nextMajor}."
53+
values={{
54+
nextMajor: `${nextMajor}.0`,
55+
}}
56+
/>
57+
</EuiLink>
58+
</p>
59+
)}
60+
</>
61+
}
62+
/>
63+
</EuiPageContent>
64+
);
65+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import React from 'react';
9+
import { EuiPageHeader, EuiPageHeaderSection, EuiTitle } from '@elastic/eui';
10+
import { FormattedMessage } from '@kbn/i18n/react';
11+
12+
import { useAppContext } from '../app_context';
13+
import { ComingSoonPrompt } from './coming_soon_prompt';
14+
import { UpgradeAssistantTabs } from './tabs';
15+
16+
export const PageContent: React.FunctionComponent = () => {
17+
const { kibanaVersionInfo, isReadOnlyMode, http } = useAppContext();
18+
const { nextMajor } = kibanaVersionInfo;
19+
20+
// Read-only mode will be enabled up until the last minor before the next major release
21+
if (isReadOnlyMode) {
22+
return <ComingSoonPrompt />;
23+
}
24+
25+
return (
26+
<>
27+
<EuiPageHeader data-test-subj="upgradeAssistantPageContent">
28+
<EuiPageHeaderSection>
29+
<EuiTitle size="l">
30+
<h1>
31+
<FormattedMessage
32+
id="xpack.upgradeAssistant.appTitle"
33+
defaultMessage="{version} Upgrade Assistant"
34+
values={{ version: `${nextMajor}.0` }}
35+
/>
36+
</h1>
37+
</EuiTitle>
38+
</EuiPageHeaderSection>
39+
</EuiPageHeader>
40+
41+
<UpgradeAssistantTabs http={http} />
42+
</>
43+
);
44+
};

x-pack/plugins/upgrade_assistant/public/application/mount_management_section.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import { CoreSetup } from 'src/core/public';
99
import { ManagementAppMountParams } from '../../../../../src/plugins/management/public';
10+
import { UA_READONLY_MODE } from '../../common/constants';
1011
import { renderApp } from './render_app';
1112
import { KibanaVersionContext } from './app_context';
1213

@@ -24,5 +25,6 @@ export async function mountManagementSection(
2425
i18n,
2526
docLinks,
2627
kibanaVersionInfo,
28+
isReadOnlyMode: UA_READONLY_MODE,
2729
});
2830
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
export { setup, OverviewTestBed } from './overview.helpers';
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import { registerTestBed, TestBed, TestBedConfig } from '@kbn/test/jest';
9+
import { PageContent } from '../../public/application/components/page_content';
10+
import { WithAppDependencies } from './setup_environment';
11+
12+
const testBedConfig: TestBedConfig = {
13+
doMountAsync: true,
14+
};
15+
16+
export type OverviewTestBed = TestBed<OverviewTestSubjects>;
17+
18+
export const setup = async (overrides?: any): Promise<OverviewTestBed> => {
19+
const initTestBed = registerTestBed(WithAppDependencies(PageContent, overrides), testBedConfig);
20+
const testBed = await initTestBed();
21+
22+
return testBed;
23+
};
24+
25+
export type OverviewTestSubjects = 'comingSoonPrompt' | 'upgradeAssistantPageContent';
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import React from 'react';
9+
import axios from 'axios';
10+
11+
import { docLinksServiceMock } from '../../../../../src/core/public/mocks';
12+
import { HttpSetup } from '../../../../../src/core/public';
13+
14+
import { mockKibanaSemverVersion, UA_READONLY_MODE } from '../../common/constants';
15+
import { AppContextProvider } from '../../public/application/app_context';
16+
17+
const mockHttpClient = axios.create();
18+
19+
const contextValue = {
20+
http: (mockHttpClient as unknown) as HttpSetup,
21+
isCloudEnabled: false,
22+
docLinks: docLinksServiceMock.createStartContract(),
23+
kibanaVersionInfo: {
24+
currentMajor: mockKibanaSemverVersion.major,
25+
prevMajor: mockKibanaSemverVersion.major - 1,
26+
nextMajor: mockKibanaSemverVersion.major + 1,
27+
},
28+
isReadOnlyMode: UA_READONLY_MODE,
29+
};
30+
31+
export const WithAppDependencies = (Comp: any, overrides: any = {}) => (props: any) => {
32+
return (
33+
<AppContextProvider value={{ ...contextValue, ...overrides }}>
34+
<Comp {...props} />
35+
</AppContextProvider>
36+
);
37+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import { act } from 'react-dom/test-utils';
9+
10+
import { OverviewTestBed, setup } from './helpers';
11+
12+
describe('<PageContent />', () => {
13+
let testBed: OverviewTestBed;
14+
15+
beforeEach(async () => {
16+
await act(async () => {
17+
testBed = await setup();
18+
});
19+
});
20+
21+
describe('Coming soon prompt', () => {
22+
// Default behavior up until the last minor before the next major release
23+
test('renders the coming soon prompt by default', () => {
24+
const { exists } = testBed;
25+
26+
expect(exists('comingSoonPrompt')).toBe(true);
27+
});
28+
});
29+
30+
describe('Tabs', () => {
31+
beforeEach(async () => {
32+
await act(async () => {
33+
// Override the default context value to verify tab content renders as expected
34+
// This will be the default behavior on the last minor before the next major release (e.g., v7.15)
35+
testBed = await setup({ isReadOnlyMode: false });
36+
});
37+
});
38+
39+
test('renders the coming soon prompt by default', () => {
40+
const { exists } = testBed;
41+
42+
expect(exists('comingSoonPrompt')).toBe(false);
43+
expect(exists('upgradeAssistantPageContent')).toBe(true);
44+
});
45+
});
46+
});

0 commit comments

Comments
 (0)