mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-06-30 15:15:12 +08:00
### What problem does this PR solve? Feat: Synchronize BeginForm's query data to the canvas #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
parent
bdc2b74e8f
commit
9e80f39caa
@ -1,68 +1,61 @@
|
|||||||
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
'use client';
|
||||||
import { Button, Form, Input } from 'antd';
|
|
||||||
|
import { BlockButton, Button } from '@/components/ui/button';
|
||||||
|
import {
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormMessage,
|
||||||
|
} from '@/components/ui/form';
|
||||||
|
import { Input } from '@/components/ui/input';
|
||||||
|
import { X } from 'lucide-react';
|
||||||
|
import { useFieldArray, useFormContext } from 'react-hook-form';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
export function BeginDynamicOptions() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const form = useFormContext();
|
||||||
|
const name = 'options';
|
||||||
|
|
||||||
|
const { fields, remove, append } = useFieldArray({
|
||||||
|
name: name,
|
||||||
|
control: form.control,
|
||||||
|
});
|
||||||
|
|
||||||
const BeginDynamicOptions = () => {
|
|
||||||
return (
|
return (
|
||||||
<Form.List
|
<div className="space-y-5">
|
||||||
name="options"
|
{fields.map((field, index) => {
|
||||||
rules={[
|
const typeField = `${name}.${index}.value`;
|
||||||
{
|
return (
|
||||||
validator: async (_, names) => {
|
<div key={field.id} className="flex items-center gap-2">
|
||||||
if (!names || names.length < 1) {
|
<FormField
|
||||||
return Promise.reject(new Error('At least 1 option'));
|
control={form.control}
|
||||||
}
|
name={typeField}
|
||||||
},
|
render={({ field }) => (
|
||||||
},
|
<FormItem className="flex-1">
|
||||||
]}
|
<FormControl>
|
||||||
>
|
|
||||||
{(fields, { add, remove }, { errors }) => (
|
|
||||||
<>
|
|
||||||
{fields.map((field, index) => (
|
|
||||||
<Form.Item
|
|
||||||
label={index === 0 ? 'Options' : ''}
|
|
||||||
required={false}
|
|
||||||
key={field.key}
|
|
||||||
>
|
|
||||||
<Form.Item
|
|
||||||
{...field}
|
|
||||||
validateTrigger={['onChange', 'onBlur']}
|
|
||||||
rules={[
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
whitespace: true,
|
|
||||||
message: 'Please input option or delete this field.',
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
noStyle
|
|
||||||
>
|
|
||||||
<Input
|
<Input
|
||||||
placeholder="option"
|
{...field}
|
||||||
style={{ width: '90%', marginRight: 16 }}
|
placeholder={t('common.pleaseInput')}
|
||||||
/>
|
></Input>
|
||||||
</Form.Item>
|
</FormControl>
|
||||||
{fields.length > 1 ? (
|
<FormMessage />
|
||||||
<MinusCircleOutlined
|
</FormItem>
|
||||||
className="dynamic-delete-button"
|
|
||||||
onClick={() => remove(field.name)}
|
|
||||||
/>
|
|
||||||
) : null}
|
|
||||||
</Form.Item>
|
|
||||||
))}
|
|
||||||
<Form.Item>
|
|
||||||
<Button
|
|
||||||
type="dashed"
|
|
||||||
onClick={() => add()}
|
|
||||||
icon={<PlusOutlined />}
|
|
||||||
block
|
|
||||||
>
|
|
||||||
Add option
|
|
||||||
</Button>
|
|
||||||
<Form.ErrorList errors={errors} />
|
|
||||||
</Form.Item>
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</Form.List>
|
/>
|
||||||
|
<Button variant={'ghost'} onClick={() => remove(index)}>
|
||||||
|
<X className="text-text-sub-title-invert " />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
})}
|
||||||
|
<BlockButton
|
||||||
export default BeginDynamicOptions;
|
onClick={() => append({ value: '' })}
|
||||||
|
variant={'outline'}
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
{t('flow.addVariable')}
|
||||||
|
</BlockButton>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -15,16 +15,16 @@ import { useCallback } from 'react';
|
|||||||
import { useWatch } from 'react-hook-form';
|
import { useWatch } from 'react-hook-form';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { AgentDialogueMode } from '../../constant';
|
import { AgentDialogueMode } from '../../constant';
|
||||||
import { BeginQuery, INextOperatorForm } from '../../interface';
|
import { INextOperatorForm } from '../../interface';
|
||||||
import { useEditQueryRecord } from './hooks';
|
import { ParameterDialog } from './parameter-dialog';
|
||||||
import { ParameterDialog } from './paramater-dialog';
|
|
||||||
import QueryTable from './query-table';
|
import QueryTable from './query-table';
|
||||||
|
import { useEditQueryRecord } from './use-edit-query';
|
||||||
|
|
||||||
const ModeOptions = buildSelectOptions([
|
const ModeOptions = buildSelectOptions([
|
||||||
(AgentDialogueMode.Conversational, AgentDialogueMode.Task),
|
(AgentDialogueMode.Conversational, AgentDialogueMode.Task),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const BeginForm = ({ form }: INextOperatorForm) => {
|
const BeginForm = ({ form, node }: INextOperatorForm) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const query = useWatch({ control: form.control, name: 'query' });
|
const query = useWatch({ control: form.control, name: 'query' });
|
||||||
@ -40,22 +40,17 @@ const BeginForm = ({ form }: INextOperatorForm) => {
|
|||||||
hideModal,
|
hideModal,
|
||||||
showModal,
|
showModal,
|
||||||
otherThanCurrentQuery,
|
otherThanCurrentQuery,
|
||||||
|
handleDeleteRecord,
|
||||||
} = useEditQueryRecord({
|
} = useEditQueryRecord({
|
||||||
form,
|
form,
|
||||||
|
node,
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleDeleteRecord = useCallback(
|
const handleParameterDialogSubmit = useCallback(
|
||||||
(idx: number) => {
|
(values: any) => {
|
||||||
const query = form?.getValues('query') || [];
|
ok(values);
|
||||||
const nextQuery = query.filter(
|
|
||||||
(item: BeginQuery, index: number) => index !== idx,
|
|
||||||
);
|
|
||||||
// onValuesChange?.(
|
|
||||||
// { query: nextQuery },
|
|
||||||
// { query: nextQuery, prologue: form?.getFieldValue('prologue') },
|
|
||||||
// );
|
|
||||||
},
|
},
|
||||||
[form],
|
[ok],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -118,11 +113,11 @@ const BeginForm = ({ form }: INextOperatorForm) => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{/* Create a hidden field to make Form instance record this */}
|
{/* Create a hidden field to make Form instance record this */}
|
||||||
{/* <FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name={'query'}
|
name={'query'}
|
||||||
render={() => <div></div>}
|
render={() => <div></div>}
|
||||||
/> */}
|
/>
|
||||||
<QueryTable
|
<QueryTable
|
||||||
data={query}
|
data={query}
|
||||||
showModal={showModal}
|
showModal={showModal}
|
||||||
@ -138,6 +133,7 @@ const BeginForm = ({ form }: INextOperatorForm) => {
|
|||||||
initialValue={currentRecord}
|
initialValue={currentRecord}
|
||||||
onOk={ok}
|
onOk={ok}
|
||||||
otherThanCurrentQuery={otherThanCurrentQuery}
|
otherThanCurrentQuery={otherThanCurrentQuery}
|
||||||
|
submit={handleParameterDialogSubmit}
|
||||||
></ParameterDialog>
|
></ParameterDialog>
|
||||||
)}
|
)}
|
||||||
</Form>
|
</Form>
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import {
|
|
||||||
FormControl,
|
|
||||||
FormField,
|
|
||||||
FormItem,
|
|
||||||
FormMessage,
|
|
||||||
} from '@/components/ui/form';
|
|
||||||
import { Input } from '@/components/ui/input';
|
|
||||||
import { Plus, X } from 'lucide-react';
|
|
||||||
import { useFieldArray, useFormContext } from 'react-hook-form';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
|
|
||||||
export function BeginDynamicOptions() {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const form = useFormContext();
|
|
||||||
const name = 'options';
|
|
||||||
|
|
||||||
const { fields, remove, append } = useFieldArray({
|
|
||||||
name: name,
|
|
||||||
control: form.control,
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-5">
|
|
||||||
{fields.map((field, index) => {
|
|
||||||
const typeField = `${name}.${index}`;
|
|
||||||
return (
|
|
||||||
<div key={field.id} className="flex items-center gap-2">
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name={typeField}
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem className="w-2/5">
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
{...field}
|
|
||||||
placeholder={t('common.pleaseInput')}
|
|
||||||
></Input>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Button variant={'ghost'} onClick={() => remove(index)}>
|
|
||||||
<X className="text-text-sub-title-invert " />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
<Button
|
|
||||||
onClick={append}
|
|
||||||
className="mt-4 border-dashed w-full"
|
|
||||||
variant={'outline'}
|
|
||||||
>
|
|
||||||
<Plus />
|
|
||||||
{t('flow.addVariable')}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,124 +0,0 @@
|
|||||||
import { useResetFormOnCloseModal } from '@/hooks/logic-hooks';
|
|
||||||
import { IModalProps } from '@/interfaces/common';
|
|
||||||
import { Form, Input, Modal, Select, Switch } from 'antd';
|
|
||||||
import { DefaultOptionType } from 'antd/es/select';
|
|
||||||
import { useEffect, useMemo } from 'react';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
import { BeginQueryType, BeginQueryTypeIconMap } from '../../constant';
|
|
||||||
import { BeginQuery } from '../../interface';
|
|
||||||
import BeginDynamicOptions from './begin-dynamic-options';
|
|
||||||
|
|
||||||
export const ModalForm = ({
|
|
||||||
visible,
|
|
||||||
initialValue,
|
|
||||||
hideModal,
|
|
||||||
otherThanCurrentQuery,
|
|
||||||
}: IModalProps<BeginQuery> & {
|
|
||||||
initialValue: BeginQuery;
|
|
||||||
otherThanCurrentQuery: BeginQuery[];
|
|
||||||
}) => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const [form] = Form.useForm();
|
|
||||||
const options = useMemo(() => {
|
|
||||||
return Object.values(BeginQueryType).reduce<DefaultOptionType[]>(
|
|
||||||
(pre, cur) => {
|
|
||||||
const Icon = BeginQueryTypeIconMap[cur];
|
|
||||||
|
|
||||||
return [
|
|
||||||
...pre,
|
|
||||||
{
|
|
||||||
label: (
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Icon
|
|
||||||
className={`size-${cur === BeginQueryType.Options ? 4 : 5}`}
|
|
||||||
></Icon>
|
|
||||||
{cur}
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
value: cur,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
},
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useResetFormOnCloseModal({
|
|
||||||
form,
|
|
||||||
visible: visible,
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
form.setFieldsValue(initialValue);
|
|
||||||
}, [form, initialValue]);
|
|
||||||
|
|
||||||
const onOk = () => {
|
|
||||||
form.submit();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Modal
|
|
||||||
title={t('flow.variableSettings')}
|
|
||||||
open={visible}
|
|
||||||
onOk={onOk}
|
|
||||||
onCancel={hideModal}
|
|
||||||
centered
|
|
||||||
>
|
|
||||||
<Form form={form} layout="vertical" name="queryForm" autoComplete="false">
|
|
||||||
<Form.Item
|
|
||||||
name="type"
|
|
||||||
label="Type"
|
|
||||||
rules={[{ required: true }]}
|
|
||||||
initialValue={BeginQueryType.Line}
|
|
||||||
>
|
|
||||||
<Select options={options} />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
name="key"
|
|
||||||
label="Key"
|
|
||||||
rules={[
|
|
||||||
{ required: true },
|
|
||||||
() => ({
|
|
||||||
validator(_, value) {
|
|
||||||
if (
|
|
||||||
!value ||
|
|
||||||
!otherThanCurrentQuery.some((x) => x.key === value)
|
|
||||||
) {
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
return Promise.reject(new Error('The key cannot be repeated!'));
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item name="name" label="Name" rules={[{ required: true }]}>
|
|
||||||
<Input />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
name="optional"
|
|
||||||
label={'Optional'}
|
|
||||||
valuePropName="checked"
|
|
||||||
initialValue={false}
|
|
||||||
>
|
|
||||||
<Switch />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
shouldUpdate={(prevValues, curValues) =>
|
|
||||||
prevValues.type !== curValues.type
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{({ getFieldValue }) => {
|
|
||||||
const type: BeginQueryType = getFieldValue('type');
|
|
||||||
return (
|
|
||||||
type === BeginQueryType.Options && (
|
|
||||||
<BeginDynamicOptions></BeginDynamicOptions>
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
</Form.Item>
|
|
||||||
</Form>
|
|
||||||
</Modal>
|
|
||||||
);
|
|
||||||
};
|
|
@ -25,11 +25,12 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { BeginQueryType, BeginQueryTypeIconMap } from '../../constant';
|
import { BeginQueryType, BeginQueryTypeIconMap } from '../../constant';
|
||||||
import { BeginQuery } from '../../interface';
|
import { BeginQuery } from '../../interface';
|
||||||
import { BeginDynamicOptions } from './next-begin-dynamic-options';
|
import { BeginDynamicOptions } from './begin-dynamic-options';
|
||||||
|
|
||||||
type ModalFormProps = {
|
type ModalFormProps = {
|
||||||
initialValue: BeginQuery;
|
initialValue: BeginQuery;
|
||||||
otherThanCurrentQuery: BeginQuery[];
|
otherThanCurrentQuery: BeginQuery[];
|
||||||
|
submit(values: any): void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const FormId = 'BeginParameterForm';
|
const FormId = 'BeginParameterForm';
|
||||||
@ -37,6 +38,7 @@ const FormId = 'BeginParameterForm';
|
|||||||
function ParameterForm({
|
function ParameterForm({
|
||||||
initialValue,
|
initialValue,
|
||||||
otherThanCurrentQuery,
|
otherThanCurrentQuery,
|
||||||
|
submit,
|
||||||
}: ModalFormProps) {
|
}: ModalFormProps) {
|
||||||
const FormSchema = z.object({
|
const FormSchema = z.object({
|
||||||
type: z.string(),
|
type: z.string(),
|
||||||
@ -51,7 +53,9 @@ function ParameterForm({
|
|||||||
),
|
),
|
||||||
optional: z.boolean(),
|
optional: z.boolean(),
|
||||||
name: z.string().trim().min(1),
|
name: z.string().trim().min(1),
|
||||||
options: z.array(z.string().or(z.boolean()).or(z.number())).optional(),
|
options: z
|
||||||
|
.array(z.object({ value: z.string().or(z.boolean()).or(z.number()) }))
|
||||||
|
.optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const form = useForm<z.infer<typeof FormSchema>>({
|
const form = useForm<z.infer<typeof FormSchema>>({
|
||||||
@ -94,11 +98,17 @@ function ParameterForm({
|
|||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
form.reset(initialValue);
|
form.reset({
|
||||||
|
...initialValue,
|
||||||
|
options: initialValue.options?.map((x) => ({ value: x })),
|
||||||
|
});
|
||||||
}, [form, initialValue]);
|
}, [form, initialValue]);
|
||||||
|
|
||||||
function onSubmit(data: z.infer<typeof FormSchema>) {
|
function onSubmit(data: z.infer<typeof FormSchema>) {
|
||||||
console.log('🚀 ~ onSubmit ~ data:', data);
|
const values = { ...data, options: data.options?.map((x) => x.value) };
|
||||||
|
console.log('🚀 ~ onSubmit ~ values:', values);
|
||||||
|
|
||||||
|
submit(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -176,6 +186,7 @@ export function ParameterDialog({
|
|||||||
initialValue,
|
initialValue,
|
||||||
hideModal,
|
hideModal,
|
||||||
otherThanCurrentQuery,
|
otherThanCurrentQuery,
|
||||||
|
submit,
|
||||||
}: ModalFormProps & IModalProps<BeginQuery>) {
|
}: ModalFormProps & IModalProps<BeginQuery>) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
@ -188,6 +199,7 @@ export function ParameterDialog({
|
|||||||
<ParameterForm
|
<ParameterForm
|
||||||
initialValue={initialValue}
|
initialValue={initialValue}
|
||||||
otherThanCurrentQuery={otherThanCurrentQuery}
|
otherThanCurrentQuery={otherThanCurrentQuery}
|
||||||
|
submit={submit}
|
||||||
></ParameterForm>
|
></ParameterForm>
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<Button type="submit" form={FormId}>
|
<Button type="submit" form={FormId}>
|
@ -2,11 +2,30 @@ import { useSetModalState } from '@/hooks/common-hooks';
|
|||||||
import { useSetSelectedRecord } from '@/hooks/logic-hooks';
|
import { useSetSelectedRecord } from '@/hooks/logic-hooks';
|
||||||
import { useCallback, useMemo, useState } from 'react';
|
import { useCallback, useMemo, useState } from 'react';
|
||||||
import { BeginQuery, INextOperatorForm } from '../../interface';
|
import { BeginQuery, INextOperatorForm } from '../../interface';
|
||||||
|
import useGraphStore from '../../store';
|
||||||
|
|
||||||
export const useEditQueryRecord = ({ form }: INextOperatorForm) => {
|
export function useUpdateQueryToNodeForm({ form, node }: INextOperatorForm) {
|
||||||
|
const updateNodeForm = useGraphStore((state) => state.updateNodeForm);
|
||||||
|
|
||||||
|
const update = useCallback(
|
||||||
|
(query: BeginQuery[]) => {
|
||||||
|
const values = form.getValues();
|
||||||
|
const nextValues = { ...values, query };
|
||||||
|
if (node?.id) {
|
||||||
|
updateNodeForm(node.id, nextValues);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[form, node?.id, updateNodeForm],
|
||||||
|
);
|
||||||
|
|
||||||
|
return { update };
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useEditQueryRecord = ({ form, node }: INextOperatorForm) => {
|
||||||
const { setRecord, currentRecord } = useSetSelectedRecord<BeginQuery>();
|
const { setRecord, currentRecord } = useSetSelectedRecord<BeginQuery>();
|
||||||
const { visible, hideModal, showModal } = useSetModalState();
|
const { visible, hideModal, showModal } = useSetModalState();
|
||||||
const [index, setIndex] = useState(-1);
|
const [index, setIndex] = useState(-1);
|
||||||
|
const { update } = useUpdateQueryToNodeForm({ form, node });
|
||||||
|
|
||||||
const otherThanCurrentQuery = useMemo(() => {
|
const otherThanCurrentQuery = useMemo(() => {
|
||||||
const query: BeginQuery[] = form?.getValues('query') || [];
|
const query: BeginQuery[] = form?.getValues('query') || [];
|
||||||
@ -16,17 +35,21 @@ export const useEditQueryRecord = ({ form }: INextOperatorForm) => {
|
|||||||
const handleEditRecord = useCallback(
|
const handleEditRecord = useCallback(
|
||||||
(record: BeginQuery) => {
|
(record: BeginQuery) => {
|
||||||
const query: BeginQuery[] = form?.getValues('query') || [];
|
const query: BeginQuery[] = form?.getValues('query') || [];
|
||||||
|
console.log('🚀 ~ useEditQueryRecord ~ query:', query);
|
||||||
|
|
||||||
const nextQuery: BeginQuery[] =
|
const nextQuery: BeginQuery[] =
|
||||||
index > -1 ? query.toSpliced(index, 1, record) : [...query, record];
|
index > -1 ? query.toSpliced(index, 1, record) : [...query, record];
|
||||||
|
|
||||||
// onValuesChange?.(
|
form.setValue('query', nextQuery, {
|
||||||
// { query: nextQuery },
|
shouldDirty: true,
|
||||||
// { query: nextQuery, prologue: form?.getFieldValue('prologue') },
|
shouldTouch: true,
|
||||||
// );
|
});
|
||||||
|
|
||||||
|
update(nextQuery);
|
||||||
|
|
||||||
hideModal();
|
hideModal();
|
||||||
},
|
},
|
||||||
[form, hideModal, index],
|
[form, hideModal, index, update],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleShowModal = useCallback(
|
const handleShowModal = useCallback(
|
||||||
@ -38,6 +61,20 @@ export const useEditQueryRecord = ({ form }: INextOperatorForm) => {
|
|||||||
[setRecord, showModal],
|
[setRecord, showModal],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleDeleteRecord = useCallback(
|
||||||
|
(idx: number) => {
|
||||||
|
const query = form?.getValues('query') || [];
|
||||||
|
const nextQuery = query.filter(
|
||||||
|
(item: BeginQuery, index: number) => index !== idx,
|
||||||
|
);
|
||||||
|
|
||||||
|
form.setValue('query', nextQuery, { shouldDirty: true });
|
||||||
|
|
||||||
|
update(nextQuery);
|
||||||
|
},
|
||||||
|
[form, update],
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ok: handleEditRecord,
|
ok: handleEditRecord,
|
||||||
currentRecord,
|
currentRecord,
|
||||||
@ -46,5 +83,6 @@ export const useEditQueryRecord = ({ form }: INextOperatorForm) => {
|
|||||||
hideModal,
|
hideModal,
|
||||||
showModal: handleShowModal,
|
showModal: handleShowModal,
|
||||||
otherThanCurrentQuery,
|
otherThanCurrentQuery,
|
||||||
|
handleDeleteRecord,
|
||||||
};
|
};
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user