mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-27 13:46:39 +08:00
Fix: Add a no-data filter condition to MetaData (#12189)
### What problem does this PR solve? Fix: Add a no-data filter condition to MetaData ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -12,7 +12,7 @@ import {
|
||||
useState,
|
||||
} from 'react';
|
||||
import { FieldPath, useForm } from 'react-hook-form';
|
||||
import { ZodArray, ZodString, z } from 'zod';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
@ -71,34 +71,37 @@ function CheckboxFormMultiple({
|
||||
}, {});
|
||||
}, [resolvedFilters]);
|
||||
|
||||
// const FormSchema = useMemo(() => {
|
||||
// if (resolvedFilters.length === 0) {
|
||||
// return z.object({});
|
||||
// }
|
||||
|
||||
// return z.object(
|
||||
// resolvedFilters.reduce<
|
||||
// Record<
|
||||
// string,
|
||||
// ZodArray<ZodString, 'many'> | z.ZodObject<any> | z.ZodOptional<any>
|
||||
// >
|
||||
// >((pre, cur) => {
|
||||
// const hasNested = cur.list?.some(
|
||||
// (item) => item.list && item.list.length > 0,
|
||||
// );
|
||||
|
||||
// if (hasNested) {
|
||||
// pre[cur.field] = z
|
||||
// .record(z.string(), z.array(z.string().optional()).optional())
|
||||
// .optional();
|
||||
// } else {
|
||||
// pre[cur.field] = z.array(z.string().optional()).optional();
|
||||
// }
|
||||
|
||||
// return pre;
|
||||
// }, {}),
|
||||
// );
|
||||
// }, [resolvedFilters]);
|
||||
const FormSchema = useMemo(() => {
|
||||
if (resolvedFilters.length === 0) {
|
||||
return z.object({});
|
||||
}
|
||||
|
||||
return z.object(
|
||||
resolvedFilters.reduce<
|
||||
Record<
|
||||
string,
|
||||
ZodArray<ZodString, 'many'> | z.ZodObject<any> | z.ZodOptional<any>
|
||||
>
|
||||
>((pre, cur) => {
|
||||
const hasNested = cur.list?.some(
|
||||
(item) => item.list && item.list.length > 0,
|
||||
);
|
||||
|
||||
if (hasNested) {
|
||||
pre[cur.field] = z
|
||||
.record(z.string(), z.array(z.string().optional()).optional())
|
||||
.optional();
|
||||
} else {
|
||||
pre[cur.field] = z.array(z.string().optional()).optional();
|
||||
}
|
||||
|
||||
return pre;
|
||||
}, {}),
|
||||
);
|
||||
}, [resolvedFilters]);
|
||||
return z.object({});
|
||||
}, []);
|
||||
|
||||
const form = useForm<z.infer<typeof FormSchema>>({
|
||||
resolver: resolvedFilters.length > 0 ? zodResolver(FormSchema) : undefined,
|
||||
|
||||
Reference in New Issue
Block a user