Skip to content

Commit

Permalink
feat(OCPADVISOR-70): Enable "Upgrade Risks" tab on the cluster detail…
Browse files Browse the repository at this point in the history
  • Loading branch information
gkarat authored Apr 6, 2023
1 parent cc84d19 commit c47ac72
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 55 deletions.
1 change: 1 addition & 0 deletions compiled-lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"unableToConnectDesc": "There was an error retrieving data. Check your connection and try again.",
"undefined": "Undefined",
"unknown": "Unknown",
"upgradeRisks": "Upgrade risks",
"version": "Version",
"veryLow": "Very Low",
"viewAffectedClusters": "View {clusters, plural, one {the affected cluster} other {# affected clusters}}",
Expand Down
47 changes: 47 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"nightly": "npm run deploy",
"start": "webpack serve --config config/dev.webpack.config.js",
"start:beta": "BETA=true npm start",
"start:proxy:beta": "npm run start:beta",
"start:beta:mock": "BETA=true MOCK=true npm start",
"test:ct": "BABEL_ENV=component cypress run --component",
"test:jest": "TZ=UTC jest --verbose --passWithNoTests --no-cache",
Expand All @@ -35,6 +36,7 @@
"@redhat-cloud-services/frontend-components-utilities": "^3.3.13",
"@redhat-cloud-services/rule-components": "^3.2.6",
"@reduxjs/toolkit": "1.8.6",
"@unleash/proxy-client-react": "^3.5.2",
"axios": "^0.27.2",
"babel-plugin-formatjs": "^10.3.31",
"classnames": "^2.3.1",
Expand Down
119 changes: 68 additions & 51 deletions src/Components/Cluster/Cluster.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
checkNoMatchingRecs,
checkRowCounts,
} from '../../../cypress/utils/table';
import FlagProvider from '@unleash/proxy-client-react';

