Skip to content

feat(web): 支持渠道列表手动调整列宽#5948

Merged
Calcium-Ion merged 4 commits into
QuantumNous:mainfrom
zuiho-kai:codex/channel-table-column-resize
Jul 8, 2026
Merged

feat(web): 支持渠道列表手动调整列宽#5948
Calcium-Ion merged 4 commits into
QuantumNous:mainfrom
zuiho-kai:codex/channel-table-column-resize

Conversation

@zuiho-kai

@zuiho-kai zuiho-kai commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

Important

  • 本说明为人工整理后的摘要,按项目模板填写。

📝 变更描述 / Description

渠道列表的字段很多,渠道名称、模型、分组等内容也可能很长。固定列宽时,用户只能看到被截断后的内容,对比和排查渠道不方便。

本 PR 给渠道列表增加了可调整列宽:

  • 拖动表头右侧分隔线,可以手动调整列宽。
  • 双击分隔线,会按当前可见内容自动调整到合适宽度。
  • 调整后的列宽保存在浏览器本地,刷新页面后仍然保留。
  • 分隔线支持键盘操作:左右方向键调整宽度,Enter / Space 自动适应内容。

实现上,列宽状态复用通用 DataTable 的 TanStack Table sizing 状态;只有渠道列表传入本地保存 key 并启用列宽调整,不影响未启用该能力的其他表格。

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,未发现渠道列表列宽调整的重复提交。
  • Bug fix 说明: 此 PR 未标记为 Bug fix
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 仅包含渠道列表列宽调整相关改动。
  • 本地验证: 已在本地运行并通过类型检查、相关文件 lint、格式检查和 diff 空白检查。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

当前 PR head 已执行并通过:

bun run --cwd default typecheck
./node_modules/.bin/oxlint.exe -c default/.oxlintrc.json default/src/components/data-table/core/data-table-colgroup.tsx default/src/components/data-table/core/data-table-header.tsx default/src/components/data-table/core/data-table-row.tsx default/src/components/data-table/hooks/use-data-table.ts default/src/features/channels/components/channels-columns.tsx default/src/features/channels/components/channels-table.tsx
./node_modules/.bin/oxfmt.exe --check default/src/components/data-table/core/data-table-colgroup.tsx default/src/components/data-table/core/data-table-header.tsx default/src/components/data-table/core/data-table-row.tsx default/src/components/data-table/hooks/use-data-table.ts default/src/features/channels/components/channels-columns.tsx default/src/features/channels/components/channels-table.tsx
git diff --check origin/main...HEAD

Summary by CodeRabbit

  • New Features

    • Added resizable table columns with keyboard controls and automatic sizing.
    • Table column widths can now be saved and restored between visits on supported views.
  • Bug Fixes

    • Improved column sizing behavior for content-based columns and mobile devices.
    • Updated table layouts to better handle narrow content without overflow.

@coderabbitai

coderabbitai Bot commented Jul 6, 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: e4c9a6db-f8de-430c-a313-f2cbf69ebfdf

📥 Commits

Reviewing files that changed from the base of the PR and between cf23478 and ce2e1f6.

📒 Files selected for processing (2)
  • web/default/src/components/data-table/hooks/use-data-table.ts
  • web/default/src/features/channels/components/channels-table.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • web/default/src/features/channels/components/channels-table.tsx
  • web/default/src/components/data-table/hooks/use-data-table.ts

Walkthrough

This PR adds manual column resizing to the shared data table, persists column widths in browser storage, and enables it for the channels table with adjusted name-column sizing and layout.

Changes

Column Resizing Feature

Layer / File(s) Summary
Column sizing state and persistence in useDataTable
web/default/src/components/data-table/hooks/use-data-table.ts
Adds column sizing options and state, derives bounded persisted widths, and wires hydration plus localStorage persistence into the table hook.
Pixel-based column width calculation
web/default/src/components/data-table/core/data-table-colgroup.tsx
Returns pixel widths for resizable columns and keeps percentage widths for non-resizable columns.
Resize handle rendering in header
web/default/src/components/data-table/core/data-table-header.tsx, web/default/src/components/data-table/core/data-table-row.tsx
Adds the resizer visibility helper, translated aria label, relative header styling, keyboard resize handling, and the cell attribute used for content measurement.
Enable resizing for channels table
web/default/src/features/channels/components/channels-table.tsx, web/default/src/features/channels/components/channels-columns.tsx
Turns on resizing for the channels table, stores sizing under a dedicated key, disables resizing for the selection column, and updates the Name column sizing and layout.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ChannelsTable
  participant DataTableHeader
  participant useDataTable
  participant localStorage

  ChannelsTable->>useDataTable: enableColumnResizing + storage key
  DataTableHeader->>useDataTable: onColumnSizingChange from drag/key resize
  useDataTable->>localStorage: read and persist columnSizing
  useDataTable-->>DataTableHeader: updated sizing state
