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(ui): hide resource actions menu if it's empty #20051

Merged
Merged
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 @@ -284,7 +284,8 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
const logsAllowed = await services.accounts.canI('logs', 'get', application.spec.project + '/' + application.metadata.name);
const execAllowed = execEnabled && (await services.accounts.canI('exec', 'create', application.spec.project + '/' + application.metadata.name));
const links = await services.applications.getResourceLinks(application.metadata.name, application.metadata.namespace, selectedNode).catch(() => null);
return {controlledState, liveState, events, podState, execEnabled, execAllowed, logsAllowed, links, childResources};
const resourceActionsMenuItems = await AppUtils.getResourceActionsMenuItems(selectedNode, application.metadata, appContext);
return {controlledState, liveState, events, podState, execEnabled, execAllowed, logsAllowed, links, childResources, resourceActionsMenuItems};
}}>
{data => (
<React.Fragment>
Expand Down Expand Up @@ -314,15 +315,17 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
className='argo-button argo-button--base'>
<i className='fa fa-trash' /> <span className='show-for-large'>DELETE</span>
</button>
<DropDown
isMenu={true}
anchor={() => (
<button className='argo-button argo-button--light argo-button--lg argo-button--short'>
<i className='fa fa-ellipsis-v' />
</button>
)}>
{() => AppUtils.renderResourceActionMenu(selectedNode, application, appContext)}
</DropDown>
{data.resourceActionsMenuItems?.length > 0 && (
<DropDown
isMenu={true}
anchor={() => (
<button className='argo-button argo-button--light argo-button--lg argo-button--short'>
<i className='fa fa-ellipsis-v' />
</button>
)}>
{() => AppUtils.renderResourceActionMenu(data.resourceActionsMenuItems)}
</DropDown>
)}
</div>
<Tabs
navTransparent={true}
Expand Down
42 changes: 18 additions & 24 deletions ui/src/app/applications/components/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ export const deletePopup = async (
);
};

function getResourceActionsMenuItems(resource: ResourceTreeNode, metadata: models.ObjectMeta, apis: ContextApis): Promise<ActionMenuItem[]> {
export function getResourceActionsMenuItems(resource: ResourceTreeNode, metadata: models.ObjectMeta, apis: ContextApis): Promise<ActionMenuItem[]> {
return services.applications
.getResourceActions(metadata.name, metadata.namespace, resource)
.then(actions => {
Expand Down Expand Up @@ -683,30 +683,24 @@ export function renderResourceMenu(
);
}

export function renderResourceActionMenu(resource: ResourceTreeNode, application: appModels.Application, apis: ContextApis): React.ReactNode {
const menuItems = getResourceActionsMenuItems(resource, application.metadata, apis);

export function renderResourceActionMenu(menuItems: ActionMenuItem[]): React.ReactNode {
return (
<DataLoader load={() => menuItems}>
{items => (
<ul>
{items.map((item, i) => (
<li
className={classNames('application-details__action-menu', {disabled: item.disabled})}
key={i}
onClick={e => {
e.stopPropagation();
if (!item.disabled) {
item.action();
document.body.click();
}
}}>
{item.iconClassName && <i className={item.iconClassName} />} {item.title}
</li>
))}
</ul>
)}
</DataLoader>
<ul>
{menuItems.map((item, i) => (
<li
className={classNames('application-details__action-menu', {disabled: item.disabled})}
key={i}
onClick={e => {
e.stopPropagation();
if (!item.disabled) {
item.action();
document.body.click();
}
}}>
{item.iconClassName && <i className={item.iconClassName} />} {item.title}
</li>
))}
</ul>
);
}

Expand Down