|
|
|
@@ -1,5 +1,11 @@ |
|
|
|
import { |
|
|
|
Sheet, |
|
|
|
SheetContent, |
|
|
|
SheetHeader, |
|
|
|
SheetTitle, |
|
|
|
} from '@/components/ui/sheet'; |
|
|
|
import { IModalProps } from '@/interfaces/common'; |
|
|
|
import { Drawer } from 'antd'; |
|
|
|
import { cn } from '@/lib/utils'; |
|
|
|
import { useCallback } from 'react'; |
|
|
|
import { useTranslation } from 'react-i18next'; |
|
|
|
import { BeginId } from '../constant'; |
|
|
|
@@ -8,14 +14,13 @@ import { useGetBeginNodeDataQuery } from '../hooks/use-get-begin-query'; |
|
|
|
import { useSaveGraphBeforeOpeningDebugDrawer } from '../hooks/use-save-graph'; |
|
|
|
import { BeginQuery } from '../interface'; |
|
|
|
import useGraphStore from '../store'; |
|
|
|
import { getDrawerWidth } from '../utils'; |
|
|
|
|
|
|
|
const RunSheet = ({ |
|
|
|
hideModal, |
|
|
|
showModal: showChatModal, |
|
|
|
}: IModalProps<any>) => { |
|
|
|
const { t } = useTranslation(); |
|
|
|
const updateNodeForm = useGraphStore((state) => state.updateNodeForm); |
|
|
|
const { updateNodeForm, getNode } = useGraphStore((state) => state); |
|
|
|
|
|
|
|
const getBeginNodeDataQuery = useGetBeginNodeDataQuery(); |
|
|
|
const query: BeginQuery[] = getBeginNodeDataQuery(); |
|
|
|
@@ -25,12 +30,26 @@ const RunSheet = ({ |
|
|
|
); |
|
|
|
|
|
|
|
const handleRunAgent = useCallback( |
|
|
|
(nextValues: Record<string, any>) => { |
|
|
|
const currentNodes = updateNodeForm(BeginId, nextValues, ['query']); |
|
|
|
(nextValues: BeginQuery[]) => { |
|
|
|
const beginNode = getNode(BeginId); |
|
|
|
const inputs: Record<string, BeginQuery> = beginNode?.data.form.inputs; |
|
|
|
|
|
|
|
const nextInputs = Object.keys(inputs).reduce<Record<string, BeginQuery>>( |
|
|
|
(pre, key) => { |
|
|
|
const item = nextValues.find((x) => x.key === key); |
|
|
|
if (item) { |
|
|
|
pre[key] = { ...item }; |
|
|
|
} |
|
|
|
return pre; |
|
|
|
}, |
|
|
|
{}, |
|
|
|
); |
|
|
|
|
|
|
|
const currentNodes = updateNodeForm(BeginId, nextInputs, ['inputs']); |
|
|
|
handleRun(currentNodes); |
|
|
|
hideModal?.(); |
|
|
|
}, |
|
|
|
[handleRun, hideModal, updateNodeForm], |
|
|
|
[getNode, handleRun, hideModal, updateNodeForm], |
|
|
|
); |
|
|
|
|
|
|
|
const onOk = useCallback( |
|
|
|
@@ -41,21 +60,18 @@ const RunSheet = ({ |
|
|
|
); |
|
|
|
|
|
|
|
return ( |
|
|
|
<Drawer |
|
|
|
title={t('flow.testRun')} |
|
|
|
placement="right" |
|
|
|
onClose={hideModal} |
|
|
|
open |
|
|
|
getContainer={false} |
|
|
|
width={getDrawerWidth()} |
|
|
|
mask={false} |
|
|
|
> |
|
|
|
<DebugContent |
|
|
|
ok={onOk} |
|
|
|
parameters={query} |
|
|
|
loading={loading} |
|
|
|
></DebugContent> |
|
|
|
</Drawer> |
|
|
|
<Sheet onOpenChange={hideModal} open> |
|
|
|
<SheetContent className={cn('top-20 p-2')}> |
|
|
|
<SheetHeader> |
|
|
|
<SheetTitle>{t('flow.testRun')}</SheetTitle> |
|
|
|
<DebugContent |
|
|
|
ok={onOk} |
|
|
|
parameters={query} |
|
|
|
loading={loading} |
|
|
|
></DebugContent> |
|
|
|
</SheetHeader> |
|
|
|
</SheetContent> |
|
|
|
</Sheet> |
|
|
|
); |
|
|
|
}; |
|
|
|
|