fix(web): open IP policies for editing from rows (SNP-833)

This commit is contained in:
CodingOnStar committed 2026-09-20 17:27:40 +08:00
1 parent c1944ca09a
commit bbfca74704
3 files changed
+45 -20

No files matched your search

@@ -516,4 +516,29 @@ describe('IpPoliciesPage', () => {
}
},
)
it.each(['owner', 'admin'] as const)(
'opens edit directly from the policy row for %s',
async (role) => {
const user = userEvent.setup()
const queryClient = createConsoleQueryClient()
seedNetworkAccessGroups(queryClient, { groups: [createNetworkAccessGroupFixture()] })
renderWithConsoleQuery(
<NuqsTestingAdapter>
<IpPoliciesPage />
</NuqsTestingAdapter>,
{
queryClient,
currentWorkspace: { role },
systemFeatures: { deployment_edition: 'CLOUD' },
},
)
await user.click(screen.getByRole('button', { name: 'Internal Network' }))
expect(screen.getByRole('dialog', { name: 'Edit IP Policy' })).toBeInTheDocument()
expect(screen.getByRole('textbox', { name: 'Name' })).toHaveValue('Internal Network')
await user.keyboard('{Escape}')
await user.click(screen.getByRole('button', { name: 'More actions for Internal Network' }))
expect(screen.getByRole('menuitem', { name: 'Delete' })).toBeInTheDocument()
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
},
)
})
@@ -156,7 +156,7 @@ export default function IpPoliciesPage() {
key={group.id}
group={group}
canMutate={canMutate}
onView={(group) => setDialogState({ mode: 'view', group })}
onView={(group) => setDialogState({ mode: canMutate ? 'edit' : 'view', group })}
onEdit={(group) => {
if (!canMutate) return
setDialogState({ mode: 'edit', group })
@@ -78,25 +78,25 @@ export function PolicyItem({ group, canMutate, onView, onEdit }: PolicyItemProps
return (
<div className={`${policyRowClassName} border-b border-divider-subtle py-3`}>
<div className={policyNameColClassName}>
<Button
variant="ghost"
size="small"
className="h-auto max-w-full justify-start p-0 text-text-secondary"
onClick={() => onView(group)}
>
<span className="truncate">{group.name}</span>
</Button>
</div>
<p className={`${policyIpEntriesColClassName} system-sm-regular text-text-tertiary`}>
{group.allowed_cidrs.length}
</p>
<p className={`${policyEnforcingColClassName} system-sm-regular text-text-tertiary`}>
{enforcingLabel}
</p>
<p className={`${policyUpdatedColClassName} system-sm-regular text-text-tertiary`}>
{formatTimeFromNow(Date.parse(group.updated_at))}
</p>
<Button
variant="ghost"
aria-label={group.name}
className="h-auto min-w-0 flex-1 justify-start gap-0 rounded-none p-0 text-left"
onClick={() => onView(group)}
>
<span className={`${policyNameColClassName} system-sm-medium text-text-secondary`}>
{group.name}
</span>
<span className={`${policyIpEntriesColClassName} system-sm-regular text-text-tertiary`}>
{group.allowed_cidrs.length}
</span>
<span className={`${policyEnforcingColClassName} system-sm-regular text-text-tertiary`}>
{enforcingLabel}
</span>
<span className={`${policyUpdatedColClassName} system-sm-regular text-text-tertiary`}>
{formatTimeFromNow(Date.parse(group.updated_at))}
</span>
</Button>
<div className={policyActionsColClassName}>
{canMutate && (
<DropdownMenu open={menuOpen} onOpenChange={setMenuOpen}>