← Back to Pull requests

AAP-95973 XLAB Leaderboard achievement alert and refresh on new sync #3739

Closed
unknown closed this pull request without merging on Oct 12, 2026 17:17 UTC
View on GitHub
unknown unknown commented on Oct 09, 2026 08:03 UTC
Author

Summary


AAP-95973 Adds a "new achievements" alert to the Automation Dashboard → Leaderboards tab and makes the leaderboard data refresh automatically after each analytics sync.

New achievement alert

  • A dismissible inline success alert is shown when the user or their organization has earned an achievement they have not dismissed yet. One generic alert is shown regardless of how many achievements are new.

  • Dismissed achievements are stored per user in localStorage (awx-automation-leaderboards-acknowledged-achievements:<userId>). User and org achievements are stored as user:<id> / org:<id>.

  • The stored list is pruned on every leaderboard response, so an achievement that is lost and later re-earned shows the alert again. Storage is not touched while the report is loading or has failed.

  • Dismissing in one browser tab also hides the alert in the user's other open tabs (storage event).

  • The alert is a live region (isLiveRegion), so screen readers announce it.
  • Leaderboard refresh on sync

  • Before this change, the leaderboard report was fetched only on mount or window focus. Its SWR key is now [url, lastSyncedAt], so the report is refetched as soon as collection_status (already polled every 10 s) reports a new last_sync.

  • keepPreviousData keeps the current report on screen while the new one loads, so the page does not flash back to the loading state.

  • Each report is stored together with the sync it was fetched for, so the "Updated:" timestamp always matches the numbers shown.

  • If a refetch fails while a valid report is shown, the page keeps that report and its timestamp instead of switching to the error state. This matches how collection_status already handles a failed poll; SWR keeps retrying in the background.

  • useAutomationDashboardCollectionStatus now also returns isRequestLoading (the collection_status request only, without waiting for the user's role). The report request waits only for that, not for /me/.
  • Files

  • New: common/useNewAchievementsAlert.ts, utils/persistedAchievementState.ts (+ tests)

  • Changed: AutomationLeaderboards.tsx, views/useAutomationLeaderboardsView.ts, common/useAutomationDashboardCollectionStatus.tsx (+ tests)

  • frontend/awx/main/useAwxNavigation.test.tsx: mock updated with the new isRequestLoading field.
  • Type of Change

  • Bug fix

  • Enhancement

  • Tests

  • Documentation

  • Other (please specify)
  • Risk Analysis - REQUIRED

  • High — Broad platform impact (e.g., SWR config, shared framework components, authentication, routing, API wrappers, build/bundler config). Changes affect multiple workspaces or could cause widespread regressions.

  • Medium — Scoped but cross-cutting (e.g., shared utility functions, changes to multiple pages within one workspace, component library updates, test infrastructure). Limited blast radius but touches common code paths.

  • Low — Narrowly scoped (e.g., single page fix, styling tweak, documentation, test-only changes, copy/string updates). Minimal risk of unintended side effects.
  • Changes are limited to the Automation Dashboard Leaderboards tab. The only shared piece, useAutomationDashboardCollectionStatus, gains one additive return field; its existing fields and behavior are unchanged.

    Dependencies

    None.

    Testing

    Ephemeral E2E Tests

    Once PR is ready and preliminary checks pass, trigger tests by posting a comment /run-playwright on this PR.

    Tests run against a fresh AAP instance (version based on branch).

    Unit Tests

  • useNewAchievementsAlert.test.ts covers: first visit, user and org achievements, dismiss, a new achievement after dismiss, lost and re-earned, no change while loading or after an error, unknown user, per-user isolation, user switch, storage only written on change, and dismiss in another tab.

  • persistedAchievementState.test.ts covers: read/write round trip, per-user keys, malformed payloads, and storage errors.

  • useAutomationLeaderboardsView.test.tsx covers: refetch on a new last_sync, no refetch on the same last_sync, the timestamp matching the shown report, a failed refetch keeping the report, and not waiting for the user role.

  • AutomationLeaderboards.test.tsx covers: alert shown and dismissed, live region, and no alert in the empty state.
  • Manual Testing

    Setup: Log in as a user who has at least one earned achievement (user or organization) and open Analytics → Automation Dashboard → Leaderboards.

    1. First visit: Clear the awx-automation-leaderboards-acknowledged-achievements:<userId> key in DevTools → Application → Local Storage and reload. The success alert "Congratulations! You or your organization earned new achievements." is shown above the sync timestamp.
    2. Dismiss: Close the alert with the ✕ button. Reload the page and switch tabs (Dashboard ↔ Leaderboards); the alert stays hidden. The localStorage key now lists the earned achievements (e.g. ["user:centurion","org:topTier"]).
    3. New achievement: Earn a new achievement (or remove one key from the stored list in localStorage and wait for the next sync). The alert appears again.
    4. Lost and re-earned achievement: When an achievement disappears from the report, it is removed from the stored list on the next response. When it is earned again, the alert appears again.
    5. Multiple browser tabs: Open Leaderboards in two tabs while the alert is shown. Dismiss it in one; it also disappears in the other.
    6. Refresh on sync: Keep the Leaderboards tab open until the next analytics sync. Within ~10 s of the new sync the "Updated:" timestamp and the leaderboard data both refresh. In the Network tab, a dashboard_reports/leaderboard/ request follows the collection_status response with the new last_sync. No loading spinner is shown during the refresh.
    7. No achievements: Log in as a user with no earned achievements; no alert is shown.
    8. Accessibility: With a screen reader, the alert is announced when it appears, and the close button is reachable by keyboard.

    Screenshots

    <!-- Add a screenshot of the Leaderboards tab with the alert shown. -->
    <img width="1959" height="763" alt="image" src="https://github.com/user-attachments/assets/e36be082-9938-42b5-ac29-73b47c06b59a" />

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: kcagran Review duration: 4874m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3739"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%