Feat: Setting parameters for array type
This commit is contained in:
parent
3fa97cf507
commit
60ca0959b4
2 changed files with 67 additions and 14 deletions
|
|
@ -866,7 +866,6 @@ export enum VariableAssignerLogicalNumberOperator {
|
||||||
export enum VariableAssignerLogicalArrayOperator {
|
export enum VariableAssignerLogicalArrayOperator {
|
||||||
Overwrite = VariableAssignerLogicalOperator.Overwrite,
|
Overwrite = VariableAssignerLogicalOperator.Overwrite,
|
||||||
Clear = VariableAssignerLogicalOperator.Clear,
|
Clear = VariableAssignerLogicalOperator.Clear,
|
||||||
Set = VariableAssignerLogicalOperator.Set,
|
|
||||||
Append = 'append',
|
Append = 'append',
|
||||||
Extend = 'extend',
|
Extend = 'extend',
|
||||||
RemoveFirst = 'remove_first',
|
RemoveFirst = 'remove_first',
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,25 @@
|
||||||
import NumberInput from '@/components/originui/number-input';
|
import NumberInput from '@/components/originui/number-input';
|
||||||
import { SelectWithSearch } from '@/components/originui/select-with-search';
|
import { SelectWithSearch } from '@/components/originui/select-with-search';
|
||||||
import { RAGFlowFormItem } from '@/components/ragflow-form';
|
import { RAGFlowFormItem } from '@/components/ragflow-form';
|
||||||
|
import { useIsDarkTheme } from '@/components/theme-provider';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group';
|
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group';
|
||||||
import { Separator } from '@/components/ui/separator';
|
import { Separator } from '@/components/ui/separator';
|
||||||
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
|
import { Editor } from '@monaco-editor/react';
|
||||||
import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
|
import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
|
||||||
import { X } from 'lucide-react';
|
import { X } from 'lucide-react';
|
||||||
import { ReactNode, useCallback } from 'react';
|
import { ReactNode, useCallback } from 'react';
|
||||||
import { useFieldArray, useFormContext } from 'react-hook-form';
|
import { useFieldArray, useFormContext } from 'react-hook-form';
|
||||||
import {
|
import {
|
||||||
JsonSchemaDataType,
|
JsonSchemaDataType,
|
||||||
|
VariableAssignerLogicalArrayOperator,
|
||||||
VariableAssignerLogicalNumberOperator,
|
VariableAssignerLogicalNumberOperator,
|
||||||
VariableAssignerLogicalOperator,
|
VariableAssignerLogicalOperator,
|
||||||
} from '../../constant';
|
} from '../../constant';
|
||||||
import { useGetVariableLabelOrTypeByValue } from '../../hooks/use-get-begin-query';
|
import { useGetVariableLabelOrTypeByValue } from '../../hooks/use-get-begin-query';
|
||||||
import { DynamicFormHeader } from '../components/dynamic-fom-header';
|
import { DynamicFormHeader } from '../components/dynamic-fom-header';
|
||||||
import { PromptEditor } from '../components/prompt-editor';
|
|
||||||
import { QueryVariable } from '../components/query-variable';
|
import { QueryVariable } from '../components/query-variable';
|
||||||
import { useBuildLogicalOptions } from './use-build-logical-options';
|
import { useBuildLogicalOptions } from './use-build-logical-options';
|
||||||
|
|
||||||
|
|
@ -57,6 +60,12 @@ function RadioButton({ value, onChange }: RadioButtonProps) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const EmptyFields = [
|
||||||
|
VariableAssignerLogicalOperator.Clear,
|
||||||
|
VariableAssignerLogicalArrayOperator.RemoveFirst,
|
||||||
|
VariableAssignerLogicalArrayOperator.RemoveLast,
|
||||||
|
];
|
||||||
|
|
||||||
export function DynamicVariables({
|
export function DynamicVariables({
|
||||||
name,
|
name,
|
||||||
label,
|
label,
|
||||||
|
|
@ -67,6 +76,7 @@ export function DynamicVariables({
|
||||||
}: SelectKeysProps) {
|
}: SelectKeysProps) {
|
||||||
const form = useFormContext();
|
const form = useFormContext();
|
||||||
const { getType } = useGetVariableLabelOrTypeByValue();
|
const { getType } = useGetVariableLabelOrTypeByValue();
|
||||||
|
const isDarkTheme = useIsDarkTheme();
|
||||||
|
|
||||||
const { fields, remove, append } = useFieldArray({
|
const { fields, remove, append } = useFieldArray({
|
||||||
name: name,
|
name: name,
|
||||||
|
|
@ -86,28 +96,55 @@ export function DynamicVariables({
|
||||||
const renderParameter = useCallback(
|
const renderParameter = useCallback(
|
||||||
(keyFieldName: string, operatorFieldName: string) => {
|
(keyFieldName: string, operatorFieldName: string) => {
|
||||||
const logicalOperator = form.getValues(operatorFieldName);
|
const logicalOperator = form.getValues(operatorFieldName);
|
||||||
|
const type = getVariableType(keyFieldName);
|
||||||
|
|
||||||
if (logicalOperator === VariableAssignerLogicalOperator.Clear) {
|
if (EmptyFields.includes(logicalOperator)) {
|
||||||
return null;
|
return null;
|
||||||
} else if (
|
} else if (
|
||||||
logicalOperator === VariableAssignerLogicalOperator.Overwrite
|
logicalOperator === VariableAssignerLogicalOperator.Overwrite ||
|
||||||
|
VariableAssignerLogicalArrayOperator.Extend === logicalOperator
|
||||||
) {
|
) {
|
||||||
return <PromptEditor showToolbar={false} multiLine={false} />;
|
return <QueryVariable types={[type]} hideLabel></QueryVariable>;
|
||||||
} else if (logicalOperator === VariableAssignerLogicalOperator.Set) {
|
} else if (logicalOperator === VariableAssignerLogicalOperator.Set) {
|
||||||
const type = getVariableType(keyFieldName);
|
|
||||||
|
|
||||||
if (type === JsonSchemaDataType.Boolean) {
|
if (type === JsonSchemaDataType.Boolean) {
|
||||||
return <RadioButton></RadioButton>;
|
return <RadioButton></RadioButton>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type === JsonSchemaDataType.Number) {
|
||||||
|
return <NumberInput className="w-full"></NumberInput>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === JsonSchemaDataType.Object) {
|
||||||
|
return (
|
||||||
|
<Editor
|
||||||
|
height={300}
|
||||||
|
theme={isDarkTheme ? 'vs-dark' : 'vs'}
|
||||||
|
language={'json'}
|
||||||
|
options={{
|
||||||
|
minimap: { enabled: false },
|
||||||
|
automaticLayout: true,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === JsonSchemaDataType.String) {
|
||||||
|
return <Textarea></Textarea>;
|
||||||
|
}
|
||||||
} else if (
|
} else if (
|
||||||
Object.values(VariableAssignerLogicalNumberOperator).some(
|
Object.values(VariableAssignerLogicalNumberOperator).some(
|
||||||
(x) => logicalOperator === x,
|
(x) => logicalOperator === x,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return <NumberInput className="w-full"></NumberInput>;
|
return <NumberInput className="w-full"></NumberInput>;
|
||||||
|
} else if (
|
||||||
|
logicalOperator === VariableAssignerLogicalArrayOperator.Append
|
||||||
|
) {
|
||||||
|
const subType = type.match(/<([^>]+)>/).at(1);
|
||||||
|
return <QueryVariable types={[subType]} hideLabel></QueryVariable>;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[form, getVariableType],
|
[form, getVariableType, isDarkTheme],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleVariableChange = useCallback(
|
const handleVariableChange = useCallback(
|
||||||
|
|
@ -115,12 +152,23 @@ export function DynamicVariables({
|
||||||
form.setValue(
|
form.setValue(
|
||||||
operatorFieldAlias,
|
operatorFieldAlias,
|
||||||
VariableAssignerLogicalOperator.Overwrite,
|
VariableAssignerLogicalOperator.Overwrite,
|
||||||
|
{ shouldDirty: true, shouldValidate: true },
|
||||||
);
|
);
|
||||||
form.setValue(valueFieldAlias, undefined);
|
form.setValue(valueFieldAlias, undefined);
|
||||||
},
|
},
|
||||||
[form],
|
[form],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleOperatorChange = useCallback(
|
||||||
|
(valueFieldAlias: string) => {
|
||||||
|
form.setValue(valueFieldAlias, undefined, {
|
||||||
|
shouldDirty: true,
|
||||||
|
shouldValidate: true,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[form],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="space-y-2">
|
<section className="space-y-2">
|
||||||
<DynamicFormHeader
|
<DynamicFormHeader
|
||||||
|
|
@ -152,12 +200,18 @@ export function DynamicVariables({
|
||||||
<Separator className="w-2" />
|
<Separator className="w-2" />
|
||||||
|
|
||||||
<RAGFlowFormItem name={operatorFieldAlias} className="w-1/3">
|
<RAGFlowFormItem name={operatorFieldAlias} className="w-1/3">
|
||||||
<SelectWithSearch
|
{({ onChange, value }) => (
|
||||||
{...field}
|
<SelectWithSearch
|
||||||
options={buildLogicalOptions(
|
value={value}
|
||||||
getVariableType(keyFieldAlias),
|
onChange={(val) => {
|
||||||
)}
|
handleOperatorChange(valueFieldAlias);
|
||||||
></SelectWithSearch>
|
onChange(val);
|
||||||
|
}}
|
||||||
|
options={buildLogicalOptions(
|
||||||
|
getVariableType(keyFieldAlias),
|
||||||
|
)}
|
||||||
|
></SelectWithSearch>
|
||||||
|
)}
|
||||||
</RAGFlowFormItem>
|
</RAGFlowFormItem>
|
||||||
</div>
|
</div>
|
||||||
<RAGFlowFormItem name={valueFieldAlias} className="w-full">
|
<RAGFlowFormItem name={valueFieldAlias} className="w-full">
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue