Skip to content

Refactor: Policy Editor - #4436

Merged
MuhammadKhalilzadeh merged 10 commits into
developfrom
refactor/policy-editor-theme-split
Aug 12, 2026
Merged

Refactor: Policy Editor#4436
MuhammadKhalilzadeh merged 10 commits into
developfrom
refactor/policy-editor-theme-split

Conversation

@Br0wnHammer

Copy link
Copy Markdown
Member

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:

  • I deployed the code locally.
  • I have performed a self-review of my code.
  • I have included the issue # in the PR.
  • I have labelled the PR correctly.
  • The issue I am working on is assigned to me.
  • I have avoided using hardcoded values to ensure scalability and maintain consistency across the application.
  • I have ensured that font sizes, color choices, and other UI elements are referenced from the theme.
  • My pull request is focused and addresses a single, specific feature.
  • If there are UI changes, I have attached a screenshot or video to this PR.
  • If I added or modified an API endpoint, the change is reflected in the generated OpenAPI spec (npm run generate:swagger).
  • If the endpoint requires authentication, it uses authenticateJWT and the generated spec declares bearerAuth security.
  • I ran npm run check:api-drift and committed the regenerated swagger.yaml and endpoints.ts.
  • If this PR adds or modifies an organization-scoped table, the tenant isolation registry and test matrix are updated. See the tenant isolation runbook for details.

@Br0wnHammer Br0wnHammer added this to the 2.5 milestone Aug 6, 2026
@Br0wnHammer Br0wnHammer self-assigned this Aug 6, 2026
@Br0wnHammer Br0wnHammer added enhancement New feature or request frontend Frontend related tasks/issues labels Aug 6, 2026
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

✅ Coverage Gate Passed

All coverage thresholds are met.

gorkem-bwl and others added 3 commits August 7, 2026 16:20
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
MuhammadKhalilzadeh merged commit 8d115bb into develop Aug 12, 2026
22 checks passed
@MuhammadKhalilzadeh
MuhammadKhalilzadeh deleted the refactor/policy-editor-theme-split branch August 12, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request frontend Frontend related tasks/issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants