From 0472dc2967e3dd79b2c8d2f3a0c417a3d8715f9b Mon Sep 17 00:00:00 2001 From: Archer <545436317@qq.com> Date: Wed, 13 Nov 2024 18:29:24 +0800 Subject: [PATCH] perf: checkbox dom (#3149) * perf: checkbox dom * perf: null check * perf: simple mode variables * perf: get csv encoding code * fix: dataset filter * perf: code editor ui --- .../zh-cn/docs/development/upgrading/4813.md | 7 ++-- packages/global/common/file/constants.ts | 2 +- .../workflow/template/system/datasetSearch.ts | 4 +- .../service/core/dataset/search/controller.ts | 7 +++- .../core/workflow/dispatch/dataset/search.ts | 2 - packages/web/common/file/utils.ts | 35 ++++++++--------- .../common/MySelect/MultipleRowSelect.tsx | 8 +--- .../common/Textarea/CodeEditor/Editor.tsx | 7 ++-- .../common/Textarea/CodeEditor/index.tsx | 6 ++- packages/web/hooks/useI18n.ts | 22 ++++++----- .../core/app/DatasetParamsModal.tsx | 7 +--- .../MemberManager/AddMemberModal.tsx | 38 +++++++++---------- .../detail/components/SimpleApp/EditForm.tsx | 2 +- 13 files changed, 68 insertions(+), 79 deletions(-) diff --git a/docSite/content/zh-cn/docs/development/upgrading/4813.md b/docSite/content/zh-cn/docs/development/upgrading/4813.md index 9855eadc8d8..198e38abac8 100644 --- a/docSite/content/zh-cn/docs/development/upgrading/4813.md +++ b/docSite/content/zh-cn/docs/development/upgrading/4813.md @@ -39,6 +39,7 @@ weight: 811 14. 优化 - Markdown 组件自动空格,避免分割 url 中的中文。 15. 优化 - 工作流上下文拆分,性能优化。 16. 优化 - 语音播报,不支持 mediaSource 的浏览器可等待完全生成语音后输出。 -17. 修复 - Dockerfile pnpm install 支持代理。 -18. 修复 - BI 图表生成无法写入文件。同时优化其解析,支持数字类型数组。 -19. 修复 - 分享链接首次加载时,标题显示不正确。 +17. 优化 - 对话引导 csv 读取,自动识别编码。 +18. 修复 - Dockerfile pnpm install 支持代理。 +19. 修复 - BI 图表生成无法写入文件。同时优化其解析,支持数字类型数组。 +20. 修复 - 分享链接首次加载时,标题显示不正确。 diff --git a/packages/global/common/file/constants.ts b/packages/global/common/file/constants.ts index 4be4bab2211..aa8e842174b 100644 --- a/packages/global/common/file/constants.ts +++ b/packages/global/common/file/constants.ts @@ -16,7 +16,7 @@ export const bucketNameMap = { } }; -export const ReadFileBaseUrl = `${process.env.FE_DOMAIN || ''}${process.env.NEXT_PUBLIC_BASE_URL}/api/common/file/read`; +export const ReadFileBaseUrl = `${process.env.FE_DOMAIN || ''}${process.env.NEXT_PUBLIC_BASE_URL || ''}/api/common/file/read`; export const documentFileType = '.txt, .docx, .csv, .xlsx, .pdf, .md, .html, .pptx'; export const imageFileType = diff --git a/packages/global/core/workflow/template/system/datasetSearch.ts b/packages/global/core/workflow/template/system/datasetSearch.ts index 476d10287a1..69e15a67984 100644 --- a/packages/global/core/workflow/template/system/datasetSearch.ts +++ b/packages/global/core/workflow/template/system/datasetSearch.ts @@ -95,10 +95,10 @@ export const DatasetSearchModule: FlowNodeTemplateType = { }, { key: NodeInputKeyEnum.collectionFilterMatch, - renderTypeList: [FlowNodeInputTypeEnum.JSONEditor, FlowNodeInputTypeEnum.reference], + renderTypeList: [FlowNodeInputTypeEnum.textarea, FlowNodeInputTypeEnum.reference], label: i18nT('workflow:collection_metadata_filter'), - valueType: WorkflowIOValueTypeEnum.object, + valueType: WorkflowIOValueTypeEnum.string, isPro: true, description: i18nT('workflow:filter_description') } diff --git a/packages/service/core/dataset/search/controller.ts b/packages/service/core/dataset/search/controller.ts index c5368726cff..0667a2b1e7c 100644 --- a/packages/service/core/dataset/search/controller.ts +++ b/packages/service/core/dataset/search/controller.ts @@ -118,7 +118,10 @@ export async function searchDatasetData(props: SearchDatasetDataProps) { let createTimeCollectionIdList: string[] | undefined = undefined; try { - const jsonMatch = json5.parse(collectionFilterMatch); + const jsonMatch = + typeof collectionFilterMatch === 'object' + ? collectionFilterMatch + : json5.parse(collectionFilterMatch); // Tag let andTags = jsonMatch?.tags?.$and as (string | null)[] | undefined; @@ -347,7 +350,7 @@ export async function searchDatasetData(props: SearchDatasetDataProps) { teamId: new Types.ObjectId(teamId), datasetId: new Types.ObjectId(id), $text: { $search: jiebaSplit({ text: query }) }, - ...(filterCollectionIdList && filterCollectionIdList.length > 0 + ...(filterCollectionIdList ? { collectionId: { $in: filterCollectionIdList.map((id) => new Types.ObjectId(id)) diff --git a/packages/service/core/workflow/dispatch/dataset/search.ts b/packages/service/core/workflow/dispatch/dataset/search.ts index 2691a487bf9..213aa473ccc 100644 --- a/packages/service/core/workflow/dispatch/dataset/search.ts +++ b/packages/service/core/workflow/dispatch/dataset/search.ts @@ -76,8 +76,6 @@ export async function dispatchDatasetSearch( nodeDispatchUsages: [], [DispatchNodeResponseKeyEnum.toolResponses]: [] }; - - return Promise.reject(i18nT('common:core.chat.error.User input empty')); } // query extension diff --git a/packages/web/common/file/utils.ts b/packages/web/common/file/utils.ts index 9b8a1618f17..7fd10744530 100644 --- a/packages/web/common/file/utils.ts +++ b/packages/web/common/file/utils.ts @@ -81,26 +81,21 @@ export const readCsvRawText = async ({ file }: { file: File }) => { return csvArr; }; -interface EncodingDetectionResult { - encoding: string | null; -} - -function detectEncoding(buffer: ArrayBuffer): EncodingDetectionResult { - const encodings = ['utf-8', 'iso-8859-1', 'windows-1252']; - for (let encoding of encodings) { - try { - const decoder = new TextDecoder(encoding, { fatal: true }); - decoder.decode(buffer); - return { encoding }; // 如果解码成功,返回当前编码 - } catch (e) { - // continue to try next encoding - } - } - return { encoding: null }; // 如果没有编码匹配,返回null -} - async function detectFileEncoding(file: File): Promise { const buffer = await loadFile2Buffer({ file }); - const { encoding } = detectEncoding(buffer); - return encoding || 'unknown'; + const encoding = (() => { + const encodings = ['utf-8', 'iso-8859-1', 'windows-1252']; + for (let encoding of encodings) { + try { + const decoder = new TextDecoder(encoding, { fatal: true }); + decoder.decode(buffer); + return encoding; // 如果解码成功,返回当前编码 + } catch (e) { + // continue to try next encoding + } + } + return null; // 如果没有编码匹配,返回null + })(); + + return encoding || 'utf-8'; } diff --git a/packages/web/components/common/MySelect/MultipleRowSelect.tsx b/packages/web/components/common/MySelect/MultipleRowSelect.tsx index 6ab2710586b..c8d335b7794 100644 --- a/packages/web/components/common/MySelect/MultipleRowSelect.tsx +++ b/packages/web/components/common/MySelect/MultipleRowSelect.tsx @@ -245,13 +245,7 @@ export const MultipleRowArraySelect = ({ onClick={() => handleSelect(item)} {...(isSelected ? { color: 'primary.600' } : {})} > - {showCheckbox && ( - } - mr={1} - /> - )} + {showCheckbox && } {item.label} ); diff --git a/packages/web/components/common/Textarea/CodeEditor/Editor.tsx b/packages/web/components/common/Textarea/CodeEditor/Editor.tsx index 4177ef89780..bb96bdd3c7e 100644 --- a/packages/web/components/common/Textarea/CodeEditor/Editor.tsx +++ b/packages/web/components/common/Textarea/CodeEditor/Editor.tsx @@ -14,7 +14,6 @@ type EditorVariablePickerType = { }; export type Props = Omit & { - height?: number; resize?: boolean; defaultValue?: string; value?: string; @@ -111,7 +110,7 @@ const MyEditor = ({ borderWidth={'1px'} borderRadius={'md'} borderColor={'myGray.200'} - py={2} + py={1} height={height} position={'relative'} pl={2} @@ -132,8 +131,8 @@ const MyEditor = ({ {resize && ( { iconSrc="modal/edit" title={t('common:code_editor')} w={'full'} + h={'85vh'} + isCentered > - - + +