Skip to content

fix: refresh channel test dialog status - #5504

Open
lichengzhe wants to merge 2 commits into
QuantumNous:mainfrom
lichengzhe:fix/channel-test-dialog-status
Open

fix: refresh channel test dialog status#5504
lichengzhe wants to merge 2 commits into
QuantumNous:mainfrom
lichengzhe:fix/channel-test-dialog-status

Conversation

@lichengzhe

@lichengzhe lichengzhe commented Jun 15, 2026

Copy link
Copy Markdown

【中文说明】Bug:新版渠道测试弹窗点击模型后仍显示“未测试”

在新版 UI 的「渠道管理 -> 测试连接」弹窗中,点击某个模型进行测试后,后端请求已经完成,但该模型所在行的状态可能仍停留在「未测试」,没有切换到「测试中 / 成功 / 失败」。

根因有两点:

  • 后端 /api/channel/test/:id 当前返回的是顶层 time 字段,例如 { "success": true, "message": "", "time": 4.57 }。新版前端却按 data.response_time 读取耗时,导致结果数据没有被正确消费。
  • 弹窗表格行只保存 model,没有把每个模型对应的 testResult / isTesting 绑定进 row data,测试状态更新后表格行展示容易继续显示旧状态。

这个 PR 修复后,点击单个模型测试时,行状态会从「未测试」立即变为「测试中」,请求完成后再显示「成功」或「失败」;成功时也会同步刷新渠道响应时间和最后测试时间。

Summary

  • keep channel test dialog row data in sync with each model's testing/result state
  • support the existing channel test API response shape where response time is returned as top-level time
  • update the active channel row and invalidate channel list queries after a successful test

Test Plan

  • cd web/default && bun run typecheck

Notes

The bug is visible in the new UI channel test dialog: clicking a model test can leave the row displayed as Not tested even after the backend request completes. The backend currently returns { success, message, time }, while the new UI expected data.response_time.

Summary by CodeRabbit

  • Bug Fixes
    • Improved channel test result tracking and display in the channel list, including accurate “Status” and “Actions” updates per model.
    • Enhanced response time measurement during channel testing by correctly handling multiple response time fields.
  • Refactor
    • Improved list refresh behavior after channel tests complete to ensure the latest results are shown.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d019dc55-d0da-4c71-b610-1c6fa2e517c9

📥 Commits

Reviewing files that changed from the base of the PR and between e5e4d94 and 71200ee.

📒 Files selected for processing (2)
  • web/default/src/features/channels/components/dialogs/channel-test-dialog.tsx
  • web/default/src/features/channels/lib/channel-actions.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/default/src/features/channels/components/dialogs/channel-test-dialog.tsx

Walkthrough

Adds time?: number to ChannelTestResponse, updates handleTestChannel to normalize response time from either response.data.response_time or response.time (converted to ms), and refactors ChannelTestDialog to embed testResult/isTesting directly into ModelRow, synchronize a ref to the current row, update it on test success, and invalidate the channels query cache.

Changes

Channel Test Response Time and Cache Invalidation

Layer / File(s) Summary
ChannelTestResponse type and responseTime normalization
web/default/src/features/channels/types.ts, web/default/src/features/channels/lib/channel-actions.ts
Adds optional time?: number to ChannelTestResponse; handleTestChannel now derives responseTime from response.data.response_time or response.time * 1000, passing the normalized value to onTestComplete.
Dialog setup, row model enrichment, and tableData mapping
web/default/src/features/channels/components/dialogs/channel-test-dialog.tsx
Imports useQueryClient and channelsQueryKeys; extends ModelRow with optional testResult and isTesting; initializes queryClient and obtains setCurrentRow from useChannels(); introduces currentRowRef synchronized via useEffect; reworks tableData to map filtered models into enriched rows carrying test state.
Cache invalidation on success and updated cell rendering
web/default/src/features/channels/components/dialogs/channel-test-dialog.tsx
On successful test with numeric responseTime, uses currentRowRef to guard against stale updates, calls setCurrentRow with updated response_time/test_time, and invalidates channelsQueryKeys.lists(); "Status" and "Actions" cells now read from row.original.testResult/row.original.isTesting; updates hook and memo dependencies.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • QuantumNous/new-api#4988: Modifies channel-test-dialog.tsx's Status cell and table row rendering logic, directly overlapping with this PR's switch to row.original.testResult/isTesting.

Suggested reviewers

  • seefs001

Poem

🐇 Hop, hop! The timer ticks true,
response.time converts for the queue,
Each row holds its test, fresh and tight,
The cache clears swift—no stale data blight,
Results flow in with millisecond might,
A rabbit-approved, perfectly-timed delight! 🕐

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: refresh channel test dialog status' directly describes the main fix - ensuring the channel test dialog status updates correctly after testing, which is the core issue addressed by all three file modifications.
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 unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@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)
web/default/src/features/channels/lib/channel-actions.ts (1)

240-245: ⚡ Quick win

Avoid nested ternary in response-time normalization.

Use explicit branching here; it keeps this API-shape fallback logic easier to read and maintain.

♻️ Proposed refactor
-    const responseTime =
-      typeof response.data?.response_time === 'number'
-        ? response.data.response_time
-        : typeof response.time === 'number'
-          ? response.time * 1000
-          : undefined
+    let responseTime: number | undefined
+    if (typeof response.data?.response_time === 'number') {
+      responseTime = response.data.response_time
+    } else if (typeof response.time === 'number') {
+      responseTime = response.time * 1000
+    }

As per coding guidelines, web/default/**/*.{ts,tsx} prohibits nested ternary expressions with 2 or more levels and asks to use if-else, early returns, or extracted functions instead.

🤖 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 `@web/default/src/features/channels/lib/channel-actions.ts` around lines 240 -
245, Replace the nested ternary operator in the responseTime variable assignment
with explicit if-else branching. The current code has two levels of ternary
operators checking response.data?.response_time, then response.time, and falling
back to undefined. Convert this to use if-else statements or early returns to
check each condition sequentially and assign the appropriate value, ensuring the
logic is clearer and adheres to the coding guidelines that prohibit nested
ternary expressions with 2 or more levels.

Source: Coding guidelines

🤖 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
`@web/default/src/features/channels/components/dialogs/channel-test-dialog.tsx`:
- Around line 342-351: The success callback in the test completion handler uses
the closure-captured currentRow value, which becomes stale if the user switches
channels before the async test completes. Create a useRef to hold the current
row reference, update it whenever currentRow changes, and in the success
callback block (where success && typeof responseTime === 'number'), read the
latest row from the ref instead of using the closure variable. Additionally, add
a verification check comparing the response row's ID with the current ref row's
ID before calling setCurrentRow to ensure you only update results for the
channel the test was actually run against.

---

Nitpick comments:
In `@web/default/src/features/channels/lib/channel-actions.ts`:
- Around line 240-245: Replace the nested ternary operator in the responseTime
variable assignment with explicit if-else branching. The current code has two
levels of ternary operators checking response.data?.response_time, then
response.time, and falling back to undefined. Convert this to use if-else
statements or early returns to check each condition sequentially and assign the
appropriate value, ensuring the logic is clearer and adheres to the coding
guidelines that prohibit nested ternary expressions with 2 or more levels.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b2c3fc30-21c3-42f4-9c04-ec5aeb0fe4ad

📥 Commits

Reviewing files that changed from the base of the PR and between 1ac0f58 and e5e4d94.

📒 Files selected for processing (3)
  • web/default/src/features/channels/components/dialogs/channel-test-dialog.tsx
  • web/default/src/features/channels/lib/channel-actions.ts
  • web/default/src/features/channels/types.ts

@Calcium-Ion
Calcium-Ion force-pushed the main branch 2 times, most recently from 51fdfc5 to 2b6f1df Compare August 30, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant