Skip to content

chore(ui/history): improve Retry toast wording - #708

Merged
cristim merged 3 commits into
feat/multicloud-web-frontendfrom
fix/707-retry-toast-wording
May 25, 2026
Merged

cristim merged 3 commits into
feat/multicloud-web-frontendfrom
fix/707-retry-toast-wording

Conversation

@cristim

@cristim cristim commented May 25, 2026 •

Copy link
Copy Markdown
Member

Closes #707. Changes the toast string in frontend/src/history.ts:815 from 'Retry execution created' to 'Purchase request sent for approval' — friendlier and more accurate (the Retry creates an approval-required execution, not an execution itself). All 1932 frontend tests pass.

Summary by CodeRabbit

  • Bug Fixes

    • Retry flow now shows conditional notifications: success when approval/email was sent or status is pending/notified; warning if the retry was created but the approval email failed.
  • Tests

    • Expanded coverage for retry outcomes (email sent vs not sent, pending status) and threshold-override behavior; updated assertions to match the revised UX messaging.

Review Change Stack

@cristim cristim added triaged Item has been triaged priority/p3 Polish / idea / may never ship severity/low Minor harm urgency/eventually No deadline impact/few Limited audience effort/xs Trivial / one-liner type/chore Maintenance / non-user-visible labels May 25, 2026
@coderabbitai

coderabbitai Bot commented May 25, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 50b8332d-2b2c-4a3c-a2d1-8a74e0ed7b20

📥 Commits

Reviewing files that changed from the base of the PR and between 8c63d50 and 25ab8a1.

📒 Files selected for processing (2)
  • frontend/src/__tests__/history-retry-button.test.ts
  • frontend/src/history.ts

📝 Walkthrough

Walkthrough

The Retry click handler now inspects the api.retryPurchase response and shows either a success toast (when approval email sent or status is pending/notified) or a warning (when the retry was created but email delivery failed). Tests were expanded to document and assert these outcomes and the force-override flow.

Changes

Approval Workflow Toast Update

Layer / File(s) Summary
Retry handler branching and toast selection
frontend/src/history.ts
The Retry click handler captures api.retryPurchase's return value and conditionally shows a success toast when email_sent === true or status is pending/notified; otherwise it shows a warning indicating the approval email failed.
Tests: UX matrix and toast assertions
frontend/src/__tests__/history-retry-button.test.ts
Test header extended with the retry UX matrix; tests updated/made more specific to mock full retryPurchase payloads (including email_sent and status variants) and assert success vs warning toasts and the force: true override call.

Sequence Diagram(s)

sequenceDiagram
  participant HistoryUI as History UI
  participant API as api.retryPurchase
  participant Toast as Toast system
  HistoryUI->>API: POST retryPurchase({ force? })
  API-->>HistoryUI: { status, email_sent, ... } (retryResult)
  HistoryUI->>Toast: show success if email_sent===true or status in [pending, notified]
  HistoryUI->>Toast: show warning otherwise
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • #707: Directly related—both PRs modify the retry toast behavior in frontend/src/history.ts.

Possibly related PRs

  • LeanerCloud/CUDly#387: Modifies wireRowActionHandlers and related approval-queue row action wiring used by this handler.
  • LeanerCloud/CUDly#294: Adjusted frontend UX for approval-required flows and related toast/copy behavior.

Suggested labels

effort/s

Poem

🐰 I tapped Retry, the API replied,
A hopeful toast, or else a sigh,
Tests now check each email flag,
Small hops of code, no need to lag,
Rabbit cheers: "Approved or warned—let's try!"

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'chore(ui/history): improve Retry toast wording' directly addresses the main change: improving toast messaging in the Retry button handler based on backend-reported outcomes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/707-retry-toast-wording

Comment @coderabbitai help to get the list of available commands and usage tips.

@cristim

cristim commented May 25, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
frontend/src/history.ts (1)

783-783: ⚡ Quick win

Update the confirm dialog to match the new toast message.

The confirmation dialog states "This will create a new purchase execution from the same recommendations," but the success toast now says "Purchase request sent for approval." If retries create approval-required purchases (as the PR rationale states), this dialog message is inconsistent and should be updated.

📝 Suggested update for consistency
-          ? 'This will create a new purchase execution from the same recommendations. The original failed row will be linked to the new attempt.'
+          ? 'This will create a new purchase request from the same recommendations, which will be sent for approval. The original failed row will be linked to the new attempt.'
🤖 Prompt for 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.

