Refactor: Policy Editor - #4436
Merged
MuhammadKhalilzadeh merged 10 commits intoAug 12, 2026
Merged
Conversation
…eader/PolicyToolbar
…from PolicyEditorPage
…nents, tokenize colors, and update save state from server response
✅ Coverage Gate PassedAll coverage thresholds are met. |
The refactor's new save flow wrote the full server response back into policy state via setPolicy(savedPolicy). Because policy.content_html seeds initialContent — the sole dependency of the TipTap useEditor([initialContent]) — adopting the server's re-serialized/sanitized HTML changed that dep and tore down and recreated the editor on every save. That reset cursor, selection, scroll and undo/redo history, and silently dropped any edits typed while a save was in flight (the rebuild reseeds from the server content, never from the live editor). - usePolicySave: on success, merge the server metadata (status, last_updated_at, etc.) but preserve the existing content_html so initialContent stays stable and the editor instance persists across saves. The live editor already holds the authoritative content. - PolicyEditorPage: the 'populate form from policy' effect now seeds formData.content from policy.content_html only when a different policy loads (tracked by id), not on same-policy churn such as a post-save setPolicy, so formData.content no longer reverts to the pre-save HTML. Also corrects the usePolicySave JSDoc, which still described writing the server's content_html back to local state.
The project uses react-router v8, not react-router-dom. The wrong import broke the Frontend Checks typecheck.
MuhammadKhalilzadeh
approved these changes
Aug 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your changes
Refactors PolicyEditorPage (937 to 583 lines) into five co-located components and two hooks under
PolicyEditor/, with all hardcoded colors replaced by theme palette tokens. The save flow now applies the server response entity (status, last_updated_at, sanitized content) directly to local state, removing the refetch.Fixes No. 7 of #4150
Please ensure all items are checked off before requesting a review:
npm run generate:swagger).authenticateJWTand the generated spec declaresbearerAuthsecurity.npm run check:api-driftand committed the regeneratedswagger.yamlandendpoints.ts.