Skip to content

Commit

Permalink
feat: [M3-8703] - Disable VPC Action Buttons for Restricted Users (#1…
Browse files Browse the repository at this point in the history
…1072)

* feat: [M3-8703] - Disable VPC Action Buttons for Restricted Users

* Added changeset: Disable VPC Action Buttons for Restricted Users
  • Loading branch information
hasyed-akamai authored Oct 9, 2024
1 parent 8cd0333 commit 66e7823
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-11072-changed-1728479835625.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Changed
---

Disable VPC Action Buttons for Restricted Users ([#11072](https://github.com/linode/manager/pull/11072))
26 changes: 26 additions & 0 deletions packages/manager/src/features/VPCs/VPCLanding/VPCRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { InlineMenuAction } from 'src/components/InlineMenuAction/InlineMenuActi
import { TableCell } from 'src/components/TableCell';
import { TableRow } from 'src/components/TableRow';
import { useRegionsQuery } from 'src/queries/regions/regions';
import { getRestrictedResourceText } from 'src/features/Account/utils';
import { useIsResourceRestricted } from 'src/hooks/useIsResourceRestricted';

interface Props {
handleDeleteVPC: () => void;
Expand All @@ -25,14 +27,36 @@ export const VPCRow = ({ handleDeleteVPC, handleEditVPC, vpc }: Props) => {
0
);

const isVPCReadOnly = useIsResourceRestricted({
grantLevel: 'read_only',
grantType: 'vpc',
id: vpc.id,
});

const actions: Action[] = [
{
onClick: handleEditVPC,
title: 'Edit',
disabled: isVPCReadOnly,
tooltip: isVPCReadOnly
? getRestrictedResourceText({
action: 'edit',
isSingular: true,
resourceType: 'VPCs',
})
: undefined,
},
{
onClick: handleDeleteVPC,
title: 'Delete',
disabled: isVPCReadOnly,
tooltip: isVPCReadOnly
? getRestrictedResourceText({
action: 'delete',
isSingular: true,
resourceType: 'VPCs',
})
: undefined,
},
];

Expand All @@ -55,8 +79,10 @@ export const VPCRow = ({ handleDeleteVPC, handleEditVPC, vpc }: Props) => {
{actions.map((action) => (
<InlineMenuAction
actionText={action.title}
disabled={action.disabled}
key={action.title}
onClick={action.onClick}
tooltip={action.tooltip}
/>
))}
</TableCell>
Expand Down

0 comments on commit 66e7823

Please sign in to comment.