fix(web): workflow bug
This commit is contained in:
@@ -54,7 +54,7 @@ const Chat = forwardRef<ChatRef, { appId: string; graphRef: GraphRef }>(({ appId
|
|||||||
setChatList([])
|
setChatList([])
|
||||||
}
|
}
|
||||||
const handleEditVariables = () => {
|
const handleEditVariables = () => {
|
||||||
variableConfigModalRef.current?.handleOpen()
|
variableConfigModalRef.current?.handleOpen(variables)
|
||||||
}
|
}
|
||||||
const handleSave = (values: StartVariableItem[]) => {
|
const handleSave = (values: StartVariableItem[]) => {
|
||||||
setVariables([...values])
|
setVariables([...values])
|
||||||
@@ -91,7 +91,7 @@ const Chat = forwardRef<ChatRef, { appId: string; graphRef: GraphRef }>(({ appId
|
|||||||
}])
|
}])
|
||||||
setChatList(prev => [...prev, {
|
setChatList(prev => [...prev, {
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
content: message,
|
content: '',
|
||||||
created_at: Date.now(),
|
created_at: Date.now(),
|
||||||
}])
|
}])
|
||||||
|
|
||||||
|
|||||||
@@ -12,12 +12,12 @@ interface VariableEditModalProps {
|
|||||||
|
|
||||||
const VariableConfigModal = forwardRef<VariableEditModalRef, VariableEditModalProps>(({
|
const VariableConfigModal = forwardRef<VariableEditModalRef, VariableEditModalProps>(({
|
||||||
refresh,
|
refresh,
|
||||||
variables
|
|
||||||
}, ref) => {
|
}, ref) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const [form] = Form.useForm<{variables: StartVariableItem[]}>();
|
const [form] = Form.useForm<{variables: StartVariableItem[]}>();
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [initialValues, setInitialValues] = useState<StartVariableItem[]>([])
|
||||||
|
|
||||||
// 封装取消方法,添加关闭弹窗逻辑
|
// 封装取消方法,添加关闭弹窗逻辑
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
@@ -26,9 +26,10 @@ const VariableConfigModal = forwardRef<VariableEditModalRef, VariableEditModalPr
|
|||||||
setLoading(false)
|
setLoading(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOpen = () => {
|
const handleOpen = (values: StartVariableItem[]) => {
|
||||||
|
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
|
form.setFieldsValue({variables: values})
|
||||||
|
setInitialValues([...values])
|
||||||
};
|
};
|
||||||
// 封装保存方法,添加提交逻辑
|
// 封装保存方法,添加提交逻辑
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
@@ -59,18 +60,18 @@ const VariableConfigModal = forwardRef<VariableEditModalRef, VariableEditModalPr
|
|||||||
form={form}
|
form={form}
|
||||||
layout="horizontal"
|
layout="horizontal"
|
||||||
scrollToFirstError={{ behavior: 'instant', block: 'end', focus: true }}
|
scrollToFirstError={{ behavior: 'instant', block: 'end', focus: true }}
|
||||||
initialValues={{ variables: variables }}
|
|
||||||
>
|
>
|
||||||
<Form.List name="variables">
|
<Form.List name="variables">
|
||||||
{(fields) => (
|
{(fields) => (
|
||||||
<>
|
<>
|
||||||
{fields.map(({ name }, index) => {
|
{fields.map(({ name }, index) => {
|
||||||
const field = variables[index]
|
const field = initialValues[index]
|
||||||
return (
|
return (
|
||||||
<Form.Item
|
<Form.Item
|
||||||
key={name}
|
key={name}
|
||||||
name={[name, 'value']}
|
name={[name, 'value']}
|
||||||
label={field.type === 'boolean' ? undefined : `${field.name}·${field.description}`}
|
label={field.type === 'boolean' ? undefined : `${field.name}·${field.description}`}
|
||||||
|
valuePropName={field.type === 'boolean' ? 'checked' : 'value'}
|
||||||
rules={[
|
rules={[
|
||||||
{ required: field.required, message: field.type === 'boolean' ? t('common.pleaseSelect') : t('common.pleaseEnter') },
|
{ required: field.required, message: field.type === 'boolean' ? t('common.pleaseSelect') : t('common.pleaseEnter') },
|
||||||
]}
|
]}
|
||||||
|
|||||||
@@ -138,6 +138,15 @@ export const useWorkflowGraph = ({
|
|||||||
})
|
})
|
||||||
graphRef.current.addEdges(edgeList.filter(vo => vo !== null))
|
graphRef.current.addEdges(edgeList.filter(vo => vo !== null))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 初始化完成后,将节点展示在可视区域内
|
||||||
|
if (nodes.length > 0 || edges.length > 0) {
|
||||||
|
setTimeout(() => {
|
||||||
|
if (graphRef.current) {
|
||||||
|
graphRef.current.centerContent()
|
||||||
|
}
|
||||||
|
}, 200)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveState = () => {
|
const saveState = () => {
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ export interface WorkflowConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface VariableEditModalRef {
|
export interface VariableEditModalRef {
|
||||||
handleOpen: (values?: StartVariableItem) => void;
|
handleOpen: (values: StartVariableItem[]) => void;
|
||||||
}
|
}
|
||||||
export interface StartVariableItem {
|
export interface StartVariableItem {
|
||||||
name: string;
|
name: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user