Loading

Possibly related PRs

  • QuantumNous/new-api#5405: Both PRs modify the shared web/default/src/components/data-table infrastructure, including use-data-table.ts and colgroup/table sizing logic.
  • QuantumNous/new-api#5460: Both PRs change DataTableColgroup width calculation in web/default/src/components/data-table/core/data-table-colgroup.tsx.

Poem

I’m a bunny with a measuring hop,
I tug the columns, stop and stop.
Long names stretch out, then snugly stay,
And widths remember from day to day.
🐇

🚥 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 Title clearly states the channel list manual column resizing feature and matches the PR scope.
Linked Issues check ✅ Passed The PR adds drag, keyboard, and double-click resizing, persists widths, and improves the channel name column as requested by #5946.
Out of Scope Changes check ✅ Passed The changes stay focused on channel list column resizing and related DataTable support, with no unrelated feature work apparent.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@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: 2

🤖 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/components/data-table/core/data-table-header.tsx`:
- Around line 65-79: The resize handle in data-table-header is mouse/touch only,
so make the separator keyboard operable. Update the inline separator element
returned by the header render path to add focusability and keyboard handling,
using the existing header.column resize/reset behavior from getResizeHandler()
and resetSize(). Add a sensible tab order and onKeyDown support for resize
actions and reset, while preserving the current aria-label/role='separator'
semantics.

In `@web/default/src/components/data-table/hooks/use-data-table.ts`:
- Around line 158-182: `readColumnSizing` currently accepts any positive
persisted width, which can let saved state تجاوز a column’s `minSize`/`maxSize`.
Update the hydration path in `use-data-table.ts` so each restored width is
validated against the matching column definition bounds before being returned.
Use the column metadata used by the table setup (especially the column
definitions that set `minSize`/`maxSize`, like the Channels name column) to
clamp or discard out-of-range values. Ensure only bounded widths are merged into
`ColumnSizingState`.
🪄 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: 8c830920-01e0-48bb-bb6a-09bbed8f9494

📥 Commits

Reviewing files that changed from the base of the PR and between 45f0484 and ceed881.

📒 Files selected for processing (5)
  • web/default/src/components/data-table/core/data-table-colgroup.tsx
  • web/default/src/components/data-table/core/data-table-header.tsx
  • web/default/src/components/data-table/hooks/use-data-table.ts
  • web/default/src/features/channels/components/channels-columns.tsx
  • web/default/src/features/channels/components/channels-table.tsx

Comment thread web/default/src/components/data-table/core/data-table-header.tsx
Comment thread web/default/src/components/data-table/hooks/use-data-table.ts Outdated
Signed-off-by: zuiho <2324465096@qq.com>

@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.

🧹 Nitpick comments (2)
web/default/src/components/data-table/core/data-table-header.tsx (1)

66-84: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Expose resize value on the focusable separator. Keyboard operability is now correctly handled (resolves the prior review), but a focusable role="separator" acting as a resizer should follow the window-splitter pattern and expose aria-valuenow/aria-valuemin/aria-valuemax so assistive tech can announce the current width during keyboard resizing.

♿ Suggested ARIA additions
                 <div
                   role='separator'
                   aria-orientation='vertical'
                   aria-label={t('Resize column')}
+                  aria-valuenow={Math.round(header.column.getSize())}
+                  aria-valuemin={header.column.columnDef.minSize}
+                  aria-valuemax={header.column.columnDef.maxSize}
                   tabIndex={0}

As per path instructions, "add ARIA attributes when needed" for web/default/**/*.tsx React components.

🤖 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/components/data-table/core/data-table-header.tsx` around
lines 66 - 84, The focusable resize handle in data-table-header should expose
the current size to assistive tech as a window-splitter style separator. Update
the separator element in data-table-header.tsx (the one using
shouldRenderColumnResizer, header.getResizeHandler, and
handleColumnResizeKeyDown) to include aria-valuenow, aria-valuemin, and
aria-valuemax based on the column’s resize bounds/current width, while keeping
the existing keyboard resize behavior intact.

Source: Path instructions

web/default/src/components/data-table/hooks/use-data-table.ts (1)

479-495: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Debounce column-sizing persistence columnResizeMode: 'onChange' updates columnSizing on every drag frame, so this effect does a synchronous JSON.stringify + localStorage.setItem per mousemove. Debounce the write or skip it while resizing is active.

