From 932b2d3d7f5eff6538044fbd513ceb6456a9b544 Mon Sep 17 00:00:00 2001 From: duanfuxiang Date: Sun, 6 Jul 2025 07:20:07 +0800 Subject: [PATCH] Optimize the insight view component, add internationalization support, update log output, improve user interaction prompts, and ensure better user experience and code readability. --- src/components/chat-view/InsightView.tsx | 104 +++++++++++------------ src/lang/locale/en.ts | 67 +++++++++++++++ src/lang/locale/zh-cn.ts | 67 +++++++++++++++ 3 files changed, 186 insertions(+), 52 deletions(-) diff --git a/src/components/chat-view/InsightView.tsx b/src/components/chat-view/InsightView.tsx index d663af1..72a7189 100644 --- a/src/components/chat-view/InsightView.tsx +++ b/src/components/chat-view/InsightView.tsx @@ -67,9 +67,9 @@ const InsightView = () => { // 设置范围信息 let scopeDescription = '' if (currentWorkspace) { - scopeDescription = `工作区: ${currentWorkspace.name}` + scopeDescription = `${t('insights.fileGroup.workspacePrefix')} ${currentWorkspace.name}` } else { - scopeDescription = '整个 Vault' + scopeDescription = t('insights.stats.scopeLabel') + ' ' + t('workspace.entireVault') } setCurrentScope(scopeDescription) @@ -192,7 +192,7 @@ const InsightView = () => { // 设置初始进度状态 setInitProgress({ - stage: '准备初始化工作区洞察', + stage: t('insights.stage.preparing'), current: 0, total: 1, currentItem: currentWorkspace.name @@ -217,10 +217,10 @@ const InsightView = () => { // 更新进度为完成状态 setInitProgress({ - stage: '正在完成初始化', + stage: t('insights.stage.completing'), current: 1, total: 1, - currentItem: '保存结果' + currentItem: t('insights.stage.savingResults') }) if (result.success) { @@ -228,15 +228,15 @@ const InsightView = () => { await loadInsights() // 显示成功消息 - console.log(`工作区 "${currentWorkspace.name}" 洞察初始化成功`) + console.log(t('insights.success.workspaceInitialized', { name: currentWorkspace.name })) } else { - console.error('工作区洞察初始化失败:', result.error) - throw new Error(result.error || '初始化失败') + console.error(t('insights.error.initializationFailed'), result.error) + throw new Error(result.error || t('insights.error.initializationFailed')) } } catch (error) { - console.error('初始化工作区洞察时出错:', error) - // 可以在这里添加错误提示 + console.error(t('insights.error.initializationFailed'), error) + setInsightResults([]) } finally { setIsInitializing(false) setInitProgress(null) @@ -266,19 +266,19 @@ const InsightView = () => { if (result.success) { const workspaceName = currentWorkspace?.name || 'vault' - console.log(`工作区 "${workspaceName}" 的 ${result.deletedCount} 个转换已成功删除`) + console.log(t('insights.success.workspaceDeleted', { name: workspaceName, count: result.deletedCount })) // 刷新洞察列表 await loadInsights() // 可以在这里添加用户通知,比如显示删除成功的消息 } else { - console.error('删除工作区洞察失败:', result.error) + console.error(t('insights.error.deletionFailed'), result.error) // 可以在这里添加错误提示 } } catch (error) { - console.error('删除工作区洞察时出错:', error) + console.error(t('insights.error.deletionFailed'), error) // 可以在这里添加错误提示 } finally { setIsDeleting(false) @@ -307,17 +307,17 @@ const InsightView = () => { const result = await transEngine.deleteSingleInsight(insightId) if (result.success) { - console.log(`洞察 ID ${insightId} 已成功删除`) + console.log(t('insights.success.insightDeleted', { id: insightId })) // 刷新洞察列表 await loadInsights() } else { - console.error('删除洞察失败:', result.error) + console.error(t('insights.error.singleDeletionFailed'), result.error) // 可以在这里添加错误提示 } } catch (error) { - console.error('删除洞察时出错:', error) + console.error(t('insights.error.singleDeletionFailed'), error) // 可以在这里添加错误提示 } finally { setDeletingInsightId(null) @@ -341,7 +341,7 @@ const InsightView = () => { // 检查路径是否存在 if (!insight.source_path) { - console.error('❌ [InsightView] 文件路径为空') + console.error(t('insights.error.fileNotFound') + ' ' + insight.source_path) return } @@ -367,14 +367,14 @@ const InsightView = () => { } console.debug('✅ [InsightView] 在文件管理器中显示文件夹') } else { - console.warn('❌ [InsightView] 文件夹不存在:', insight.source_path) + console.warn(t('insights.error.folderNotFound'), insight.source_path) } return } else { // 文件洞察 - 正常打开文件 const file = app.vault.getFileByPath(insight.source_path) if (!file) { - console.error('❌ [InsightView] 在vault中找不到文件:', insight.source_path) + console.error(t('insights.error.fileNotFound'), insight.source_path) return } @@ -422,10 +422,10 @@ const InsightView = () => { // 根据源路径类型确定显示名称和类型 if (sourcePath.startsWith('workspace:')) { const workspaceName = sourcePath.replace('workspace:', '') - displayName = `🌐 工作区: ${workspaceName}` + displayName = `${t('insights.fileGroup.workspacePrefix')} ${workspaceName}` groupType = 'workspace' } else if (result.source_type === 'folder') { - displayName = `📁 ${sourcePath.split('/').pop() || sourcePath}` + displayName = `${t('insights.fileGroup.folderPrefix')} ${sourcePath.split('/').pop() || sourcePath}` groupType = 'folder' } else { displayName = sourcePath.split('/').pop() || sourcePath @@ -472,12 +472,12 @@ const InsightView = () => { // 获取洞察类型的显示名称 const getInsightTypeDisplayName = (insightType: string) => { const typeMapping: Record = { - 'dense_summary': '📋 密集摘要', - 'simple_summary': '📄 简单摘要', - 'key_insights': '💡 关键洞察', - 'analyze_paper': '🔬 论文分析', - 'table_of_contents': '📑 目录大纲', - 'reflections': '🤔 思考反思' + 'dense_summary': t('insights.types.denseSummary'), + 'simple_summary': t('insights.types.simpleSummary'), + 'key_insights': t('insights.types.keyInsights'), + 'analyze_paper': t('insights.types.analyzePaper'), + 'table_of_contents': t('insights.types.tableOfContents'), + 'reflections': t('insights.types.reflections') } return typeMapping[insightType] || insightType.toUpperCase() } @@ -487,30 +487,30 @@ const InsightView = () => { {/* 头部信息 */}
-

{t('insights.title') || 'AI 洞察'}

+

{t('insights.title')}

@@ -519,23 +519,23 @@ const InsightView = () => { {hasLoaded && !isLoading && (
- {insightGroupedResults.length} 个项目,{insightResults.length} 个洞察 + {t('insights.stats.itemsAndInsights', { items: insightGroupedResults.length, insights: insightResults.length })} {insightGroupedResults.length > 0 && ( {' '}( {insightGroupedResults.filter(g => g.groupType === 'workspace').length > 0 && - `${insightGroupedResults.filter(g => g.groupType === 'workspace').length}工作区 `} + `${t('insights.stats.workspace', { count: insightGroupedResults.filter(g => g.groupType === 'workspace').length })} `} {insightGroupedResults.filter(g => g.groupType === 'folder').length > 0 && - `${insightGroupedResults.filter(g => g.groupType === 'folder').length}文件夹 `} + `${t('insights.stats.folder', { count: insightGroupedResults.filter(g => g.groupType === 'folder').length })} `} {insightGroupedResults.filter(g => g.groupType === 'file').length > 0 && - `${insightGroupedResults.filter(g => g.groupType === 'file').length}文件`} + `${t('insights.stats.file', { count: insightGroupedResults.filter(g => g.groupType === 'file').length })}`} ) )}
{currentScope && (
- 范围: {currentScope} + {t('insights.stats.scopeLabel')} {currentScope}
)}
@@ -545,7 +545,7 @@ const InsightView = () => { {/* 加载进度 */} {isLoading && (
- 正在加载洞察... + {t('insights.loading')}
)} @@ -553,8 +553,8 @@ const InsightView = () => { {isInitializing && (
-

正在初始化工作区洞察...

-

这可能需要几分钟时间,请耐心等待

+

{t('insights.initializingWorkspace')}

+

{t('insights.initializingDescription')}

{initProgress && (
@@ -573,7 +573,7 @@ const InsightView = () => { >
- 正在处理: {initProgress.currentItem} + {t('insights.progress.current', { item: initProgress.currentItem })}
)} @@ -585,17 +585,17 @@ const InsightView = () => {
-

确认删除

+

{t('insights.deleteConfirm.title')}

- 您确定要删除当前工作区的所有洞察吗? + {t('insights.deleteConfirm.message')}

- ⚠️ 这个操作不可撤销,将删除所有生成的转换和洞察数据。 + {t('insights.deleteConfirm.warning')}

- 影响范围: {currentScope} + {t('insights.deleteConfirm.scopeLabel')} {currentScope}
@@ -603,13 +603,13 @@ const InsightView = () => { onClick={cancelDeleteConfirm} className="obsidian-confirm-dialog-cancel-btn" > - 取消 + {t('insights.deleteConfirm.cancel')}
@@ -685,9 +685,9 @@ const InsightView = () => { deleteSingleInsight(insight.id) }} disabled={deletingInsightId === insight.id} - title="删除此洞察" + title={t('insights.tooltips.clear')} > - {deletingInsightId === insight.id ? '删除中...' : '🗑️'} + {deletingInsightId === insight.id ? t('insights.deleting') : '🗑️'}
@@ -707,9 +707,9 @@ const InsightView = () => { {!isLoading && hasLoaded && insightGroupedResults.length === 0 && (
-

当前范围内没有找到洞察数据

+

{t('insights.noResults.title')}

- 请尝试在文档上运行转换工具来生成 AI 洞察 + {t('insights.noResults.hint')}

)} diff --git a/src/lang/locale/en.ts b/src/lang/locale/en.ts index 3c5eec1..e0a8354 100644 --- a/src/lang/locale/en.ts +++ b/src/lang/locale/en.ts @@ -494,10 +494,77 @@ export default { toolNoDescription: "No description", useMcpToolFrom: "Use MCP tool from", }, + insights: { + title: "AI Insights", + initializeInsights: "Initialize Insights", + clearInsights: "Clear Insights", + refresh: "Refresh", + initializing: "Initializing...", + deleting: "Deleting...", + loading: "Loading...", + initializingWorkspace: "Initializing workspace insights...", + initializingDescription: "This may take a few minutes, please be patient", + stage: { + preparing: "Preparing to initialize workspace insights", + completing: "Completing initialization", + savingResults: "Saving results" + }, + deleteConfirm: { + title: "Confirm Delete", + message: "Are you sure you want to delete all insights for the current workspace?", + warning: "⚠️ This action cannot be undone and will delete all generated transformation and insight data.", + scopeLabel: "Affected scope:", + cancel: "Cancel", + confirm: "Confirm Delete" + }, + stats: { + itemsAndInsights: "{items} items, {insights} insights", + workspace: "{count} workspace", + folder: "{count} folder", + file: "{count} file", + scopeLabel: "Scope:" + }, + types: { + denseSummary: "📋 Dense Summary", + simpleSummary: "📄 Simple Summary", + keyInsights: "💡 Key Insights", + analyzePaper: "🔬 Paper Analysis", + tableOfContents: "📑 Table of Contents", + reflections: "🤔 Reflections" + }, + fileGroup: { + workspacePrefix: "🌐 Workspace:", + folderPrefix: "📁" + }, + noResults: { + title: "No insight data found in the current scope", + hint: "Please try running transformation tools on documents to generate AI insights" + }, + tooltips: { + initialize: "Initialize insights for the current workspace, will recursively process all files and generate summaries", + clear: "Delete all transformations and insights for the current workspace" + }, + success: { + workspaceInitialized: 'Workspace "{name}" insights initialization successful', + workspaceDeleted: 'Successfully deleted {count} transformations for workspace "{name}"', + insightDeleted: 'Insight ID {id} successfully deleted' + }, + error: { + initializationFailed: "Workspace insight initialization failed:", + deletionFailed: "Failed to delete workspace insights:", + singleDeletionFailed: "Failed to delete insight:", + fileNotFound: "File not found in vault:", + folderNotFound: "Folder does not exist:" + }, + progress: { + current: "Processing: {item}" + } + }, workspace: { title: "Workspace Management", shortTitle: "Workspace", description: "Manage and switch between different workspaces (note vaults)", + entireVault: "Entire Vault", createNew: "Create New Workspace", recentWorkspaces: "Recent Workspaces", loading: "Loading workspace list...", diff --git a/src/lang/locale/zh-cn.ts b/src/lang/locale/zh-cn.ts index 4c26617..c0fac27 100644 --- a/src/lang/locale/zh-cn.ts +++ b/src/lang/locale/zh-cn.ts @@ -496,10 +496,77 @@ export default { useMcpToolFrom: "使用来自以下的 MCP 工具:", } }, + insights: { + title: "AI 洞察", + initializeInsights: "初始化洞察", + clearInsights: "清除洞察", + refresh: "刷新", + initializing: "初始化中...", + deleting: "删除中...", + loading: "加载中...", + initializingWorkspace: "正在初始化工作区洞察...", + initializingDescription: "这可能需要几分钟时间,请耐心等待", + stage: { + preparing: "准备初始化工作区洞察", + completing: "正在完成初始化", + savingResults: "保存结果" + }, + deleteConfirm: { + title: "确认删除", + message: "您确定要删除当前工作区的所有洞察吗?", + warning: "⚠️ 这个操作不可撤销,将删除所有生成的转换和洞察数据。", + scopeLabel: "影响范围:", + cancel: "取消", + confirm: "确认删除" + }, + stats: { + itemsAndInsights: "{items} 个项目,{insights} 个洞察", + workspace: "{count}工作区", + folder: "{count}文件夹", + file: "{count}文件", + scopeLabel: "范围:" + }, + types: { + denseSummary: "📋 密集摘要", + simpleSummary: "📄 简单摘要", + keyInsights: "💡 关键洞察", + analyzePaper: "🔬 论文分析", + tableOfContents: "📑 目录大纲", + reflections: "🤔 思考反思" + }, + fileGroup: { + workspacePrefix: "🌐 工作区:", + folderPrefix: "📁" + }, + noResults: { + title: "当前范围内没有找到洞察数据", + hint: "请尝试在文档上运行转换工具来生成 AI 洞察" + }, + tooltips: { + initialize: "初始化当前工作区的洞察,会递归处理所有文件并生成摘要", + clear: "删除当前工作区的所有转换和洞察" + }, + success: { + workspaceInitialized: '工作区 "{name}" 洞察初始化成功', + workspaceDeleted: '工作区 "{name}" 的 {count} 个转换已成功删除', + insightDeleted: '洞察 ID {id} 已成功删除' + }, + error: { + initializationFailed: "工作区洞察初始化失败:", + deletionFailed: "删除工作区洞察失败:", + singleDeletionFailed: "删除洞察失败:", + fileNotFound: "在vault中找不到文件:", + folderNotFound: "文件夹不存在:" + }, + progress: { + current: "正在处理: {item}" + } + }, workspace: { title: "工作区管理", shortTitle: "工作区", description: "管理和切换不同的工作区(笔记库)", + entireVault: "整个 Vault", createNew: "创建新工作区", recentWorkspaces: "最近的工作区", loading: "正在加载工作区列表...",