// selectors
const CLUSTER_HEADER = '#cluster-header';
Expand Down Expand Up @@ -42,13 +43,15 @@ describe('cluster page', () => {

it('cluster page in the successful state', () => {
mount(
<MemoryRouter>
<Intl>
<Provider store={getStore()}>
<Cluster {...props} />
</Provider>
</Intl>
</MemoryRouter>
<FlagProvider>
<MemoryRouter>
<Intl>
<Provider store={getStore()}>
<Cluster {...props} />
</Provider>
</Intl>
</MemoryRouter>
</FlagProvider>
);
// renders breadcrumbs
cy.get(BREADCRUMBS)
Expand All @@ -74,13 +77,15 @@ describe('cluster page', () => {
},
};
mount(
<MemoryRouter>
<Intl>
<Provider store={getStore()}>
<Cluster {...props} />
</Provider>
</Intl>
</MemoryRouter>
<FlagProvider>
<MemoryRouter>
<Intl>
<Provider store={getStore()}>
<Cluster {...props} />
</Provider>
</Intl>
</MemoryRouter>
</FlagProvider>
);
// renders breadcrumbs
cy.get(BREADCRUMBS).should('have.length', 1);
Expand All @@ -103,13 +108,15 @@ describe('cluster page', () => {
},
};
mount(
<MemoryRouter>
<Intl>
<Provider store={getStore()}>
<Cluster {...props} />
</Provider>
</Intl>
</MemoryRouter>
<FlagProvider>
<MemoryRouter>
<Intl>
<Provider store={getStore()}>
<Cluster {...props} />
</Provider>
</Intl>
</MemoryRouter>
</FlagProvider>
);
// renders breadcrumbs
cy.get(BREADCRUMBS).should('have.length', 1);
Expand All @@ -122,13 +129,17 @@ describe('cluster page', () => {

it('adds additional filters passed by the query parameters №1', () => {
mount(
<MemoryRouter initialEntries={['?total_risk=1&text=foo+bar&category=2']}>
<Intl>
<Provider store={getStore()}>
<Cluster {...props} />
</Provider>
</Intl>
</MemoryRouter>
<FlagProvider>
<MemoryRouter
initialEntries={['?total_risk=1&text=foo+bar&category=2']}
>
<Intl>
<Provider store={getStore()}>
<Cluster {...props} />
</Provider>
</Intl>
</MemoryRouter>
</FlagProvider>
);
cy.get(BREADCRUMBS);
cy.get(CLUSTER_HEADER);
Expand All @@ -141,13 +152,15 @@ describe('cluster page', () => {

it('adds additional filters passed by the query parameters №2', () => {
mount(
<MemoryRouter initialEntries={['?total_risk=2&text=foo&category=1']}>
<Intl>
<Provider store={getStore()}>
<Cluster {...props} />
</Provider>
</Intl>
</MemoryRouter>
<FlagProvider>
<MemoryRouter initialEntries={['?total_risk=2&text=foo&category=1']}>
<Intl>
<Provider store={getStore()}>
<Cluster {...props} />
</Provider>
</Intl>
</MemoryRouter>
</FlagProvider>
);
cy.get(BREADCRUMBS);
cy.get(CLUSTER_HEADER);
Expand Down Expand Up @@ -180,13 +193,15 @@ describe('Cluster page display name test №1', () => {

it('Cluster breadcrumbs name should be Cluster With Issues', () => {
mount(
<MemoryRouter>
<Intl>
<Provider store={getStore()}>
<Cluster {...props} />
</Provider>
</Intl>
</MemoryRouter>
<FlagProvider>
<MemoryRouter>
<Intl>
<Provider store={getStore()}>
<Cluster {...props} />
</Provider>
</Intl>
</MemoryRouter>
</FlagProvider>
);
cy.get(BREADCRUMBS)
.should('have.length', 1)
Expand All @@ -196,15 +211,17 @@ describe('Cluster page display name test №1', () => {

it('Cluster breadcrumbs name should be = Cluster Id', () => {
mount(
<MemoryRouter>
<Intl>
<Provider store={getStore()}>
<Cluster
{...{ ...props, cluster: { ...props.cluster, data: null } }}
/>
</Provider>
</Intl>
</MemoryRouter>
<FlagProvider>
<MemoryRouter>
<Intl>
<Provider store={getStore()}>
<Cluster
{...{ ...props, cluster: { ...props.cluster, data: null } }}
/>
</Provider>
</Intl>
</MemoryRouter>
</FlagProvider>
);
cy.get(BREADCRUMBS)
.should('have.length', 1)
Expand Down
9 changes: 5 additions & 4 deletions src/Components/Cluster/Cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import PropTypes from 'prop-types';

import PageHeader from '@redhat-cloud-services/frontend-components/PageHeader';
import ClusterHeader from '../ClusterHeader';
import ClusterRules from '../ClusterRules/ClusterRules';
import Breadcrumbs from '../Breadcrumbs';
import ClusterTabs from '../ClusterTabs/ClusterTabs';
import { PageSection } from '@patternfly/react-core';

export const Cluster = ({ cluster, clusterId }) => {
// TODO: make breadcrumbs take display name from GET /cluster/id/info
Expand All @@ -18,9 +19,9 @@ export const Cluster = ({ cluster, clusterId }) => {
/>
<ClusterHeader />
</PageHeader>
<section className="pf-l-page__main-section pf-c-page__main-section">
<ClusterRules cluster={cluster} />
</section>
<PageSection>
<ClusterTabs cluster={cluster} />
</PageSection>
</React.Fragment>
);
};
Expand Down
64 changes: 64 additions & 0 deletions src/Components/ClusterTabs/ClusterTabs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Card, CardBody, Tab, Tabs } from '@patternfly/react-core';
import PropTypes from 'prop-types';
import React, { useState } from 'react';

import { useIntl } from 'react-intl';
import { useSearchParams } from 'react-router-dom';
import messages from '../../Messages';
import { setSearchParameter } from '../../Utilities/Helpers';
import { useUpgradeRisksFeatureFlag } from '../../Utilities/useFeatureFlag';
import ClusterRules from '../ClusterRules/ClusterRules';
import { ComingSoon } from '../MessageState/EmptyStates';

const CLUSTER_TABS = ['recommendations', 'upgrade_risks'];

const ClusterTabs = ({ cluster }) => {
const intl = useIntl();
const upgradeRisksEnabled = useUpgradeRisksFeatureFlag();
const [searchParams] = useSearchParams();

const [activeKey, setActiveKey] = useState(() => {
const activeTab = searchParams.get('active_tab');
return upgradeRisksEnabled
? CLUSTER_TABS.includes(activeTab)
? activeTab
: 'recommendations'
: 'recommendations';
});

return (
<Card isCompact>
<CardBody>
<Tabs
activeKey={activeKey}
onSelect={(event, key) => {
setSearchParameter('active_tab', key);
setActiveKey(key);
}}
aria-label="Cluster tabs"
>
<Tab
eventKey="recommendations"
title={intl.formatMessage(messages.recommendations)}
>
<ClusterRules cluster={cluster} />
</Tab>
{upgradeRisksEnabled && (
<Tab
eventKey="upgrade_risks"
title={intl.formatMessage(messages.upgradeRisks)}
>
<ComingSoon />
</Tab>
)}
</Tabs>
</CardBody>
</Card>
);
};

ClusterTabs.propTypes = {
cluster: PropTypes.object,
};

export default ClusterTabs;
5 changes: 5 additions & 0 deletions src/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,4 +642,9 @@ export default defineMessages({
defaultMessage:
'The risk of change is <strong>{ level }</strong>, because the change takes very little time to implement and there is minimal impact to system operations.',
},
upgradeRisks: {
id: 'upgradeRisks',
description: 'Upgrade risks text',
defaultMessage: 'Upgrade risks',
},
});
Loading

0 comments on commit c47ac72

Please sign in to comment.