Skip to content

Commit

Permalink
perf: checkbox dom (#3149)
Browse files Browse the repository at this point in the history
* perf: checkbox dom

* perf: null check

* perf: simple mode variables

* perf: get csv encoding code

* fix: dataset filter

* perf: code editor ui
  • Loading branch information
c121914yu authored Nov 13, 2024
1 parent 98d4a6e commit 0472dc2
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 79 deletions.
7 changes: 4 additions & 3 deletions docSite/content/zh-cn/docs/development/upgrading/4813.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. 修复 - 分享链接首次加载时,标题显示不正确。
2 changes: 1 addition & 1 deletion packages/global/common/file/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
7 changes: 5 additions & 2 deletions packages/service/core/dataset/search/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 0 additions & 2 deletions packages/service/core/workflow/dispatch/dataset/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ export async function dispatchDatasetSearch(
nodeDispatchUsages: [],
[DispatchNodeResponseKeyEnum.toolResponses]: []
};

return Promise.reject(i18nT('common:core.chat.error.User input empty'));
}

// query extension
Expand Down
35 changes: 15 additions & 20 deletions packages/web/common/file/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
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';
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,7 @@ export const MultipleRowArraySelect = ({
onClick={() => handleSelect(item)}
{...(isSelected ? { color: 'primary.600' } : {})}
>
{showCheckbox && (
<Checkbox
isChecked={isChecked}
icon={<MyIcon name={'common/check'} w={'12px'} />}
mr={1}
/>
)}
{showCheckbox && <Checkbox isChecked={isChecked} mr={1} />}
<Box>{item.label}</Box>
</Flex>
);
Expand Down
7 changes: 3 additions & 4 deletions packages/web/components/common/Textarea/CodeEditor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type EditorVariablePickerType = {
};

export type Props = Omit<BoxProps, 'resize' | 'onChange'> & {
height?: number;
resize?: boolean;
defaultValue?: string;
value?: string;
Expand Down Expand Up @@ -111,7 +110,7 @@ const MyEditor = ({
borderWidth={'1px'}
borderRadius={'md'}
borderColor={'myGray.200'}
py={2}
py={1}
height={height}
position={'relative'}
pl={2}
Expand All @@ -132,8 +131,8 @@ const MyEditor = ({
{resize && (
<Box
position={'absolute'}
right={'-1'}
bottom={'-1'}
right={'-2.5'}
bottom={'-3.5'}
zIndex={10}
cursor={'ns-resize'}
px={'4px'}
Expand Down
6 changes: 4 additions & 2 deletions packages/web/components/common/Textarea/CodeEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ const CodeEditor = (props: Props) => {
iconSrc="modal/edit"
title={t('common:code_editor')}
w={'full'}
h={'85vh'}
isCentered
>
<ModalBody>
<MyEditor {...props} bg={'myGray.50'} defaultHeight={600} />
<ModalBody flex={'1 0 0'} overflow={'auto'}>
<MyEditor {...props} bg={'myGray.50'} height={'100%'} />
</ModalBody>
<ModalFooter>
<Button mr={2} onClick={onClose} px={6}>
Expand Down
22 changes: 12 additions & 10 deletions packages/web/hooks/useI18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,27 @@ const LANG_KEY = 'NEXT_LOCALE';

export const useI18nLng = () => {
const { i18n } = useTranslation();
const languageMap: Record<string, string> = {
zh: 'zh',
'zh-CN': 'zh',
'zh-Hans': 'zh',
en: 'en',
'en-US': 'en'
};

const onChangeLng = (lng: string) => {
setCookie(LANG_KEY, lng, {
expires: 30,
sameSite: 'None',
secure: true
const lang = languageMap[lng] || 'en';

setCookie(LANG_KEY, lang, {
expires: 30
});
i18n?.changeLanguage(lng);
i18n?.changeLanguage(lang);
};

const setUserDefaultLng = () => {
if (!navigator || !localStorage) return;
if (getCookie(LANG_KEY)) return onChangeLng(getCookie(LANG_KEY) as string);

const languageMap: Record<string, string> = {
zh: 'zh',
'zh-CN': 'zh'
};

const lang = languageMap[navigator.language] || 'en';

// currentLng not in userLang
Expand Down
7 changes: 1 addition & 6 deletions projects/app/src/components/core/app/DatasetParamsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,7 @@ const DatasetParamsModal = ({
</Box>
</Box>
<Box position={'relative'} w={'18px'} h={'18px'}>
<Checkbox
colorScheme="primary"
isChecked={getValues('usingReRank')}
size="lg"
icon={<MyIcon name={'common/check'} w={'12px'} />}
/>
<Checkbox colorScheme="primary" isChecked={getValues('usingReRank')} size="lg" />
<Box position={'absolute'} top={0} right={0} bottom={0} left={0} zIndex={1}></Box>
</Box>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,12 @@ function AddMemberModal({ onClose, mode = 'member' }: AddModalPropsType) {
<Flex flexDirection="column" mt="2" overflow={'auto'} maxH="400px">
{filterGroups.map((group) => {
const onChange = () => {
if (selectedGroupIdList.includes(group._id)) {
setSelectedGroupIdList(selectedGroupIdList.filter((v) => v !== group._id));
} else {
setSelectedGroupIdList([...selectedGroupIdList, group._id]);
}
setSelectedGroupIdList((state) => {
if (state.includes(group._id)) {
return state.filter((v) => v !== group._id);
}
return [...state, group._id];
});
};
const collaborator = collaboratorList.find((v) => v.groupId === group._id);
return (
Expand All @@ -141,10 +142,7 @@ function AddMemberModal({ onClose, mode = 'member' }: AddModalPropsType) {
}}
onClick={onChange}
>
<Checkbox
isChecked={selectedGroupIdList.includes(group._id)}
icon={<MyIcon name={'common/check'} w={'12px'} />}
/>
<Checkbox isChecked={selectedGroupIdList.includes(group._id)} />
<MyAvatar src={group.avatar} w="1.5rem" borderRadius={'50%'} />
<Box ml="2" w="full">
{group.name === DefaultGroupName ? userInfo?.team.teamName : group.name}
Expand All @@ -157,11 +155,12 @@ function AddMemberModal({ onClose, mode = 'member' }: AddModalPropsType) {
})}
{filterMembers.map((member) => {
const onChange = () => {
if (selectedMemberIdList.includes(member.tmbId)) {
setSelectedMembers(selectedMemberIdList.filter((v) => v !== member.tmbId));
} else {
setSelectedMembers([...selectedMemberIdList, member.tmbId]);
}
setSelectedMembers((state) => {
if (state.includes(member.tmbId)) {
return state.filter((v) => v !== member.tmbId);
}
return [...state, member.tmbId];
});
};
const collaborator = collaboratorList.find((v) => v.tmbId === member.tmbId);
return (
Expand Down Expand Up @@ -205,11 +204,12 @@ function AddMemberModal({ onClose, mode = 'member' }: AddModalPropsType) {
<Flex flexDirection="column" mt="2" overflow={'auto'} maxH="400px">
{selectedGroupIdList.map((groupId) => {
const onChange = () => {
if (selectedGroupIdList.includes(groupId)) {
setSelectedGroupIdList(selectedGroupIdList.filter((v) => v !== groupId));
} else {
setSelectedGroupIdList([...selectedGroupIdList, groupId]);
}
setSelectedGroupIdList((state) => {
if (state.includes(groupId)) {
return state.filter((v) => v !== groupId);
}
return [...state, groupId];
});
};
const group = groups.find((v) => String(v._id) === groupId);
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const EditForm = ({
formatEditorVariablePickerIcon([
...workflowSystemVariables.filter(
(variable) =>
!['userId', 'appId', 'chatId', 'responseChatItemId', 'histories'].includes(variable.key)
!['appId', 'chatId', 'responseChatItemId', 'histories'].includes(variable.key)
),
...(appForm.chatConfig.variables || [])
]).map((item) => ({
Expand Down

0 comments on commit 0472dc2

Please sign in to comment.