Skip to content

Fix #4762 - Fix API Publisher Policies page breaking after deleting a policy attached to a flow#1387

Open
Irash-Perera wants to merge 5 commits into
wso2:mainfrom
Irash-Perera:policy-deletion
Open

Fix #4762 - Fix API Publisher Policies page breaking after deleting a policy attached to a flow#1387
Irash-Perera wants to merge 5 commits into
wso2:mainfrom
Irash-Perera:policy-deletion

Conversation

@Irash-Perera

@Irash-Perera Irash-Perera commented Jul 8, 2026

Copy link
Copy Markdown

Purpose

Fixes wso2/api-manager#4762

Deleting a policy from the policy list did not remove its references from the unsaved request/response/fault flow state (apiOperations / apiLevelPolicies). The stale policyId was sent on Save, causing a "Selected api policy not found" error, and since the state was never cleaned, every subsequent Save failed until the page was reloaded.

There was also no warning when deleting a policy that was still attached to a flow.

Approach

  • Policies.tsx
    • Added isPolicyAttachedToAnyFlow(policyId) - checks whether the policy is attached to any flow (API level or any operation) in the local, possibly unsaved state.
    • Added removePolicyFromAllFlows(policyId) - removes all attachments of the policy from the local flow state after it is deleted, so a stale policyId can never reach Save.
    • Exposed both via the existing ApiOperationContext provider.
  • DeletePolicy.tsx
    • Shows a warning in the delete confirmation dialog when the policy is attached to a flow.
    • Prunes the policy from all flows after a successful backend deletion.
  • en.json
    • Added the Apis.Details.Policies.DeletePolicy.delete.confirm.usedInFlow locale entry.
Screenshot 2026-07-09 at 12 05 18

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 99310e15-01fa-434e-963b-6e0b75fdefc9

📥 Commits

Reviewing files that changed from the base of the PR and between 07453a6 and 9a8321c.

📒 Files selected for processing (1)
  • portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/DeletePolicy.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/DeletePolicy.tsx

📝 Walkthrough

Walkthrough

This PR detects policy flow associations, removes deleted policies from local flow state, and updates the deletion confirmation dialog with a localized warning when a policy is attached to flows.

Changes

Policy deletion flow cleanup

Layer / File(s) Summary
Context helpers for flow attachment detection and cleanup
portals/publisher/.../Policies/Policies.tsx
Adds helpers to detect and remove policies across API-level and operation-level state, exposing them through ApiOperationContextProvider.
DeletePolicy dialog integration and warning message
portals/publisher/.../Policies/DeletePolicy.tsx, portals/publisher/.../locales/en.json
Uses the helpers during deletion, cleans up flow references, conditionally displays a warning, and adds the supporting locale string.

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DeletePolicy
  participant ApiOperationContext
  participant Policies

  DeletePolicy->>ApiOperationContext: query policy flow attachment
  ApiOperationContext->>Policies: inspect policy state
  Policies-->>DeletePolicy: return attachment status
  DeletePolicy->>ApiOperationContext: remove policy from all flows
  ApiOperationContext->>Policies: update policy state
Loading

Suggested reviewers: lasanthas, krishanx92, tharikagithub, rakhitharr, heshansudarshana

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main fix: deleting a policy attached to a flow no longer breaks the Policies page.
Description check ✅ Passed The description is directly aligned with the policy-deletion flow-state bug and the added warning/locale changes.
Linked Issues check ✅ Passed The PR satisfies #4762 by removing deleted policy references from flow state and warning when the policy is attached to flows.
Out of Scope Changes check ✅ Passed The changes stay within the stated scope: context helpers, delete-flow cleanup, and the confirmation warning/localization.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/DeletePolicy.tsx`:
- Around line 69-70: The deletion flow in DeletePolicy.tsx is using a stale
`removePolicyFromAllFlows` callback captured at render time, which can overwrite
newer flow state after async deletion completes. Update `handleDelete` and the
dialog action path to read the latest callback from a `useRef` instead of
closing over the context function, and invoke that ref when
`removePolicyFromAllFlows` is needed. Make sure `useRef` is imported from React
if it is not already, and keep the ref in sync with the latest context value on
each render.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 550d0b4a-8d72-465f-9fbb-2d8301145829

📥 Commits

Reviewing files that changed from the base of the PR and between 8721231 and dacffcc.

📒 Files selected for processing (3)
  • portals/publisher/src/main/webapp/site/public/locales/en.json
  • portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/DeletePolicy.tsx
  • portals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/Policies.tsx

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 9, 2026
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API Publisher Policy page breaks after a policy deletion

1 participant