Skip to content

Commit

Permalink
fix(ui): hide resource actions menu if it's empty
Browse files Browse the repository at this point in the history
Signed-off-by: cef <moncef.abboud95@gmail.com>
  • Loading branch information
CefBoud committed Sep 21, 2024
1 parent 5f23bb6 commit 8c5bc5d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 34 deletions.
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>

Check failure on line 688 in ui/src/app/applications/components/utils.tsx

View workflow job for this annotation

GitHub Actions / Build, test & lint UI code

Delete `····`
{menuItems.map((item, i) => (

Check failure on line 689 in ui/src/app/applications/components/utils.tsx

View workflow job for this annotation

GitHub Actions / Build, test & lint UI code

Delete `····`
<li

Check failure on line 690 in ui/src/app/applications/components/utils.tsx

View workflow job for this annotation

GitHub Actions / Build, test & lint UI code

Delete `····`
className={classNames('application-details__action-menu', {disabled: item.disabled})}

Check failure on line 691 in ui/src/app/applications/components/utils.tsx

View workflow job for this annotation

GitHub Actions / Build, test & lint UI code

Delete `····`
key={i}

Check failure on line 692 in ui/src/app/applications/components/utils.tsx

View workflow job for this annotation

GitHub Actions / Build, test & lint UI code

Delete `····`
onClick={e => {

Check failure on line 693 in ui/src/app/applications/components/utils.tsx

View workflow job for this annotation

GitHub Actions / Build, test & lint UI code

Delete `····`
e.stopPropagation();

Check failure on line 694 in ui/src/app/applications/components/utils.tsx

View workflow job for this annotation

GitHub Actions / Build, test & lint UI code

Delete `····`
if (!item.disabled) {

Check failure on line 695 in ui/src/app/applications/components/utils.tsx

View workflow job for this annotation

GitHub Actions / Build, test & lint UI code

Delete `····`
item.action();

Check failure on line 696 in ui/src/app/applications/components/utils.tsx

View workflow job for this annotation

GitHub Actions / Build, test & lint UI code

Delete `····`
document.body.click();

Check failure on line 697 in ui/src/app/applications/components/utils.tsx

View workflow job for this annotation

GitHub Actions / Build, test & lint UI code

Delete `····`
}
}}>
{item.iconClassName && <i className={item.iconClassName} />} {item.title}
</li>
))}
</ul>
);
}

Expand Down

0 comments on commit 8c5bc5d

Please sign in to comment.