From ce0ccb86d1eb51098e9a5b1a60410dfbf8f1100a Mon Sep 17 00:00:00 2001 From: Hamhire Hu Date: Fri, 19 Jun 2026 16:28:46 +0800 Subject: [PATCH] =?UTF-8?q?refactor(common):=20components/common=20?= =?UTF-8?q?=E6=94=B6=E6=95=9B=20index=20barrel=EF=BC=8C=E5=9F=9F=E5=A4=96?= =?UTF-8?q?=20import=20=E7=BB=9F=E4=B8=80=E8=B5=B0=20barrel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 components/common/index.ts,re-export 12 个通用模块(Avatar / BitbucketImage / ConfirmModal / ErrorBoundary / LlmProviderIcon / Loading / MermaidDiagram / Modal / PlatformIcon / StatusChip / icons / markdownMermaid)。 跨域消费方(features/* · layout/* · App 等)50 个文件、80 条 `common/` 子路径 import 统一收敛为走 barrel 的单条引入(与 features/pr · settings · onboarding barrel 约定一致); common 内部模块相互引用(markdownMermaid → MermaidDiagram、Modal → icons、 ConfirmModal → Modal)仍走相对路径,不经 barrel,避免循环依赖。 纯 import 路径收敛,无逻辑改动。lint / typecheck / build 通过。 Co-Authored-By: Claude Opus 4.8 (1M context) --- .../renderer/src/components/common/index.ts | 16 ++++++++++ .../src/components/features/chat/ChatPane.tsx | 4 +-- .../features/chat/components/AgentStep.tsx | 2 +- .../features/chat/components/ChatEmpty.tsx | 2 +- .../features/chat/components/ChatInputBar.tsx | 9 ++++-- .../chat/components/ConversationMessage.tsx | 2 +- .../features/chat/components/FindingCard.tsx | 3 +- .../features/chat/components/QueuedView.tsx | 2 +- .../chat/components/RulePreviewModal.tsx | 3 +- .../chat/components/RunResultView.tsx | 2 +- .../features/chat/components/shared.tsx | 3 +- .../features/chat/statusbar/AutopilotChip.tsx | 11 ++----- .../chat/statusbar/PrAgentActiveChip.tsx | 6 ++-- .../features/onboarding/steps/DoneStep.tsx | 2 +- .../features/onboarding/steps/LlmStep.tsx | 2 +- .../onboarding/steps/PlatformStep.tsx | 3 +- .../features/onboarding/steps/WelcomeStep.tsx | 2 +- .../src/components/features/pr/PrHeader.tsx | 6 ++-- .../src/components/features/pr/PrItem.tsx | 9 ++++-- .../src/components/features/pr/PrPanel.tsx | 2 +- .../features/pr/statusbar/LastSyncChip.tsx | 3 +- .../features/pr/statusbar/PrsCountChip.tsx | 3 +- .../features/pr/statusbar/RepoSyncChip.tsx | 2 +- .../features/pr/tabs/CommitsPanel.tsx | 7 +++-- .../features/pr/tabs/PrInfoView.tsx | 12 +++++--- .../components/features/pr/tabs/PrTabs.tsx | 2 +- .../pr/tabs/activity/ActivityPanel.tsx | 12 ++++++-- .../features/pr/tabs/comments/CommentItem.tsx | 12 ++++---- .../features/pr/tabs/diff/DiffPane.tsx | 2 +- .../features/pr/tabs/diff/DiffScopeSelect.tsx | 3 +- .../features/pr/tabs/diff/DiffView.tsx | 4 +-- .../features/pr/tabs/diff/FileTree.tsx | 2 +- .../pr/tabs/diff/blame/BlameColumn.tsx | 2 +- .../inline-comments/InlineCommentZone.tsx | 4 +-- .../features/pr/tabs/drafts/DraftZone.tsx | 8 ++--- .../features/pr/tabs/drafts/DraftsPanel.tsx | 30 +++++++++---------- .../pr/tabs/shared/CommentMarkdown.tsx | 2 +- .../features/settings/ConnectionForm.tsx | 13 ++++++-- .../features/settings/LlmProfileForm.tsx | 16 ++++++---- .../features/settings/SettingsModal.tsx | 3 +- .../editors/ConnectionEditorModal.tsx | 2 +- .../settings/editors/LlmEditorModal.tsx | 2 +- .../settings/editors/ProxyEditorModal.tsx | 12 +++++--- .../settings/sections/AgentDirSection.tsx | 2 +- .../settings/sections/CacheDirSection.tsx | 2 +- .../settings/sections/ConnectionsSection.tsx | 3 +- .../features/settings/sections/LlmSection.tsx | 8 +++-- .../settings/sections/RuntimeSection.tsx | 10 ++----- .../features/settings/statusbar/LlmChip.tsx | 2 +- .../features/settings/statusbar/UserChip.tsx | 2 +- .../src/components/layout/StatusBar.tsx | 7 +++-- 51 files changed, 158 insertions(+), 127 deletions(-) create mode 100644 apps/desktop/src/renderer/src/components/common/index.ts diff --git a/apps/desktop/src/renderer/src/components/common/index.ts b/apps/desktop/src/renderer/src/components/common/index.ts new file mode 100644 index 0000000..38bb6a4 --- /dev/null +++ b/apps/desktop/src/renderer/src/components/common/index.ts @@ -0,0 +1,16 @@ +// components/common 对外公共 API barrel:通用展示组件 + 图标 + markdown 渲染工具。 +// 跨域消费方(features/* · layout/* · App 等)经此 barrel 引入;common 内部模块相互引用 +// (markdownMermaid → MermaidDiagram、Modal → icons、ConfirmModal → Modal)走相对路径, +// 不经此 barrel,避免循环依赖。 +export * from './Avatar'; +export * from './BitbucketImage'; +export * from './ConfirmModal'; +export * from './ErrorBoundary'; +export * from './LlmProviderIcon'; +export * from './Loading'; +export * from './MermaidDiagram'; +export * from './Modal'; +export * from './PlatformIcon'; +export * from './StatusChip'; +export * from './icons'; +export * from './markdownMermaid'; diff --git a/apps/desktop/src/renderer/src/components/features/chat/ChatPane.tsx b/apps/desktop/src/renderer/src/components/features/chat/ChatPane.tsx index 8fc8c40..8b1bc89 100644 --- a/apps/desktop/src/renderer/src/components/features/chat/ChatPane.tsx +++ b/apps/desktop/src/renderer/src/components/features/chat/ChatPane.tsx @@ -1,9 +1,7 @@ import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import type { LocalPrStatus, PrAgentStatus, StoredPullRequest } from '@meebox/shared'; -import { ChatIcon, TrashIcon } from '../../common/icons'; -import { ConfirmModal } from '../../common/ConfirmModal'; -import { PaneLoading } from '../../common/Loading'; +import { ChatIcon, TrashIcon, ConfirmModal, PaneLoading } from '../../common'; import { useChatRunStore } from '../../../stores/chat-run-store'; import { useDraftsForPr } from '../../../stores/drafts-store'; import { CHAT_MAX_WIDTH, CHAT_MIN_WIDTH } from './constants'; diff --git a/apps/desktop/src/renderer/src/components/features/chat/components/AgentStep.tsx b/apps/desktop/src/renderer/src/components/features/chat/components/AgentStep.tsx index 1c3c8d6..5c418de 100644 --- a/apps/desktop/src/renderer/src/components/features/chat/components/AgentStep.tsx +++ b/apps/desktop/src/renderer/src/components/features/chat/components/AgentStep.tsx @@ -1,7 +1,7 @@ import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import type { AgentStep } from '@meebox/shared'; -import { RobotIcon } from '../../../common/icons'; +import { RobotIcon } from '../../../common'; import { formatElapsed, formatTokens } from '../utils/format'; import { Spinner } from './shared'; diff --git a/apps/desktop/src/renderer/src/components/features/chat/components/ChatEmpty.tsx b/apps/desktop/src/renderer/src/components/features/chat/components/ChatEmpty.tsx index f3d351d..55d3f04 100644 --- a/apps/desktop/src/renderer/src/components/features/chat/components/ChatEmpty.tsx +++ b/apps/desktop/src/renderer/src/components/features/chat/components/ChatEmpty.tsx @@ -1,6 +1,6 @@ import { useTranslation } from 'react-i18next'; import type { PrAgentStatus, StoredPullRequest } from '@meebox/shared'; -import { ChatIcon } from '../../../common/icons'; +import { ChatIcon } from '../../../common'; import { Bullet } from './shared'; export function ChatEmpty({ diff --git a/apps/desktop/src/renderer/src/components/features/chat/components/ChatInputBar.tsx b/apps/desktop/src/renderer/src/components/features/chat/components/ChatInputBar.tsx index 2616b37..820c16c 100644 --- a/apps/desktop/src/renderer/src/components/features/chat/components/ChatInputBar.tsx +++ b/apps/desktop/src/renderer/src/components/features/chat/components/ChatInputBar.tsx @@ -1,7 +1,12 @@ import { useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import type { LocalPrStatus, PrAgentStatus, ReviewRunTool, StoredPullRequest } from '@meebox/shared'; -import { AutoReviewIcon, SendIcon, StopIcon } from '../../../common/icons'; +import type { + LocalPrStatus, + PrAgentStatus, + ReviewRunTool, + StoredPullRequest, +} from '@meebox/shared'; +import { AutoReviewIcon, SendIcon, StopIcon } from '../../../common'; import { COMMANDS, type CommandSpec } from '../commands'; import { loadChatHistory, pushChatHistory } from '../utils/chat-history'; diff --git a/apps/desktop/src/renderer/src/components/features/chat/components/ConversationMessage.tsx b/apps/desktop/src/renderer/src/components/features/chat/components/ConversationMessage.tsx index 54a06e6..d27bd01 100644 --- a/apps/desktop/src/renderer/src/components/features/chat/components/ConversationMessage.tsx +++ b/apps/desktop/src/renderer/src/components/features/chat/components/ConversationMessage.tsx @@ -1,6 +1,6 @@ import { useTranslation } from 'react-i18next'; import type { AgentMessage } from '@meebox/shared'; -import { ChatIcon } from '../../../common/icons'; +import { ChatIcon } from '../../../common'; import { VERDICT_LABEL_KEY } from '../constants'; import { Md } from './shared'; diff --git a/apps/desktop/src/renderer/src/components/features/chat/components/FindingCard.tsx b/apps/desktop/src/renderer/src/components/features/chat/components/FindingCard.tsx index c3094cc..5ec260a 100644 --- a/apps/desktop/src/renderer/src/components/features/chat/components/FindingCard.tsx +++ b/apps/desktop/src/renderer/src/components/features/chat/components/FindingCard.tsx @@ -4,8 +4,7 @@ import ReactMarkdown from 'react-markdown'; import remarkBreaks from 'remark-breaks'; import remarkGfm from 'remark-gfm'; import type { Finding, PrDocSectionKey, ReviewDraft } from '@meebox/shared'; -import { ChevronIcon } from '../../../common/icons'; -import { mermaidComponents, walkthroughMdComponents } from '../../../common/markdownMermaid'; +import { ChevronIcon, mermaidComponents, walkthroughMdComponents } from '../../../common'; import { REMOTE_REHYPE_PLUGINS } from '../../../../lib/markdown'; import { translatePrAgentLabels } from '../../../../utils/translate-pr-agent'; import { diff --git a/apps/desktop/src/renderer/src/components/features/chat/components/QueuedView.tsx b/apps/desktop/src/renderer/src/components/features/chat/components/QueuedView.tsx index 2319e28..a6491b8 100644 --- a/apps/desktop/src/renderer/src/components/features/chat/components/QueuedView.tsx +++ b/apps/desktop/src/renderer/src/components/features/chat/components/QueuedView.tsx @@ -1,7 +1,7 @@ import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import type { ReviewRunTool } from '@meebox/shared'; -import { CloseIcon } from '../../../common/icons'; +import { CloseIcon } from '../../../common'; import { AskQuestion } from './shared'; /** diff --git a/apps/desktop/src/renderer/src/components/features/chat/components/RulePreviewModal.tsx b/apps/desktop/src/renderer/src/components/features/chat/components/RulePreviewModal.tsx index d9ba3a7..7c6a91a 100644 --- a/apps/desktop/src/renderer/src/components/features/chat/components/RulePreviewModal.tsx +++ b/apps/desktop/src/renderer/src/components/features/chat/components/RulePreviewModal.tsx @@ -2,8 +2,7 @@ import { useTranslation } from 'react-i18next'; import ReactMarkdown from 'react-markdown'; import remarkBreaks from 'remark-breaks'; import remarkGfm from 'remark-gfm'; -import { Modal } from '../../../common/Modal'; -import { mermaidComponents } from '../../../common/markdownMermaid'; +import { Modal, mermaidComponents } from '../../../common'; import { REMOTE_REHYPE_PLUGINS } from '../../../../lib/markdown'; import type { MatchedRule } from '../types'; diff --git a/apps/desktop/src/renderer/src/components/features/chat/components/RunResultView.tsx b/apps/desktop/src/renderer/src/components/features/chat/components/RunResultView.tsx index 83e7f25..847752d 100644 --- a/apps/desktop/src/renderer/src/components/features/chat/components/RunResultView.tsx +++ b/apps/desktop/src/renderer/src/components/features/chat/components/RunResultView.tsx @@ -1,7 +1,7 @@ import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import type { Finding, ReviewDraft, ReviewRun } from '@meebox/shared'; -import { RetryIcon } from '../../../common/icons'; +import { RetryIcon } from '../../../common'; import { orderFindings } from '../utils/findings'; import { formatStartTime, formatTokens, runStatusLabel } from '../utils/format'; import { extractTokenUsage, type TokenUsage } from '../utils/tokens'; diff --git a/apps/desktop/src/renderer/src/components/features/chat/components/shared.tsx b/apps/desktop/src/renderer/src/components/features/chat/components/shared.tsx index c29fb18..228898b 100644 --- a/apps/desktop/src/renderer/src/components/features/chat/components/shared.tsx +++ b/apps/desktop/src/renderer/src/components/features/chat/components/shared.tsx @@ -3,8 +3,7 @@ import { useTranslation } from 'react-i18next'; import ReactMarkdown from 'react-markdown'; import remarkBreaks from 'remark-breaks'; import remarkGfm from 'remark-gfm'; -import { QuestionIcon } from '../../../common/icons'; -import { mermaidComponents } from '../../../common/markdownMermaid'; +import { QuestionIcon, mermaidComponents } from '../../../common'; import { REMOTE_REHYPE_PLUGINS } from '../../../../lib/markdown'; import { parseAnsi, segmentStyle } from '../../../../utils/ansi'; diff --git a/apps/desktop/src/renderer/src/components/features/chat/statusbar/AutopilotChip.tsx b/apps/desktop/src/renderer/src/components/features/chat/statusbar/AutopilotChip.tsx index e8bebbf..6d56cc5 100644 --- a/apps/desktop/src/renderer/src/components/features/chat/statusbar/AutopilotChip.tsx +++ b/apps/desktop/src/renderer/src/components/features/chat/statusbar/AutopilotChip.tsx @@ -1,17 +1,10 @@ import { useTranslation } from 'react-i18next'; -import { RobotIcon, RobotOffIcon } from '../../../common/icons'; -import { StatusChip } from '../../../common/StatusChip'; +import { RobotIcon, RobotOffIcon, StatusChip } from '../../../common'; /** * AutoPilot 开关 chip:默认关,点击切换(持久化到 agent.autopilot.enabled,下次 poll 生效)。 */ -export function AutopilotChip({ - enabled, - onToggle, -}: { - enabled: boolean; - onToggle: () => void; -}) { +export function AutopilotChip({ enabled, onToggle }: { enabled: boolean; onToggle: () => void }) { const { t } = useTranslation(); return (