fix(web): route IP policy references to bound agents (SNP-829)

This commit is contained in:
CodingOnStar committed 2026-09-20 17:28:27 +08:00
1 parent 94a15b17d6
commit e58d4f3ff6
2 files changed
+66 -1

No files matched your search

@@ -567,4 +567,65 @@ describe('IpPoliciesPage', () => {
expect(screen.queryByText('Enforcing')).not.toBeInTheDocument()
},
)
it.each(['view', 'edit', 'delete'] as const)(
'links agent and regular app references correctly in %s',
async (mode) => {
const user = userEvent.setup()
const queryClient = createConsoleQueryClient()
seedNetworkAccessGroups(queryClient, {
groups: [
createNetworkAccessGroupFixture({
used_by_count: 2,
enforcing_count: 1,
apps: [
{
id: 'backing-app',
bound_agent_id: 'agent-1',
name: 'New Agent',
mode: 'workflow',
icon: null,
icon_type: null,
icon_background: null,
},
{
id: 'app-2',
name: 'Workflow',
mode: 'workflow',
icon: null,
icon_type: null,
icon_background: null,
},
],
}),
],
})
renderWithConsoleQuery(
<NuqsTestingAdapter>
<IpPoliciesPage />
</NuqsTestingAdapter>,
{
queryClient,
currentWorkspace: { role: mode === 'view' ? 'editor' : 'owner' },
systemFeatures: { deployment_edition: 'CLOUD' },
},
)
if (mode === 'delete') {
await user.click(screen.getByRole('button', { name: 'More actions for Internal Network' }))
await user.click(screen.getByRole('menuitem', { name: 'Delete' }))
expect(screen.getByText('Still used by 2 apps')).toBeInTheDocument()
} else {
await user.click(screen.getByRole('button', { name: 'Internal Network' }))
}
expect(screen.getByRole('link', { name: 'New Agent' })).toHaveAttribute(
'href',
'/agents/agent-1/configure',
)
expect(screen.getByRole('link', { name: 'New Agent' })).toHaveAttribute('target', '_blank')
expect(screen.getByRole('link', { name: 'Workflow' })).toHaveAttribute(
'href',
'/app/app-2/overview',
)
},
)
})
@@ -32,7 +32,11 @@ export function PolicyReferencedApps({ apps, usedByCount }: PolicyReferencedApps
{apps.map((app) => (
<li key={app.id} className="max-w-full min-w-0">
<a
href={`/app/${app.id}/overview`}
href={
app.bound_agent_id
? `/agents/${app.bound_agent_id}/configure`
: `/app/${app.id}/overview`
}
target="_blank"
rel="noreferrer"
className="flex min-h-7 max-w-full items-center gap-1.5 rounded-md border border-components-panel-border-subtle bg-background-default py-1 pr-1.5 pl-1 outline-hidden hover:bg-state-base-hover focus-visible:ring-2 focus-visible:ring-state-accent-solid"