Skip to content

feat(providers): add a copy button to the API key input - #9232

Merged
farion1231 merged 3 commits into
farion1231:mainfrom
minimote:feat/api-key-copy-button
Nov 22, 2026
Merged

farion1231 merged 3 commits into
farion1231:mainfrom
minimote:feat/api-key-copy-button

Conversation

@minimote

@minimote minimote commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

本人说明

用户有时需要复制之前填过的 API Key 到其他地方用,但目前的操作路径非常复杂,需要先点击密钥右侧的眼睛按钮显示密钥,然后再选中密钥,然后再复制,所以我在 API Key 标题行右侧加了一个复制按钮,可以一键复制 API Key。

概述

为 API Key 增加了一个复制按钮:一键复制完整 Key,并通过 toast 反馈结果。

  • 复制 trim 后的值,与表单保存的内容一致,避免粘贴时带入的首尾空白进入剪贴板
  • Key 为空、纯空白或输入框禁用时不显示按钮;按钮排在 labelAside 之前
  • 沿用标签行操作按钮的现有样式,未引入新样式
  • 为所有语言补充 apiKeyInput.copied / copyFailed 文案
  • 新增 6 个测试用例,覆盖复制、trim、空值、纯空白、禁用、复制失败

截图

preview

检查清单

  • pnpm typecheck 通过 TypeScript 类型检查
  • pnpm format:check 通过代码格式检查
  • cargo clippy 未修改 Rust 代码
  • 已更新国际化文件

@minimote
minimote requested a review from farion1231 as a code owner November 4, 2026 12:40
@github-actions github-actions Bot added frontend Frontend (React/TypeScript) i18n Internationalization (zh/en/ja) labels Nov 4, 2026
Reading an API key back meant toggling visibility and selecting the text by
hand. Add a copy action to the label row that copies the whole key in one
click and reports the outcome as a toast.

- Copy the trimmed value, matching what the form saves, so pasted keys with
  stray whitespace do not carry it into the clipboard
- Hide the button while the field is empty or disabled, and render it before
  labelAside so the trailing link does not shift when the button appears
- Add apiKeyInput.copied / copyFailed to en, ja, tr, zh and zh-TW
- Cover copy, trimming, empty/whitespace, disabled and failure paths in
  ApiKeySection.test.tsx
@minimote
minimote force-pushed the feat/api-key-copy-button branch from 1e7bdca to e70a286 Compare November 16, 2026 00:16
funkpopo
funkpopo previously approved these changes Nov 20, 2026

@funkpopo funkpopo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

改动很克制清晰,解决了查看/复制已有 API Key 路径繁琐的实际痛点:

  • 复制 trim() 后的值与表单保存口径一致,空值、纯空白及禁用状态下隐藏按钮,排在 labelAside 前不会导致获取链接跳位。
  • 复用现有 copyText(兼容 Linux WebView / macOS & Windows 原生剪贴板回退)与 toast,8 种语言 locale 文案齐全,新增 6 条单测覆盖所有分支。
  • 与最新 main(bd3d38801)无冲突,全项 CI 绿灯。

LGTM,可以直接合并。

@farion1231 farion1231 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LGTM,感谢您的贡献!

allenxu09
allenxu09 previously approved these changes Nov 20, 2026

@allenxu09 allenxu09 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

已核查本次修改(10/10 文件,对应 commit e94b8f96):

  • ApiKeyInput.tsx 仅在非禁用且 value.trim() 非空时显示复制按钮,复制 trim 后的值并与 labelAside 并排展示,复用现有跨平台 copyText 与 toast 反馈成功/失败。
  • 8 种语言 locale 文件已同步补齐 apiKeyInput.copied / apiKeyInput.copyFailed,ApiKeySection.test.tsx 新增 6 条测试覆盖正常复制、trim、空值、纯空白、禁用与复制失败场景,合并无冲突且 Frontend CI 全绿。

@farion1231
farion1231 dismissed stale reviews from allenxu09 and funkpopo via cfca1c0 November 22, 2026 12:22
@farion1231
farion1231 merged commit 698b1b7 into farion1231:main Nov 22, 2026
9 checks passed
@farion1231

Copy link
Copy Markdown
Owner

已合并,感谢您的贡献!

这个按钮虽小,但细节考虑得很周到:复制前先 trim,掩码状态下复制出来的也是真实 Key,空值和禁用时自动隐藏;又是在共用的 ApiKeyInput 上加的,所有应用的供应商表单一次就都有了。测试也补得很完整。

另外说明一下:main 最近把 tests/ 也纳入了 Prettier 检查,所以合并前我在您的分支上补了一个只调整测试文件格式的提交(cfca1c0f6),代码逻辑没有改动。

以后如果发现什么小问题,也欢迎继续提 PR。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend Frontend (React/TypeScript) i18n Internationalization (zh/en/ja)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants