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
This commit is contained in:
Archer
2024-11-13 18:29:24 +08:00
committed by GitHub
parent 98d4a6ee75
commit 0472dc2967
13 changed files with 68 additions and 79 deletions

View File

@@ -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 =

View File

@@ -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')
}

View File

@@ -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))

View File

@@ -76,8 +76,6 @@ export async function dispatchDatasetSearch(
nodeDispatchUsages: [],
[DispatchNodeResponseKeyEnum.toolResponses]: []
};
return Promise.reject(i18nT('common:core.chat.error.User input empty'));
}
// query extension

View File

@@ -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';
}

View File

@@ -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>
);

View File

@@ -14,7 +14,6 @@ type EditorVariablePickerType = {
};
export type Props = Omit<BoxProps, 'resize' | 'onChange'> & {
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 && (
<Box
position={'absolute'}
right={'-1'}
bottom={'-1'}
right={'-2.5'}
bottom={'-3.5'}
zIndex={10}
cursor={'ns-resize'}
px={'4px'}

View File

@@ -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}>

View File

@@ -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