In `@frontend/src/history.ts` at line 783, Update the confirm dialog text that
currently reads "This will create a new purchase execution from the same
recommendations. The original failed row will be linked to the new attempt." to
match the new success toast ("Purchase request sent for approval") and the PR
rationale: make the confirmation explicitly state that retrying will create a
purchase request requiring approval (e.g. mention "a purchase request will be
created and sent for approval" and that the failed row will be linked). Locate
the string in frontend/src/history.ts (the exact literal above) and replace it
with the clarified confirmation message used by the confirm dialog function/call
so wording is consistent with the toast and approval flow.
🤖 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 `@frontend/src/history.ts`:
- Line 815: The success toast is shown unconditionally after calling the
retryPurchase flow; change the logic in frontend/src/history.ts around the retry
handler so that you inspect the API response (the object that contains
ApprovalToken, email_sent and status) and only call showToast({message:
'Purchase request sent for approval', ...}) when email_sent is true (or status
=== 'pending'); when email_sent is false (or status === 'failed') show an
appropriate failure toast (e.g., 'Failed to send approval email') or handle the
finalized failed execution path. Locate the retry call and the existing
showToast invocation and gate/branch based on response.email_sent and/or
response.status to match the backend behavior.

---

Nitpick comments:
In `@frontend/src/history.ts`:
- Line 783: Update the confirm dialog text that currently reads "This will
create a new purchase execution from the same recommendations. The original
failed row will be linked to the new attempt." to match the new success toast
("Purchase request sent for approval") and the PR rationale: make the
confirmation explicitly state that retrying will create a purchase request
requiring approval (e.g. mention "a purchase request will be created and sent
for approval" and that the failed row will be linked). Locate the string in
frontend/src/history.ts (the exact literal above) and replace it with the
clarified confirmation message used by the confirm dialog function/call so
wording is consistent with the toast and approval flow.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6f25f603-0912-458c-82b7-ba0db0930d81

📥 Commits

Reviewing files that changed from the base of the PR and between 423e87c and f89ebea.

📒 Files selected for processing (1)
  • frontend/src/history.ts

Comment thread frontend/src/history.ts Outdated
…onse

The "Purchase request sent for approval" toast was shown unconditionally
after a successful retry POST. The backend's RetryPurchaseResult already
carries email_sent (bool) and status (string); when the approval email
fails, the execution is created with status "failed" and email_sent false,
but the toast previously still claimed approval was requested.

Gate the toast: show success when email_sent===true or
status==='pending'/'notified'; show a warning toast when email_sent===false
or status indicates failure. Adds three new test cases covering the
email-sent, status-only, and email-failed branches.

Resolves CR finding on PR #708 (discussion_r3299766964).
@cristim

cristim commented May 25, 2026

Copy link
Copy Markdown
Member Author

CR finding addressed: gate retry toast on email_sent / status

Commit: 8c63d50

Change summary:

Captured the retryPurchase API response and branched the post-retry toast on the backend-reported outcome:

  • email_sent === true or status === 'pending' / 'notified': success toast ("Purchase request sent for approval")
  • email_sent === false or status indicates failure: warning toast ("Retry created but approval email failed - check your notification settings")

The RetryPurchaseResult interface in frontend/src/api/purchases.ts already exposed email_sent?: boolean and status: string - no backend changes needed.

Tests added: 3 new cases in history-retry-button.test.ts (email_sent true, status-only pending, email_sent false). Total: 13 tests in the retry suite, 1933 overall. TypeScript clean.

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

@cristim Great implementation — branching on both email_sent and status covers the cases where only one field is present in the response, and the warning toast for failed notification emails is a meaningful UX improvement over silently claiming success. The test coverage (3 new cases hitting both branches) looks solid. Triggering the incremental review on commit 8c63d50d3 now.

(∪・ω・∪)

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim

cristim commented May 25, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim

cristim commented May 25, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 `@frontend/src/history.ts`:
- Around line 817-824: The condition computing emailOk in the retry handling
must give explicit email_sent === false precedence over status fallbacks; update
the logic in the block around the emailOk variable (where retryResult.email_sent
and retryResult.status are checked) so that if retryResult.email_sent === false
you treat emailOk as false (and show the warning toast), otherwise treat emailOk
as true when retryResult.email_sent === true or when email_sent is not
explicitly false and retryResult.status is 'pending' or 'notified'—this ensures
explicit failures override status-based success.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: e293abcf-2779-4ed4-b277-5273f2e8c207

📥 Commits

Reviewing files that changed from the base of the PR and between f89ebea and 8c63d50.

📒 Files selected for processing (2)
  • frontend/src/__tests__/history-retry-button.test.ts
  • frontend/src/history.ts

Comment thread frontend/src/history.ts Outdated
…in retry toast gating

Guard the status-based emailOk fallback with !emailExplicitlyFailed so that
a backend payload carrying email_sent===false always shows the warning toast,
even when status is 'pending' or 'notified'. Add test case #14 covering the
conflicting-payload scenario CR round 2 identified.
@cristim

cristim commented May 25, 2026

Copy link
Copy Markdown
Member Author

Round 2 CR finding addressed in 25ab8a1.

Finding: email_sent===false + status==='pending' produced a false success toast because the prior || chain evaluated the status term before checking email_sent.

Fix (frontend/src/history.ts:817-827): added an emailExplicitlyFailed guard that short-circuits the status fallback:

const emailExplicitlyFailed = retryResult.email_sent === false;
const emailOk = !emailExplicitlyFailed && (
  retryResult.email_sent === true
  || retryResult.status === 'pending'
  || retryResult.status === 'notified'
);

New test (case #14 in history-retry-button.test.ts): email_sent:false + status:'pending' asserts warning toast is shown and success toast is NOT shown.

1934 tests pass, TypeScript clean.

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

@cristim Good catch on that edge case — the emailExplicitlyFailed guard is the right fix. Without it, status === 'pending' in the || chain would win regardless of an explicit false on email_sent, which is exactly the false-positive scenario you described. The new structure correctly makes email_sent: false a hard veto before the status fallback is even evaluated.

The additional test case (case #14: email_sent:false + status:'pending' → warning, no success) is the critical regression guard for this specific combination. Triggering the incremental review on 25ab8a1f4 now.

(ᵔᴥᵔ)ノ

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim
cristim merged commit fdcede3 into feat/multicloud-web-frontend May 25, 2026
5 checks passed
@cristim
cristim deleted the fix/707-retry-toast-wording branch May 25, 2026 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/xs Trivial / one-liner impact/few Limited audience priority/p3 Polish / idea / may never ship severity/low Minor harm triaged Item has been triaged type/chore Maintenance / non-user-visible urgency/eventually No deadline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant