Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

feat(desktop): 设置页资料卡显式展示并缩写用户 ID (#345)

bobo0e5fad2c7ca6
diff --git a/apps/desktop/src/main/__tests__/codexFileRewindExecutor.test.ts b/apps/desktop/src/main/__tests__/codexFileRewindExecutor.test.ts
index 8a089152e9..85a1b49ea2 100644
--- a/apps/desktop/src/main/__tests__/codexFileRewindExecutor.test.ts
+++ b/apps/desktop/src/main/__tests__/codexFileRewindExecutor.test.ts
@@ -19,7 +19,12 @@ const REAL_GIT_TEST_TIMEOUT_MS = process.platform === 'win32' ? 60_000 : 20_000;
let repoPath: string;
async function initRepo() {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'xdt-codex-rewind-'));
- for (const args of [['init'], ['config', 'user.email', '[email protected]'], ['config', 'user.name', 'XDT Test'], ['config', 'commit.gpgsign', 'false'], ['config', 'core.autocrlf', 'false']]) await gitExec(args, dir);
+ await gitExec(['init'], dir);
+ // 仓库级覆写 core.excludesFile:宿主机全局 gitignore(常见如 *.tmp)会吞掉
+ // 未跟踪文件,让 status 断言在部分开发机上失真。
+ const excludesOverride = path.join(dir, '.git', 'xdt-test-empty-excludes');
+ await fs.writeFile(excludesOverride, '', 'utf8');
+ for (const args of [['config', 'core.excludesFile', excludesOverride], ['config', 'user.email', '[email protected]'], ['config', 'user.name', 'XDT Test'], ['config', 'commit.gpgsign', 'false'], ['config', 'core.autocrlf', 'false']]) await gitExec(args, dir);
return dir;
}
diff --git a/apps/desktop/src/renderer/__tests__/userProfileCardCopyUserId.test.tsx b/apps/desktop/src/renderer/__tests__/userProfileCardCopyUserId.test.tsx
index be72a7a808..60db5669b1 100644
--- a/apps/desktop/src/renderer/__tests__/userProfileCardCopyUserId.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/userProfileCardCopyUserId.test.tsx
@@ -34,7 +34,11 @@ const mocks = vi.hoisted(() => ({
}));
vi.mock('react-i18next', () => ({
- useTranslation: () => ({ t: (key: string) => key }),
+ useTranslation: () => ({
+ // 带 id 插值的 key(copyUserId.display)拼上实际值,便于断言 ID 真的渲染了出来。
+ t: (key: string, params?: Record<string, unknown>) =>
+ params && 'id' in params ? `${key}:${String(params.id)}` : key,
+ }),
}));
vi.mock('@/contexts/AuthContext', () => ({
@@ -85,21 +89,52 @@ describe('UserProfileCard copy user ID', () => {
vi.clearAllMocks();
});
- it('copies the user ID and shows a success toast when the name is clicked', async () => {
+ it('shows the user ID and copies it with a success toast when the ID row is clicked', async () => {
renderCard();
- const nameButton = screen.getByRole('button', {
+ // ID 显式展示在卡片上,且名字本身不再是可点击控件。
+ expect(screen.getByText('settings.userProfile.copyUserId.display:user-123')).toBeTruthy();
+ expect(screen.getByText('Lizi').closest('button')).toBeNull();
+
+ const idButton = screen.getByRole('button', {
name: 'settings.userProfile.copyUserId.action',
});
- expect(nameButton.className).toContain('cursor-pointer');
- expect(nameButton.className).toContain('hover:bg-[var(--settings-profile-avatar-bg)]');
+ expect(idButton.className).toContain('cursor-pointer');
+ expect(idButton.className).toContain('hover:bg-[var(--settings-profile-avatar-bg)]');
+ // 交互件圆角走 pill 档(DESIGN.md Border Radius Scale,无 6px 档)。
+ expect(idButton.className).toContain('rounded-full');
+ // 可见 ID 经 aria-describedby 暴露给辅助技术(aria-label 只承载动作名)。
+ const describedById = idButton.getAttribute('aria-describedby');
+ expect(describedById).toBeTruthy();
+ expect(document.getElementById(describedById!)?.textContent).toBe(
+ 'settings.userProfile.copyUserId.display:user-123',
+ );
- fireEvent.click(nameButton);
+ fireEvent.click(idButton);
await waitFor(() => expect(mocks.writeText).toHaveBeenCalledWith('user-123'));
expect(mocks.toastSuccess).toHaveBeenCalledWith('settings.userProfile.copyUserId.success');
});
+ it('abbreviates a long user ID in the display while copying the full value', async () => {
+ mocks.authState.user!.id = 'mem_0123456789abcdef0123456789abcdef';
+ renderCard();
+
+ // 展示只露头 6 + 尾 4,完整值不直接渲染。
+ expect(screen.getByText('settings.userProfile.copyUserId.display:mem_01…cdef')).toBeTruthy();
+ expect(
+ screen.queryByText(
+ 'settings.userProfile.copyUserId.display:mem_0123456789abcdef0123456789abcdef',
+ ),
+ ).toBeNull();
+
+ fireEvent.click(screen.getByRole('button', { name: 'settings.userProfile.copyUserId.action' }));
+
+ await waitFor(() =>
+ expect(mocks.writeText).toHaveBeenCalledWith('mem_0123456789abcdef0123456789abcdef'),
+ );
+ });
+
it('opens the profile edit dialog when the avatar is clicked', () => {
renderCard();
diff --git a/apps/desktop/src/renderer/components/settings/UserProfileCard.tsx b/apps/desktop/src/renderer/components/settings/UserProfileCard.tsx
index f4a00434fd..64babc885a 100644
--- a/apps/desktop/src/renderer/components/settings/UserProfileCard.tsx
+++ b/apps/desktop/src/renderer/components/settings/UserProfileCard.tsx
@@ -1,6 +1,6 @@
-import { useEffect, useState } from 'react';
+import { useEffect, useId, useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { Building2, Pencil } from 'lucide-react';
+import { Building2, Copy, Pencil } from 'lucide-react';
import { useNavigate } from 'react-router-dom';
import { cn } from '@/lib/utils';
@@ -24,6 +24,11 @@ function getOrganizationRoleI18nKey(role: string) {
return ORGANIZATION_ROLE_I18N_KEYS[isOrganizationRole(role) ? role : 'member'];
}
+// 展示用缩写:长 ID 只露头尾便于目视比对,点击复制的仍是完整值。
+function abbreviateUserId(id: string): string {
+ return id.length > 14 ? `${id.slice(0, 6)}…${id.slice(-4)}` : id;
+}
+
export function UserProfileCard() {
const { user, mode, exitLocalMode } = useAuth();
const navigate = useNavigate();
@@ -31,6 +36,9 @@ export function UserProfileCard() {
const [orgLogoError, setOrgLogoError] = useState(false);
const [editOpen, setEditOpen] = useState(false);
const { t } = useTranslation();
+ // aria-label(动作)会覆盖子文本作为可访问名称;可见的 ID 文本经 aria-describedby
+ // 暴露给辅助技术,让读屏用户复制前也能核对 ID。
+ const userIdDescriptionId = useId();
// 换头像(服务端资料更新)后给新地址重试的机会,
// 不让一次历史加载失败永远钉死在首字母兜底上。
@@ -150,22 +158,28 @@ export function UserProfileCard() {
)}
</button>
- {/* User name — 点击复制用户 ID;hover / cursor 明示可交互。 */}
<div className="min-w-0 flex-1">
+ <p className="min-w-0 truncate text-18 font-medium leading-[1.2] text-[var(--settings-profile-name)]">
+ {displayName}
+ </p>
+ {/* User ID — 显式展示,整行点击复制;常驻小图标明示可复制。 */}
<button
type="button"
onClick={() => void handleCopyUserId()}
aria-label={t('settings.userProfile.copyUserId.action')}
+ aria-describedby={userIdDescriptionId}
title={t('settings.userProfile.copyUserId.action')}
className={cn(
- '-ml-2 flex min-w-0 max-w-full cursor-pointer items-center rounded-lg px-2 py-1 text-left',
- 'transition-colors hover:bg-[var(--settings-profile-avatar-bg)]',
+ '-ml-1.5 mt-0.5 flex min-w-0 max-w-full cursor-pointer items-center gap-1 rounded-full px-1.5 py-0.5 text-left',
+ 'text-12 text-[var(--text-tertiary)] transition-colors',
+ 'hover:bg-[var(--settings-profile-avatar-bg)] hover:text-[var(--text-secondary)]',
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring-soft)]',
)}
>
- <span className="min-w-0 truncate text-18 font-medium leading-[1.2] text-[var(--settings-profile-name)]">
- {displayName}
+ <span id={userIdDescriptionId} className="min-w-0 truncate">
+ {t('settings.userProfile.copyUserId.display', { id: abbreviateUserId(user.id) })}
</span>
+ <Copy aria-hidden="true" size={11} className="shrink-0" />
</button>
{organizationName && organizationRole && (
<div className="mt-1 flex min-w-0 items-center gap-1.5 text-sm leading-5 text-[var(--text-secondary)]">
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 18b0a47dd7..25477f2f30 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -556,6 +556,7 @@
},
"copyUserId": {
"action": "Copy user ID",
+ "display": "ID: {{id}}",
"success": "User ID copied",
"failed": "Failed to copy user ID"
},
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 7cd67399a5..fdb20944b1 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -556,6 +556,7 @@
},
"copyUserId": {
"action": "ユーザー ID をコピー",
+ "display": "ID: {{id}}",
"success": "ユーザー ID をコピーしました",
"failed": "ユーザー ID をコピーできませんでした"
},
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index d37a6fb54a..dd6e8a107e 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -556,6 +556,7 @@
},
"copyUserId": {
"action": "사용자 ID 복사",
+ "display": "ID: {{id}}",
"success": "사용자 ID를 복사했습니다",
"failed": "사용자 ID를 복사하지 못했습니다"
},
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 8c59c5774a..21777084cf 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -556,6 +556,7 @@
},
"copyUserId": {
"action": "复制用户 ID",
+ "display": "ID:{{id}}",
"success": "用户 ID 已复制",
"failed": "复制用户 ID 失败"
},