feat: add channel API address column#6079
Conversation
WalkthroughAdds an optional, hidden-by-default Base URL column to the channel table. API addresses are trimmed, validated for HTTP(S) links, displayed with sensitive-data handling, and tested for empty, valid, and non-HTTP inputs. ChangesChannel API address column
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 `@web/default/src/features/channels/lib/channel-api-address.test.ts`:
- Around line 1-2: Replace the node:test and node:assert/strict imports in
channel-api-address.test.ts with Vitest imports, using describe, test, and
appropriate expect assertions; update all assertions accordingly so the tests
run under the project’s standard Vitest runner.
🪄 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: d3466200-cd66-4dcd-8d50-fa85f7dd9f46
📒 Files selected for processing (5)
web/default/src/features/channels/components/channels-columns.tsxweb/default/src/features/channels/components/channels-table.tsxweb/default/src/features/channels/lib/channel-api-address.test.tsweb/default/src/features/channels/lib/channel-api-address.tsweb/default/src/features/channels/lib/index.ts
| import assert from 'node:assert/strict' | ||
| import { describe, test } from 'node:test' |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Use Vitest instead of node:test per project conventions.
The coding guidelines for web/default/**/*.test.ts require unit tests to be written with Vitest. Using node:test and node:assert/strict means these tests won't run under the project's standard Vitest-based test runner and may be silently skipped in CI.
As per coding guidelines: web/default/**/*.test.ts: Write unit tests for utility functions and pure logic with Vitest.
♻️ Proposed fix: migrate to Vitest
-import assert from 'node:assert/strict'
-import { describe, test } from 'node:test'
+import { describe, it, expect } from 'vitest'
import { formatChannelApiAddress } from './channel-api-address'
describe('channel API address formatting', () => {
- test('returns null for empty channel base URLs', () => {
- assert.equal(formatChannelApiAddress(null), null)
- assert.equal(formatChannelApiAddress(undefined), null)
- assert.equal(formatChannelApiAddress(' '), null)
+ it('returns null for empty channel base URLs', () => {
+ expect(formatChannelApiAddress(null)).toBeNull()
+ expect(formatChannelApiAddress(undefined)).toBeNull()
+ expect(formatChannelApiAddress(' ')).toBeNull()
})
- test('trims visible API addresses and uses the same value as the link target', () => {
- assert.deepEqual(formatChannelApiAddress(' https://api.example.com '), {
+ it('trims visible API addresses and uses the same value as the link target', () => {
+ expect(formatChannelApiAddress(' https://api.example.com ')).toEqual({
displayText: 'https://api.example.com',
href: 'https://api.example.com',
})
})
- test('does not create link targets for non-http API addresses', () => {
- assert.deepEqual(formatChannelApiAddress('javascript:alert(1)'), {
+ it('does not create link targets for non-http API addresses', () => {
+ expect(formatChannelApiAddress('javascript:alert(1)')).toEqual({
displayText: 'javascript:alert(1)',
href: null,
})
})
})📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import assert from 'node:assert/strict' | |
| import { describe, test } from 'node:test' | |
| import { describe, it, expect } from 'vitest' | |
| import { formatChannelApiAddress } from './channel-api-address' | |
| describe('channel API address formatting', () => { | |
| it('returns null for empty channel base URLs', () => { | |
| expect(formatChannelApiAddress(null)).toBeNull() | |
| expect(formatChannelApiAddress(undefined)).toBeNull() | |
| expect(formatChannelApiAddress(' ')).toBeNull() | |
| }) | |
| it('trims visible API addresses and uses the same value as the link target', () => { | |
| expect(formatChannelApiAddress(' https://api.example.com ')).toEqual({ | |
| displayText: 'https://api.example.com', | |
| href: 'https://api.example.com', | |
| }) | |
| }) | |
| it('does not create link targets for non-http API addresses', () => { | |
| expect(formatChannelApiAddress('javascript:alert(1)')).toEqual({ | |
| displayText: 'javascript:alert(1)', | |
| href: null, | |
| }) | |
| }) | |
| }) |
🤖 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-api-address.test.ts` around
lines 1 - 2, Replace the node:test and node:assert/strict imports in
channel-api-address.test.ts with Vitest imports, using describe, test, and
appropriate expect assertions; update all assertions accordingly so the tests
run under the project’s standard Vitest runner.
Source: Coding guidelines
#6077
Important
📝 变更描述 / Description
本 PR 在渠道列表中新增可选的
API 地址列,用于展示渠道配置的base_url。实现上,新增列使用现有表格列配置接入,位置放在
类型 / Type与状态 / Status之间;同时在渠道表格的initialColumnVisibility中将base_url默认设为隐藏,因此它会先出现在“切换列”菜单中,用户勾选后才显示到列表里。地址渲染逻辑单独抽到
formatChannelApiAddress:空地址显示为-,http/https地址会作为链接在新标签页打开,非http/https地址仅按文本展示,避免把不安全协议写入可点击链接。敏感信息隐藏状态下,该列也会显示掩码,保持与渠道列表现有敏感信息展示逻辑一致。本次实现由 AI 协助完成,并经过整理、验证后提交。
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
Summary by CodeRabbit
New Features
Bug Fixes
Tests