Files
ragflow/web/src/pages/agent/form/components/query-variable.tsx
balibabu d469ae6d50 Feat: The agent operator and message operator can only select string variables as prompt words. #10427 (#11054)
### What problem does this PR solve?

Feat: The agent operator and message operator can only select string
variables as prompt words. #10427
### Type of change


- [x] New Feature (non-breaking change which adds functionality)
2025-11-06 13:58:20 +08:00

60 lines
1.5 KiB
TypeScript

import {
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
} from '@/components/ui/form';
import { ReactNode } from 'react';
import { useFormContext } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { JsonSchemaDataType } from '../../constant';
import { useFilterQueryVariableOptionsByTypes } from '../../hooks/use-get-begin-query';
import { GroupedSelectWithSecondaryMenu } from './select-with-secondary-menu';
type QueryVariableProps = {
name?: string;
types?: JsonSchemaDataType[];
label?: ReactNode;
hideLabel?: boolean;
className?: string;
};
export function QueryVariable({
name = 'query',
types = [],
label,
hideLabel = false,
className,
}: QueryVariableProps) {
const { t } = useTranslation();
const form = useFormContext();
const finalOptions = useFilterQueryVariableOptionsByTypes(types);
return (
<FormField
control={form.control}
name={name}
render={({ field }) => (
<FormItem className={className}>
{hideLabel || label || (
<FormLabel tooltip={t('flow.queryTip')}>
{t('flow.query')}
</FormLabel>
)}
<FormControl>
<GroupedSelectWithSecondaryMenu
options={finalOptions}
{...field}
// allowClear
types={types}
></GroupedSelectWithSecondaryMenu>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
);
}