Fix #4762 - Fix API Publisher Policies page breaking after deleting a policy attached to a flow#1387
Fix #4762 - Fix API Publisher Policies page breaking after deleting a policy attached to a flow#1387Irash-Perera wants to merge 5 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis 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. ChangesPolicy deletion flow cleanup
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
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
portals/publisher/src/main/webapp/site/public/locales/en.jsonportals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/DeletePolicy.tsxportals/publisher/src/main/webapp/source/src/app/components/Apis/Details/Policies/Policies.tsx
|



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 stalepolicyIdwas 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.tsxisPolicyAttachedToAnyFlow(policyId)- checks whether the policy is attached to any flow (API level or any operation) in the local, possibly unsaved state.removePolicyFromAllFlows(policyId)- removes all attachments of the policy from the local flow state after it is deleted, so a stalepolicyIdcan never reach Save.ApiOperationContextprovider.DeletePolicy.tsxen.jsonApis.Details.Policies.DeletePolicy.delete.confirm.usedInFlowlocale entry.