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。

fix(settings): wrap IM channel headers within available width

shenjiachengffba9290888d
diff --git a/apps/desktop/scripts/fixtures/wechat-companion/ui-page.mjs b/apps/desktop/scripts/fixtures/wechat-companion/ui-page.mjs
index a9e68eb67a..18ef119ede 100644
--- a/apps/desktop/scripts/fixtures/wechat-companion/ui-page.mjs
+++ b/apps/desktop/scripts/fixtures/wechat-companion/ui-page.mjs
@@ -9,8 +9,101 @@ export default {
existing: { about: 'Reuse the already authorized personal WeChat connection', data: { bound: true } },
assigned: { about: 'Connected teammate and remove-link action', data: { bound: true, companionBotId: 'fixture-cindy' } },
other: { about: 'Another teammate owns this connection', data: { bound: true, companionBotId: 'fixture-other' } },
+ 'sidebar-394': {
+ about: '#6706: 394px card in a wide window',
+ viewport: { width: 1280, height: 900 },
+ data: { bound: true, companionBotId: 'fixture-cindy', botName: 'Alfred', cardWidth: 394 },
+ },
+ 'sidebar-320': {
+ about: '320px card keeps summary, status and chevron visible',
+ viewport: { width: 1280, height: 900 },
+ data: { bound: true, companionBotId: 'fixture-cindy', cardWidth: 320 },
+ },
+ 'wide-settings': {
+ about: '760px settings card keeps a compact horizontal header',
+ viewport: { width: 1280, height: 900 },
+ data: { bound: true, companionBotId: 'fixture-cindy', cardWidth: 760 },
+ },
+ 'long-name': {
+ about: 'Long unbroken teammate name wraps without hiding the connected status',
+ viewport: { width: 1280, height: 1000 },
+ data: { bound: true, companionBotId: 'fixture-cindy', cardWidth: 394, botName: 'AlfredResearchAndEngineeringCompanionWithAVeryLongName' },
+ },
+ 'header-action': {
+ about: 'Independent sibling-channel switch and long route summary at 320px',
+ viewport: { width: 1280, height: 1100 },
+ data: { bound: true, companionBotId: 'fixture-cindy', cardWidth: 320, headerAction: true, summary: 'Claude Code · ALongUnbrokenProviderAndModelRouteSummaryForTheChannel' },
+ },
+ 'header-action-empty': {
+ about: 'Independent switch without a route summary in a wide settings card',
+ viewport: { width: 1280, height: 900 },
+ data: { cardWidth: 760, headerAction: true },
+ },
},
- async check(page) {
- await page.locator('#companion-im-wechat-trigger').click();
+ // Browser/e2e regression for #6706. The existing jsdom unit test covers
+ // accordion semantics but cannot detect flex shrink or viewport breakpoints.
+ // Minimal failure: 394px assigned WeChat card inside a 1280px viewport.
+ async check(page, ui) {
+ const trigger = page.locator('#companion-im-wechat-trigger');
+ await trigger.getByRole('status').waitFor();
+ if (ui.data.companionBotId === 'fixture-cindy') {
+ await trigger.getByText(ui.data.botName ?? 'Cindy', { exact: true }).waitFor({ state: 'attached' });
+ }
+ const measureHeader = async (button) => button.evaluate((element) => {
+ const text = element.firstElementChild;
+ const title = text.firstElementChild;
+ const range = document.createRange();
+ range.selectNodeContents(title);
+ const status = element.querySelector('[role=status]');
+ const chevron = element.querySelector('svg');
+ const bounds = element.getBoundingClientRect();
+ const visible = (node) => {
+ const rect = node.getBoundingClientRect();
+ return rect.width > 0 && rect.height > 0 && rect.left >= bounds.left && rect.right <= bounds.right;
+ };
+ const summary = text.nextElementSibling.firstElementChild;
+ return {
+ textWidth: text.getBoundingClientRect().width,
+ titleLines: range.getClientRects().length,
+ statusVisible: visible(status),
+ chevronVisible: visible(chevron),
+ summaryVisible: summary.contains(status) || summary === status || (visible(summary) && summary.scrollWidth <= summary.clientWidth + 1),
+ textTop: text.getBoundingClientRect().top,
+ statusTop: status.getBoundingClientRect().top,
+ textBottom: text.getBoundingClientRect().bottom,
+ };
+ });
+ const assertHeader = async (button) => {
+ const metrics = await measureHeader(button);
+ if (metrics.textWidth < 160 || metrics.titleLines !== 1 || !metrics.statusVisible || !metrics.chevronVisible || !metrics.summaryVisible) {
+ throw new Error(`Unreadable channel header: ${JSON.stringify(metrics)}`);
+ }
+ return metrics;
+ };
+ await ui.capture('collapsed');
+ const metrics = await assertHeader(trigger);
+ if (ui.case === 'wide-settings' && metrics.statusTop >= metrics.textBottom) {
+ throw new Error('Wide settings card unnecessarily stacks its header');
+ }
+ await trigger.click();
+ await page.locator('#companion-im-wechat-panel').waitFor();
+ await assertHeader(trigger);
+ await ui.capture('expanded');
+ await trigger.click();
+ if (await trigger.getAttribute('aria-expanded') !== 'false') throw new Error('Card did not collapse');
+ if (ui.data.headerAction) {
+ const actionTrigger = page.locator('#fixture-action-trigger');
+ if (ui.data.summary) await actionTrigger.getByText(ui.data.summary, { exact: true }).waitFor({ state: 'attached' });
+ const action = page.getByRole('switch', { name: 'Enable Slack' });
+ await action.click();
+ if (await action.getAttribute('aria-checked') !== 'true' || await actionTrigger.getAttribute('aria-expanded') !== 'false') {
+ throw new Error('Independent header switch toggled the accordion or failed to enable');
+ }
+ await assertHeader(actionTrigger);
+ await actionTrigger.click();
+ await page.locator('#fixture-action-panel').waitFor();
+ await assertHeader(actionTrigger);
+ await ui.capture('header-action-expanded');
+ }
},
};
diff --git a/apps/desktop/scripts/fixtures/wechat-companion/wechat-companion-fixture.tsx b/apps/desktop/scripts/fixtures/wechat-companion/wechat-companion-fixture.tsx
index 12fbc82906..74ed002b32 100644
--- a/apps/desktop/scripts/fixtures/wechat-companion/wechat-companion-fixture.tsx
+++ b/apps/desktop/scripts/fixtures/wechat-companion/wechat-companion-fixture.tsx
@@ -1,7 +1,30 @@
+import { useState } from 'react';
+
import { BotChannelsPage } from '../../../src/renderer/features/bots/BotChannelsPage';
import type { BotProfile } from '../../../src/renderer/features/bots/botStore';
+import { ImChannelSettingsCard } from '../../../src/renderer/components/settings/ImChannelSettingsCard';
+import { Switch } from '../../../src/renderer/components/ui/switch';
import { mountPage, subscription, forbid } from '../../ui-page/harness';
+function HeaderActionCard({ summary }: { summary: string | null }) {
+ const [expanded, setExpanded] = useState(false);
+ const [enabled, setEnabled] = useState(false);
+ return (
+ <ImChannelSettingsCard
+ id="fixture-action"
+ title="Slack"
+ description="Cindy channel"
+ routeSummary={summary}
+ status={<span role="status">Connected</span>}
+ headerAction={<Switch aria-label="Enable Slack" checked={enabled} onCheckedChange={setEnabled} />}
+ expanded={expanded}
+ onToggle={() => setExpanded((value) => !value)}
+ >
+ <span>Channel settings</span>
+ </ImChannelSettingsCard>
+ );
+}
+
mountPage({
host: (ctx) => ({
botImConnection: {
@@ -21,7 +44,13 @@ mountPage({
unbind: forbid('wechatBot.unbind'),
},
}),
- render: () => <div className="mx-auto max-w-2xl p-4"><BotChannelsPage bot={{
- id: 'fixture-cindy', name: 'Cindy', status: 'active',
- } as BotProfile} /></div>,
+ render: (ctx) => <div className="mx-auto flex max-w-full flex-col gap-4 p-4"
+ style={{ width: Number(ctx.data.cardWidth ?? 586) + 32 }}>
+ <BotChannelsPage bot={{
+ id: 'fixture-cindy', name: ctx.data.botName ?? 'Cindy', status: 'active',
+ } as BotProfile} />
+ {ctx.data.headerAction ? (
+ <HeaderActionCard summary={typeof ctx.data.summary === 'string' ? ctx.data.summary : null} />
+ ) : null}
+ </div>,
});
diff --git a/apps/desktop/src/renderer/components/settings/ImChannelSettingsCard.tsx b/apps/desktop/src/renderer/components/settings/ImChannelSettingsCard.tsx
index 81eff85e4b..51a9ca5b44 100644
--- a/apps/desktop/src/renderer/components/settings/ImChannelSettingsCard.tsx
+++ b/apps/desktop/src/renderer/components/settings/ImChannelSettingsCard.tsx
@@ -88,11 +88,11 @@ export function ImChannelSettingsCard({
aria-controls={panelId}
onClick={onToggle}
className={cn(
- 'flex min-h-[76px] min-w-0 flex-1 select-none items-center gap-4 px-4 py-3 text-left',
+ 'flex min-h-[76px] min-w-0 flex-1 select-none flex-wrap items-center gap-x-4 gap-y-2 px-4 py-3 text-left',
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--focus-ring)]',
)}
>
- <span className="min-w-0 flex-1">
+ <span className="min-w-0 flex-[1_1_12rem] [overflow-wrap:anywhere]">
<span className="block text-14 font-medium leading-[1.3] text-[var(--settings-section-title)]">
{title}
</span>
@@ -101,11 +101,18 @@ export function ImChannelSettingsCard({
</span>
</span>
- <span className="flex min-w-0 shrink-0 items-center gap-3">
- {routeSummary ? <span className="hidden w-[220px] truncate text-right text-12 text-[var(--text-secondary)] md:block">
- {routeSummary}
- </span> : null}
- {status}
+ {/* Wrap using the trigger's available width, including any sibling
+ headerAction, rather than the window width of a narrow sidebar. */}
+ <span className={cn(
+ 'flex min-w-0 max-w-full items-center justify-end gap-3',
+ routeSummary ? 'flex-[1_1_18rem]' : 'shrink-0',
+ )}>
+ {routeSummary ? (
+ <span className="min-w-0 max-w-[220px] flex-1 text-right text-12 text-[var(--text-secondary)] [overflow-wrap:anywhere]">
+ {routeSummary}
+ </span>
+ ) : null}
+ <span className="inline-flex shrink-0 whitespace-nowrap">{status}</span>
<ChevronDown
size={17}
aria-hidden