mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Fix:Resolves the issue of sessions not being saved when the variable is array<object>. (#11446)
### What problem does this PR solve? Fix:Resolves the issue of sessions not being saved when the variable is array<object>. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -356,6 +356,13 @@ const DynamicForm = {
|
|||||||
...combinedErrors,
|
...combinedErrors,
|
||||||
...fieldErrors,
|
...fieldErrors,
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
|
console.log('combinedErrors', combinedErrors);
|
||||||
|
for (const key in combinedErrors) {
|
||||||
|
if (Array.isArray(combinedErrors[key])) {
|
||||||
|
combinedErrors[key] = combinedErrors[key][0];
|
||||||
|
}
|
||||||
|
}
|
||||||
console.log('combinedErrors', combinedErrors);
|
console.log('combinedErrors', combinedErrors);
|
||||||
return {
|
return {
|
||||||
values: Object.keys(combinedErrors).length ? {} : data,
|
values: Object.keys(combinedErrors).length ? {} : data,
|
||||||
@ -720,9 +727,7 @@ const DynamicForm = {
|
|||||||
type="button"
|
type="button"
|
||||||
disabled={submitLoading}
|
disabled={submitLoading}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
console.log('form submit');
|
|
||||||
(async () => {
|
(async () => {
|
||||||
console.log('form submit2');
|
|
||||||
try {
|
try {
|
||||||
let beValid = await form.formControl.trigger();
|
let beValid = await form.formControl.trigger();
|
||||||
console.log('form valid', beValid, form, form.formControl);
|
console.log('form valid', beValid, form, form.formControl);
|
||||||
|
|||||||
@ -1046,7 +1046,7 @@ Example: https://fsn1.your-objectstorage.com`,
|
|||||||
downloadFileType: 'Download file type',
|
downloadFileType: 'Download file type',
|
||||||
formatTypeError: 'Format or type error',
|
formatTypeError: 'Format or type error',
|
||||||
variableNameMessage:
|
variableNameMessage:
|
||||||
'Variable name can only contain letters and underscores',
|
'Variable name can only contain letters and underscores and numbers',
|
||||||
variableDescription: 'Variable Description',
|
variableDescription: 'Variable Description',
|
||||||
defaultValue: 'Default Value',
|
defaultValue: 'Default Value',
|
||||||
conversationVariable: 'Conversation variable',
|
conversationVariable: 'Conversation variable',
|
||||||
|
|||||||
@ -980,7 +980,7 @@ General:实体和关系提取提示来自 GitHub - microsoft/graphrag:基于
|
|||||||
downloadFileTypeTip: '文件下载的类型',
|
downloadFileTypeTip: '文件下载的类型',
|
||||||
downloadFileType: '文件类型',
|
downloadFileType: '文件类型',
|
||||||
formatTypeError: '格式或类型错误',
|
formatTypeError: '格式或类型错误',
|
||||||
variableNameMessage: '名称只能包含字母和下划线',
|
variableNameMessage: '名称只能包含字母,数字和下划线',
|
||||||
variableDescription: '变量的描述',
|
variableDescription: '变量的描述',
|
||||||
defaultValue: '默认值',
|
defaultValue: '默认值',
|
||||||
conversationVariable: '会话变量',
|
conversationVariable: '会话变量',
|
||||||
|
|||||||
@ -18,7 +18,7 @@ export const GlobalFormFields = [
|
|||||||
placeholder: t('common.namePlaceholder'),
|
placeholder: t('common.namePlaceholder'),
|
||||||
required: true,
|
required: true,
|
||||||
validation: {
|
validation: {
|
||||||
pattern: /^[a-zA-Z_]+$/,
|
pattern: /^[a-zA-Z_0-9]+$/,
|
||||||
message: t('flow.variableNameMessage'),
|
message: t('flow.variableNameMessage'),
|
||||||
},
|
},
|
||||||
type: FormFieldType.Text,
|
type: FormFieldType.Text,
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { BlockButton, Button } from '@/components/ui/button';
|
|||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Segmented } from '@/components/ui/segmented';
|
import { Segmented } from '@/components/ui/segmented';
|
||||||
import { t } from 'i18next';
|
import { t } from 'i18next';
|
||||||
|
import { isEmpty } from 'lodash';
|
||||||
import { Trash2, X } from 'lucide-react';
|
import { Trash2, X } from 'lucide-react';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { FieldValues } from 'react-hook-form';
|
import { FieldValues } from 'react-hook-form';
|
||||||
@ -36,14 +37,19 @@ export const useObjectFields = () => {
|
|||||||
path: (string | number)[] = [],
|
path: (string | number)[] = [],
|
||||||
): Array<{ path: (string | number)[]; message: string }> => {
|
): Array<{ path: (string | number)[]; message: string }> => {
|
||||||
const errors: Array<{ path: (string | number)[]; message: string }> = [];
|
const errors: Array<{ path: (string | number)[]; message: string }> = [];
|
||||||
|
if (typeof obj === 'object' && !Array.isArray(obj)) {
|
||||||
if (obj !== null && typeof obj === 'object' && !Array.isArray(obj)) {
|
if (isEmpty(obj)) {
|
||||||
|
errors.push({
|
||||||
|
path: [...path],
|
||||||
|
message: 'No empty parameters are allowed.',
|
||||||
|
});
|
||||||
|
}
|
||||||
for (const key in obj) {
|
for (const key in obj) {
|
||||||
if (obj.hasOwnProperty(key)) {
|
if (obj.hasOwnProperty(key)) {
|
||||||
if (!/^[a-zA-Z_]+$/.test(key)) {
|
if (!/^[a-zA-Z_0-9]+$/.test(key)) {
|
||||||
errors.push({
|
errors.push({
|
||||||
path: [...path, key],
|
path: [...path, key],
|
||||||
message: `Key "${key}" is invalid. Keys can only contain letters and underscores.`,
|
message: `Key "${key}" is invalid. Keys can only contain letters and underscores and numbers.`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const nestedErrors = validateKeys(obj[key], [...path, key]);
|
const nestedErrors = validateKeys(obj[key], [...path, key]);
|
||||||
@ -108,6 +114,21 @@ export const useObjectFields = () => {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const arrayObjectValidate = useCallback((value: any) => {
|
||||||
|
try {
|
||||||
|
if (validateKeys(value, [])?.length > 0) {
|
||||||
|
throw new Error(t('flow.formatTypeError'));
|
||||||
|
}
|
||||||
|
if (value && typeof value === 'string' && !JSON.parse(value)) {
|
||||||
|
throw new Error(t('flow.formatTypeError'));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
console.log('object-render-error', e, value);
|
||||||
|
throw new Error(t('flow.formatTypeError'));
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
const arrayStringRender = useCallback((field: FieldValues, type = 'text') => {
|
const arrayStringRender = useCallback((field: FieldValues, type = 'text') => {
|
||||||
const values = Array.isArray(field.value)
|
const values = Array.isArray(field.value)
|
||||||
? field.value
|
? field.value
|
||||||
@ -253,8 +274,9 @@ export const useObjectFields = () => {
|
|||||||
const handleCustomValidate = (value: TypesWithArray) => {
|
const handleCustomValidate = (value: TypesWithArray) => {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case TypesWithArray.Object:
|
case TypesWithArray.Object:
|
||||||
case TypesWithArray.ArrayObject:
|
|
||||||
return objectValidate;
|
return objectValidate;
|
||||||
|
case TypesWithArray.ArrayObject:
|
||||||
|
return arrayObjectValidate;
|
||||||
case TypesWithArray.ArrayString:
|
case TypesWithArray.ArrayString:
|
||||||
return arrayStringValidate;
|
return arrayStringValidate;
|
||||||
case TypesWithArray.ArrayNumber:
|
case TypesWithArray.ArrayNumber:
|
||||||
@ -284,6 +306,7 @@ export const useObjectFields = () => {
|
|||||||
return {
|
return {
|
||||||
objectRender,
|
objectRender,
|
||||||
objectValidate,
|
objectValidate,
|
||||||
|
arrayObjectValidate,
|
||||||
arrayStringRender,
|
arrayStringRender,
|
||||||
arrayStringValidate,
|
arrayStringValidate,
|
||||||
arrayNumberRender,
|
arrayNumberRender,
|
||||||
|
|||||||
Reference in New Issue
Block a user