🤖 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/components/data-table/hooks/use-data-table.ts` around lines
479 - 495, The column-sizing persistence effect in useDataTable is writing to
localStorage on every drag frame because it reacts directly to columnSizing
changes. Update the React.useEffect logic to debounce the persistence work or
gate it while resizing is active, so JSON.stringify and
window.localStorage.setItem are not called on every mousemove. Keep the existing
skipNextColumnSizingPersistRef and columnSizingStorageKey checks intact, and
apply the fix within the useDataTable hook around the columnSizing persistence
effect.
🤖 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.

Nitpick comments:
In `@web/default/src/components/data-table/core/data-table-header.tsx`:
- Around line 66-84: The focusable resize handle in data-table-header should
expose the current size to assistive tech as a window-splitter style separator.
Update the separator element in data-table-header.tsx (the one using
shouldRenderColumnResizer, header.getResizeHandler, and
handleColumnResizeKeyDown) to include aria-valuenow, aria-valuemin, and
aria-valuemax based on the column’s resize bounds/current width, while keeping
the existing keyboard resize behavior intact.

In `@web/default/src/components/data-table/hooks/use-data-table.ts`:
- Around line 479-495: The column-sizing persistence effect in useDataTable is
writing to localStorage on every drag frame because it reacts directly to
columnSizing changes. Update the React.useEffect logic to debounce the
persistence work or gate it while resizing is active, so JSON.stringify and
window.localStorage.setItem are not called on every mousemove. Keep the existing
skipNextColumnSizingPersistRef and columnSizingStorageKey checks intact, and
apply the fix within the useDataTable hook around the columnSizing persistence
effect.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8ee30025-2759-4f35-bf18-3128809dd41f

📥 Commits

Reviewing files that changed from the base of the PR and between ceed881 and ea351f9.

📒 Files selected for processing (2)
  • web/default/src/components/data-table/core/data-table-header.tsx
  • web/default/src/components/data-table/hooks/use-data-table.ts

@xingxinag

Copy link
Copy Markdown

我也希望可以手动调整宽度

@Calcium-Ion Calcium-Ion self-assigned this Jul 8, 2026
Signed-off-by: zuiho <2324465096@qq.com>
@Calcium-Ion

Copy link
Copy Markdown
Member

拖拽的时候有localStorage 频繁写入的问题会很卡,然后移动端下可以禁用这个功能?

@zuiho-kai

Copy link
Copy Markdown
Contributor Author

拖拽的时候有localStorage 频繁写入的问题会很卡,然后移动端下可以禁用这个功能?

我看看优化一下,不行就ban了

Signed-off-by: zuiho <2324465096@qq.com>
@zuiho-kai

Copy link
Copy Markdown
Contributor Author

@Calcium-Ion 做了250ms防抖+ban移动端

@Calcium-Ion Calcium-Ion merged commit 8739c05 into QuantumNous:main Jul 8, 2026
1 check passed
@QuentinHsu

Copy link
Copy Markdown
Collaborator
CleanShot 2026-07-09 at 11 30 05

渠道列表的默认宽度有点没充分利用可用宽度,可能要改下。 @zuiho-kai

@zuiho-kai

Copy link
Copy Markdown
Contributor Author
CleanShot 2026-07-09 at 11 30 05 渠道列表的默认宽度有点没充分利用可用宽度,可能要改下。 @zuiho-kai

我的屏幕没那么宽。。,没发现,我改改

@zuiho-kai

Copy link
Copy Markdown
Contributor Author
CleanShot 2026-07-09 at 11 30 05 渠道列表的默认宽度有点没充分利用可用宽度,可能要改下。 @zuiho-kai

#6031

xiaomingchen pushed a commit to xiaomingchen/new-api that referenced this pull request Jul 10, 2026
* 支持渠道表格列宽拖拽

* fix(web): address column resize review feedback

* feat(web): auto-fit resized table columns

* fix(web): reduce column resize persistence work

---------

Signed-off-by: zuiho <2324465096@qq.com>
Jacobinwwey pushed a commit to Jacobinwwey/new-api that referenced this pull request Jul 11, 2026
* 支持渠道表格列宽拖拽

* fix(web): address column resize review feedback

* feat(web): auto-fit resized table columns

* fix(web): reduce column resize persistence work

---------

Signed-off-by: zuiho <2324465096@qq.com>
lizhongyi1209 pushed a commit to lizhongyi1209/new-api that referenced this pull request Jul 13, 2026
* 支持渠道表格列宽拖拽

* fix(web): address column resize review feedback

* feat(web): auto-fit resized table columns

* fix(web): reduce column resize persistence work

---------

Signed-off-by: zuiho <2324465096@qq.com>
(cherry picked from commit 8739c05)
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.

渠道列表表格支持手动调整列宽

4 participants