Skip to content

Commit e6898b5

Browse files
Merge pull request #15636 from logonoff/OCPBUGS-63471-amenu-dropdown
OCPBUGS-63471: Render a button if there is 1 action
2 parents 3741376 + 002a496 commit e6898b5

File tree

6 files changed

+45
-27
lines changed

6 files changed

+45
-27
lines changed

frontend/packages/dev-console/integration-tests/features/customization/customization-of-pinned-resource.feature

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@ Feature: Customization of pre-pinned resources
1313
When user navigates to Cluster configuration page
1414
And user clicks on Developer tab
1515
Then user should see Pre-pinned navigation items section
16-
16+
1717
@regression @manual
1818
Scenario: When pre-pinned resources customization is not added: DC-02-TC02
1919
Given user is at "operator.openshift.io/v1" console details page
20-
And user selects "Customize" in the Actions menu
20+
And user clicks the "Customize" button in the page heading
2121
And user selects "Developer" tab in "Cluster configuration" page
2222
Then user should see default pins from extension under "Pinned Resources" in "Pre-pinned navigation items"
2323

2424
@regression @manual
2525
Scenario: When resource is selected for pre-pinned navigation: DC-02-TC03
2626
Given user is at "operator.openshift.io/v1" console details page
27-
And user selects "Customize" in the Actions menu
27+
And user clicks the "Customize" button in the page heading
2828
And user selects "Developer" tab in "Cluster configuration" page
2929
When user selects "Deployment" under "Resources" and added to "Pinned Resources"
3030
Then user should see "Deployment" resource details in "operator.openshift.io/v1" console YAML under spec.customization.perspectives.id.pinnedResources for id 'dev'
31-
31+
3232
@regression @manual
3333
Scenario: When resource is removed from pre-pinned navigation: DC-02-TC04
3434
Given user is at "operator.openshift.io/v1" console details page
35-
And user selects "Customize" in the Actions menu
35+
And user clicks the "Customize" button in the page heading
3636
And user selects "Developer" tab in "Cluster configuration" page
3737
When user selects "Deployment" under "Pinned Resources" and moved back "Resources"
3838
Then user should not see "Deployment" resource details in "operator.openshift.io/v1" console YAML under spec.customization.perspectives.id.pinnedResources for id 'dev'

frontend/packages/dev-console/integration-tests/features/e2e/enable-dev-perspective-ci.feature

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ Feature: Enable dev perspective
66
Given user has only admin perspective enabled
77
And user has logged in as admin user
88

9-
9+
1010
Scenario: Enable dev perspective: P-01-TC04
1111
Given user is at admin perspective
1212
And user is at Search page in Home section
1313
And user searches "console"
1414
And user clicks on cluster
15-
And user selects "Customize" from actions menu
15+
And user clicks the "Customize" button in the page heading
1616
And user selects "Enabled" in the Developer under perspective section of general customisation
1717
Then user will see Saved alert
1818
And user refreshes the page to see developer option
1919
And user will see developer perspective in the perspective switcher
20-

frontend/packages/dev-console/integration-tests/features/perspectives/configure-perspectives.feature

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Feature: Configure perspectives
55

66
Background:
77
Given user has logged in as admin user
8-
8+
99
@regression @manual
1010
Scenario: Configuring available perspectives: P-01-TC01
1111
Given user is at cluster YAML of "operator.openshift.io/v1" console
@@ -45,9 +45,8 @@ Feature: Configure perspectives
4545
And user searches "console"
4646
And user clicks on cluster
4747
# And user selects "operator.openshift.io" console
48-
And user selects "Customize" from actions menu
48+
And user clicks the "Customize" button in the page heading
4949
And user selects "Enabled" in the Developer under perspective section of general customisation
5050
Then user will see Saved alert
5151
And user refreshes the page to see developer option
5252
And user will see developer perspective in the perspective switcher
53-

frontend/packages/dev-console/integration-tests/support/step-definitions/customization/configure-perspectives.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ When('user clicks on cluster', () => {
7070
cy.byTestID('cluster').should('be.visible').click({ force: true });
7171
});
7272

73-
When('user selects {string} from actions menu', (item: string) => {
74-
cy.byLegacyTestID('actions-menu-button').should('be.visible').click();
75-
cy.get(`[data-test-action="${item}"] button`).should('be.visible').click();
73+
When('user clicks the {string} button in the page heading', (item: string) => {
74+
cy.get(`button[data-test-action="${item}"]`).should('be.visible').click();
7675
cy.get('[data-test="page-heading"] h1').should('have.text', 'Cluster configuration');
7776
});
7877

frontend/public/components/utils/actions-menu.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,31 @@ import {
33
impersonateStateToProps,
44
useSafetyFirst,
55
} from '@console/dynamic-plugin-sdk';
6-
import { Dropdown, MenuToggle, MenuToggleElement } from '@patternfly/react-core';
6+
import { Button, Dropdown, MenuToggle, MenuToggleElement } from '@patternfly/react-core';
77
import { some } from 'lodash-es';
88
import { useTranslation } from 'react-i18next';
99
import { connect } from 'react-redux';
1010
import { useNavigate } from 'react-router-dom-v5-compat';
1111

1212
import { ReactNode, RefObject, useEffect, useState } from 'react';
13-
import { KebabItems, KebabOption } from './kebab';
13+
import { KebabItem, KebabItems, KebabOption } from './kebab';
1414
import { checkAccess } from './rbac';
1515

1616
type ActionsMenuProps = {
1717
actions: KebabOption[];
1818
title?: ReactNode;
1919
};
2020

21-
const ActionsMenuDropdown = (props) => {
21+
type ActionsMenuDropdownProps = {
22+
actions: KebabOption[];
23+
title?: ReactNode;
24+
active?: boolean;
25+
};
26+
27+
const ActionsMenuDropdown: React.FCC<ActionsMenuDropdownProps> = ({ actions, title, active }) => {
2228
const { t } = useTranslation();
2329
const navigate = useNavigate();
24-
const [active, setActive] = useState(!!props.active);
30+
const [isActive, setIsActive] = useState(!!active);
2531

2632
const onClick = (event, option) => {
2733
event.preventDefault();
@@ -34,14 +40,22 @@ const ActionsMenuDropdown = (props) => {
3440
navigate(option.href);
3541
}
3642

37-
setActive(false);
43+
setIsActive(false);
3844
};
3945

46+
if (actions.length === 0) {
47+
return null;
48+
}
49+
50+
if (actions.length === 1) {
51+
return <KebabItem option={actions[0]} onClick={onClick} Component={Button} />;
52+
}
53+
4054
return (
4155
<Dropdown
42-
isOpen={active}
43-
onSelect={() => setActive(false)}
44-
onOpenChange={setActive}
56+
isOpen={isActive}
57+
onSelect={() => setIsActive(false)}
58+
onOpenChange={setIsActive}
4559
shouldFocusToggleOnSelect
4660
popperProps={{
4761
enableFlip: true,
@@ -50,15 +64,15 @@ const ActionsMenuDropdown = (props) => {
5064
toggle={(toggleRef: RefObject<MenuToggleElement>) => (
5165
<MenuToggle
5266
ref={toggleRef}
53-
onClick={() => setActive(!active)}
67+
onClick={() => setIsActive(!active)}
5468
isExpanded={active}
5569
data-test-id="actions-menu-button"
5670
>
57-
{props.title || t('public~Actions')}
71+
{title || t('public~Actions')}
5872
</MenuToggle>
5973
)}
6074
>
61-
<KebabItems options={props.actions} onClick={onClick} />
75+
<KebabItems options={actions} onClick={onClick} />
6276
</Dropdown>
6377
);
6478
};

frontend/public/components/utils/kebab.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,20 @@ const KebabItem_: React.FC<KebabItemProps & { isAllowed: boolean }> = ({
8888
onClick,
8989
autoFocus,
9090
isAllowed,
91+
Component = DropdownItem,
9192
}) => {
9293
const { t } = useTranslation();
9394
const isDisabled = !isAllowed || option.isDisabled || (!option.href && !option.callback);
9495
return (
95-
<DropdownItem
96+
<Component
9697
onClick={(e) => !isDisabled && onClick(e, option)}
9798
autoFocus={autoFocus}
9899
isDisabled={isDisabled}
99100
data-test-action={option.labelKey ? t(option.labelKey, option.labelKind) : option.label}
100101
icon={option.icon}
101102
>
102103
{option.labelKey ? t(option.labelKey, option.labelKind) : option.label}
103-
</DropdownItem>
104+
</Component>
104105
);
105106
};
106107
export const KebabItemAccessReview_ = (
@@ -456,6 +457,12 @@ type KebabItemProps = {
456457
option: KebabOption;
457458
onClick: (event: React.MouseEvent<{}>, option: KebabOption) => void;
458459
autoFocus?: boolean;
460+
Component?: React.ComponentType<
461+
Pick<
462+
React.ComponentProps<typeof DropdownItem>,
463+
'onClick' | 'isDisabled' | 'autoFocus' | 'children' | 'icon'
464+
>
465+
>;
459466
};
460467

461468
export type KebabItemsProps = {

0 commit comments

Comments
 (0)