From 2b735804bb44f91fdad36a937e02dc1d90c63ea1 Mon Sep 17 00:00:00 2001 From: Fewwy <62722417+Fewwy@users.noreply.github.com> Date: Mon, 28 Mar 2022 16:43:49 +0200 Subject: [PATCH] feat(Single cluster page): View in clusters button (#192) --- compiled-lang/en.json | 2 + src/App.scss | 4 ++ src/Components/ClusterHeader/ClusterHeader.js | 38 ++++++++++++++++++- .../ClusterHeader/ClusterHeader.spec.ct.js | 11 ++++++ src/Messages.js | 11 ++++++ 5 files changed, 64 insertions(+), 2 deletions(-) diff --git a/compiled-lang/en.json b/compiled-lang/en.json index 1ee13f8d..2deb3589 100644 --- a/compiled-lang/en.json +++ b/compiled-lang/en.json @@ -4,6 +4,7 @@ "all": "All", "cancel": "Cancel", "category": "Category", + "clusterDetailsRedirect": "View cluster details", "clusterName": "Cluster name", "clusters": "Clusters", "comingSoonBody": "We’re currently working on this page. In the meantime, you can visit the Insights Advisor recommendations page to view potential issues with your clusters.", @@ -17,6 +18,7 @@ "disableRuleSingleCluster": "Disable only for this cluster", "disabled": "Disabled", "documentTitle": "{subnav} - OCP Advisor | Red Hat Insights", + "dropDownActionSingleCluster": "Action", "enable": "Enable", "enableRule": "Enable recommendation", "enableRuleForClusters": "Enable this recommendation for all clusters", diff --git a/src/App.scss b/src/App.scss index e96f3207..d51ad67c 100644 --- a/src/App.scss +++ b/src/App.scss @@ -12,4 +12,8 @@ .pf-c-table tr > *:first-child { --pf-c-table--cell--PaddingLeft: 1rem; --pf-c-table--cell--PaddingRight: 1rem; +} + +#cluster-header-dropdown { + justify-self: end; } \ No newline at end of file diff --git a/src/Components/ClusterHeader/ClusterHeader.js b/src/Components/ClusterHeader/ClusterHeader.js index 9a718dc2..58784e0d 100644 --- a/src/Components/ClusterHeader/ClusterHeader.js +++ b/src/Components/ClusterHeader/ClusterHeader.js @@ -1,10 +1,11 @@ -import React from 'react'; +import React, { useState } from 'react'; import PropTypes from 'prop-types'; import { useIntl } from 'react-intl'; import { Grid, GridItem } from '@patternfly/react-core/dist/js/layouts/Grid'; import { Stack, StackItem } from '@patternfly/react-core/dist/js/layouts/Stack'; import { Title } from '@patternfly/react-core/dist/js/components/Title'; +import { Dropdown, DropdownToggle, DropdownItem } from '@patternfly/react-core'; import Skeleton from '@redhat-cloud-services/frontend-components/Skeleton'; import DateFormat from '@redhat-cloud-services/frontend-components/DateFormat/DateFormat'; @@ -12,6 +13,8 @@ import messages from '../../Messages'; import { OneLineLoader } from '../../Utilities/Loaders'; export const ClusterHeader = ({ clusterId, clusterData }) => { + const location = window.location; + const [isOpen, setIsOpen] = useState(false); const intl = useIntl(); // subscribe to the cluster data query const { @@ -20,9 +23,23 @@ export const ClusterHeader = ({ clusterId, clusterData }) => { data: cluster, } = clusterData; + const redirectOCM = (clusterId) => { + location.assign( + location.origin + + (location.pathname.includes('beta') ? `/beta` : '') + + `/openshift/details/${clusterId}` + ); + }; + + const dropDownItems = [ + redirectOCM(clusterId)}> + {intl.formatMessage(messages.clusterDetailsRedirect)} + , + ]; + return ( - + {isUninitializedCluster || isFetchingCluster ? ( ) : ( @@ -36,6 +53,23 @@ export const ClusterHeader = ({ clusterId, clusterData }) => { )} + + setIsOpen(!isOpen)} + autoFocus={false} + isOpen={isOpen} + toggle={ + setIsOpen(isOpen)} + > + {intl.formatMessage(messages.dropDownActionSingleCluster)} + + } + dropdownItems={dropDownItems} + /> + diff --git a/src/Components/ClusterHeader/ClusterHeader.spec.ct.js b/src/Components/ClusterHeader/ClusterHeader.spec.ct.js index bc5223ef..a9543491 100644 --- a/src/Components/ClusterHeader/ClusterHeader.spec.ct.js +++ b/src/Components/ClusterHeader/ClusterHeader.spec.ct.js @@ -78,4 +78,15 @@ describe('cluster page header', () => { // check uuid text cy.get(UUID_FIELD).should('have.text', 'foobar'); }); + + it('action redirect button works', () => { + mount( + + + + ); + cy.get('.pf-c-dropdown__toggle').click(); + cy.get('a[class=pf-c-dropdown__menu-item]').click(); + cy.url().should('include', 'openshift/details/' + props.clusterId); + }); }); diff --git a/src/Messages.js b/src/Messages.js index 03061d90..02f88f53 100644 --- a/src/Messages.js +++ b/src/Messages.js @@ -189,6 +189,12 @@ export default defineMessages({ description: 'Filter action, reset all filter chips', defaultMessage: 'Reset filters', }, + clusterDetailsRedirect: { + id: 'clusterDetailsRedirect', + description: + 'Dropdown on the single cluster page, redirects user to the OCM', + defaultMessage: 'View cluster details', + }, noMatchingRecsTitle: { id: 'noMatchingRecommendationsTitle', defaultMessage: 'No matching recommendations found', @@ -431,6 +437,11 @@ export default defineMessages({ 'Explaining the action of disabling a recommendation for a single cluster', defaultMessage: 'Disable only for this cluster', }, + dropDownActionSingleCluster: { + id: 'dropDownActionSingleCluster', + description: 'Default text for the dropdown on the single cluster page', + defaultMessage: 'Action', + }, disableRuleBody: { id: 'disableRuleBody', description: 'Explaining the action of disabling a recommendation',