Skip to content

fix(policies): restore AI-tailoring UI on the Policies page (ENG-108)#2584

Merged
tofikwest merged 2 commits intomainfrom
tofik/eng-108-policies-tailoring-ui
Apr 16, 2026
Merged

fix(policies): restore AI-tailoring UI on the Policies page (ENG-108)#2584
tofikwest merged 2 commits intomainfrom
tofik/eng-108-policies-tailoring-ui

Conversation

@tofikwest
Copy link
Copy Markdown
Contributor

@tofikwest tofikwest commented Apr 16, 2026

Summary

Fixes ENG-108 — during first-run onboarding, the "AI is tailoring your policies" banner and per-row tailoring status disappeared from the Policies page. Vendors and Risks already got their equivalent restored; Policies was the last holdout.

Root cause

Commit 8974418c6 (Jan 2026 design-system migration) replaced the old PoliciesTable with PoliciesTableDS. The new flow wraps <PolicyFilters> in <PolicyTailoringProvider statuses={{}}> with an empty map, so PoliciesTableDS's existing per-row "Tailoring/Queued/Preparing" rendering had no data to show. The page also never fetched the onboarding triggerJobId, so there was nothing to subscribe to.

Fix

No trigger.dev pipeline changes — the backend still emits policiesTotal / policiesCompleted / policy_<id>_status exactly as before. Only the frontend wiring:

  1. New hook: apps/app/.../policies/(overview)/hooks/use-policy-onboarding-status.ts — mirrors the existing risks/vendors useOnboardingStatus but handles the singular/plural correctly (the shared hook's itemType.slice(0, -1) would have produced policie_, not policy_).

  2. policies/(overview)/page.tsx: fetch /v1/organization/onboarding alongside /v1/policies and pass the triggerJobId into PolicyFilters. Moved PolicyTailoringProvider out of the server component (where it had empty statuses) into PolicyFilters (client) where the realtime data lives.

  3. PolicyFilters.tsx: accept onboardingRunId, subscribe via the new hook, wrap children in PolicyTailoringProvider with live statuses, render the "Tailoring your policies — Personalized N/M" banner while the run is active.

Scope

  • No schema changes, no new DB fields.
  • No changes to the trigger.dev tasks or API endpoints.
  • The orphaned apps/app/.../policies/all/components/policies-table.tsx (pre-migration legacy table, imported by nothing) is left in place to keep this PR focused; it's a follow-up cleanup candidate.

Test plan

  • Typecheck clean on all touched files
  • Manual: trigger a fresh org onboarding and confirm:
    • Banner appears: "Tailoring your policies — Personalized X/Y policies"
    • Each row in the table shows "Tailoring" / "Queued" / "Preparing" badges per row (via existing PoliciesTableDS rendering)
    • When onboarding completes, the banner disappears and rows show normal status
  • Regression: on an org without an active onboarding run, the page renders exactly as before (no banner, no extra state)

🤖 Generated with Claude Code


Summary by cubic

Restores the “Tailoring your policies” banner and per-row tailoring badges on the Policies page during onboarding, addressing ENG-108. The page now streams onboarding progress so users see real-time status until completion.

  • Bug Fixes
    • Added usePolicyOnboardingStatus using @trigger.dev/react-hooks to expose policiesTotal, policiesCompleted, and policy_<id>_status.
    • Updated policies/(overview)/page.tsx to fetch /v1/organization/onboarding and pass onboardingRunId to PolicyFilters.
    • Moved PolicyTailoringProvider into PolicyFilters; added a progress banner; PoliciesTableDS now shows live per-row statuses.
    • No backend, API, or schema changes.

Written for commit 6d2434c. Summary will update on new commits.

…108)

The legacy PoliciesTable + PolicyFilters wiring was removed when we
migrated to PoliciesTableDS in Jan 2026 (commit 8974418). Since then
the page wrapped <PolicyFilters> in PolicyTailoringProvider with an
empty statuses map, so the per-row "Tailoring/Queued/Preparing" UI that
PoliciesTableDS already renders had no data to show. Vendors and Risks
were restored at the time; Policies was left missing.

Wires it back up without touching the trigger.dev pipeline (which still
emits policiesTotal/policiesCompleted/policy_<id>_status as before):

1. policies/(overview)/hooks/use-policy-onboarding-status.ts — new hook
   mirroring the risks/vendors ones, using useRealtimeRun. Handles the
   policies/policy singular/plural conversion correctly (the shared
   hook's `itemType.slice(0,-1)` would have produced "policie_").

2. policies/(overview)/page.tsx — fetch /v1/organization/onboarding
   alongside /v1/policies (same pattern as risks/vendors) and pass the
   trigger run id into PolicyFilters. Move PolicyTailoringProvider into
   PolicyFilters since that's where the realtime data lives.

3. PolicyFilters.tsx — accept onboardingRunId, subscribe via the hook,
   wrap children in PolicyTailoringProvider with live statuses, render
   the "Tailoring your policies – Personalized N/M" banner while the
   run is active.

Orphaned apps/app/.../policies/all/components/policies-table.tsx (the
pre-migration table, now dead code) is left in place for a follow-up
cleanup PR so this diff stays scoped.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@linear
Copy link
Copy Markdown

linear bot commented Apr 16, 2026

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
app Ready Ready Preview, Comment Apr 16, 2026 10:20pm
comp-framework-editor Ready Ready Preview, Comment Apr 16, 2026 10:20pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
portal Skipped Skipped Apr 16, 2026 10:20pm

Request Review

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

cubic analysis

No issues found across 3 files

Auto-approved: Restores lost AI-tailoring UI elements on the Policies page using existing patterns. Frontend-only change with no impact on core logic or data.

Linked issue analysis

Linked issue: ENG-108: The UI for indicating AI is working on Policies/Vendors/Risks is gone

Status Acceptance criteria Notes
Show "Tailoring your policies — Personalized X/Y policies" banner during active onboarding Banner JSX added and shows progress.completed/progress.total
Restore per-row tailoring status badges (Tailoring/Queued/Preparing) in Policies table rows PoliciesTableDS wrapped with PolicyTailoringProvider supplying statuses
Fetch onboarding triggerJobId on the Policies page and pass it to client component page.tsx fetches /v1/organization/onboarding and passes triggerJobId
Subscribe to realtime trigger.dev run and derive per-policy statuses (useRealtimeRun) New usePolicyOnboardingStatus hook uses useRealtimeRun and derives statuses
Ensure page renders unchanged for orgs without an active onboarding run (no banner/state) onboardingRunId null prevents subscription; showTailoringBanner false
Restore equivalent AI-tailoring UI for Vendors and Risks as well (Policies/Vendors/Risks) No diffs touching vendors/risks pages or hooks

@vercel vercel bot temporarily deployed to Preview – portal April 16, 2026 22:16 Inactive
@tofikwest tofikwest merged commit f1d8be1 into main Apr 16, 2026
10 of 11 checks passed
@tofikwest tofikwest deleted the tofik/eng-108-policies-tailoring-ui branch April 16, 2026 22:20
@claudfuen
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.23.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants