Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mrc): fix <ActionMenu /> #14921

Open
wants to merge 1 commit into
base: release/mrc-v2-update
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ODS_BUTTON_VARIANT,
ODS_BUTTON_SIZE,
ODS_ICON_NAME,
ODS_BUTTON_COLOR,
} from '@ovhcloud/ods-components';
import { OdsButton, OdsPopover } from '@ovhcloud/ods-components/react';
import { useTranslation } from 'react-i18next';
Expand All @@ -13,6 +14,7 @@ import { ManagerButton } from '../../../ManagerButton/ManagerButton';
export interface ActionMenuItem {
id: number;
rel?: string;
href?: string;
download?: string;
target?: string;
onClick?: () => void;
Expand All @@ -21,6 +23,9 @@ export interface ActionMenuItem {
iamActions?: string[];
urn?: string;
className?: string;
isDisabled?: boolean;
isLoading?: boolean;
color?: ODS_BUTTON_COLOR;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
export interface ActionMenuItem {
id: number;
rel?: string;
href?: string;
download?: string;
target?: string;
onClick?: () => void;
label: string;
className?: string;
} & React.ComponentProps<typeof OdsButton>


export interface ActionMenuProps {
Expand All @@ -30,6 +35,7 @@ export interface ActionMenuProps {
variant?: ODS_BUTTON_VARIANT;
id: string;
isDisabled?: boolean;
isLoading?: boolean;
}

const MenuItem = ({
Expand All @@ -45,31 +51,22 @@ const MenuItem = ({
size: ODS_BUTTON_SIZE.sm,
variant: ODS_BUTTON_VARIANT.ghost,
displayTooltip: false,
className: 'w-full action-menu-item',
className: 'menu-item-button w-full',
...item,
};
return (
<div className="-mx-[2px]">
{!item?.iamActions || item?.iamActions?.length === 0 ? (
<OdsButton {...buttonProps} label={item.label}>
<span slot="start">
<span>{item.label}</span>
</span>
</OdsButton>
) : (
<ManagerButton
id={`${id}`}
isIamTrigger={isTrigger}
iamActions={item.iamActions}
urn={item.urn}
{...buttonProps}
>
<span slot="start">
<span>{item.label}</span>
</span>
</ManagerButton>
)}
</div>

if (item.href) {
return (
<a href={item.href} download={item.download}>
<OdsButton {...buttonProps} />
</a>
);
}

return !item?.iamActions || item?.iamActions?.length === 0 ? (
<OdsButton {...buttonProps} />
) : (
<ManagerButton id={`${id}`} isIamTrigger={isTrigger} {...buttonProps} />
);
};

Expand All @@ -79,21 +76,22 @@ export const ActionMenu: React.FC<ActionMenuProps> = ({
icon,
variant = ODS_BUTTON_VARIANT.outline,
isDisabled = false,
isLoading = false,
id,
}) => {
const { t } = useTranslation('buttons');
const [isTrigger, setIsTrigger] = React.useState(false);

return (
<>
<div key={id} id={`navigation-action-trigger-${id}`}>
<div key={id} id={`navigation-action-trigger-${id}`} className="w-min">
<OdsButton
data-testid="navigation-action-trigger-action"
className="action-menu-btn"
slot="menu-title"
id={id}
variant={variant}
isDisabled={isDisabled}
isLoading={isLoading}
size={ODS_BUTTON_SIZE.sm}
onClick={() => setIsTrigger(true)}
{...(!isCompact && { label: t('common_actions') })}
Expand All @@ -106,20 +104,20 @@ export const ActionMenu: React.FC<ActionMenuProps> = ({
/>
</div>
<OdsPopover
className="py-[8px] px-0 overflow-hidden"
className="py-[8px] px-0"
triggerId={`navigation-action-trigger-${id}`}
with-arrow
>
{items.map(({ id: itemId, ...item }) => {
return (
<div className="flex flex-col">
{items.map(({ id: itemId, ...item }) => (
<MenuItem
id={itemId}
key={itemId}
item={item}
isTrigger={isTrigger}
/>
);
})}
))}
</div>
</OdsPopover>
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Customize <OdsButton />
.menu-item-button {
&::part(button) {
width: 100%;
justify-content: left;
height: 32px;
border-radius: 0;
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
import React from 'react';
import { Meta } from '@storybook/react';
import { ActionMenu, ActionMenuProps } from './action.component';
import {
ActionMenu,
ActionMenuItem,
ActionMenuProps,
} from './action.component';

const actionItems = [
const actionItems: ActionMenuItem[] = [
{
id: 1,
href: 'https://ovhcloud.com',
href: 'https://www.ovhcloud.com',
target: '_blank',
label: 'Action 1',
urn: 'urn:v9:eu:resource:manager-react-components:vrz-a878-dsflkds-fdsfsd',
iamActions: ['vrackServices:apiovh:iam/resource/tag/remove'],
label: 'external link',
},
{
id: 2,
href: `data:text/json;charset=utf-8,${encodeURIComponent(
JSON.stringify({ name: 'john' }),
)}`,
download: 'test.json',
target: '_blank',
label: 'download',
},
{
id: 3,
href: 'https://ovhcloud.com',
target: '_blank',
label: 'disabled link',
isDisabled: true,
},
{
id: 4,
onClick: () => window.open('https://ovhcloud.com', '_blank', 'noopener'),
label: 'action',
},
{
id: 5,
onClick: () => window.open('https://ovhcloud.com', '_blank', 'noopener'),
label: 'Action 2',
label: 'action without iam permissions',
urn: 'urn:v9:eu:resource:manager-react-components:vrz-a878-dsflkds-fdsfsd',
iamActions: ['vrackServices:apiovh:iam/resource/tag/remove'],
},
Expand All @@ -27,6 +51,7 @@ export const actionMenuStandard = {
};

const meta: Meta<ActionMenuProps> = {
decorators: [(story) => <div className="h-52">{story()}</div>],
title: 'Navigation/Menus',
component: ActionMenu,
};
Expand Down
1 change: 1 addition & 0 deletions packages/manager-react-components/src/lib.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import './components/templates/error/error.scss';
@import './components/templates/update-name-modal/update-name-modal.scss';
@import './components/filters/filters.scss';
@import './components/navigation/menus/action/action.scss';
Loading