refactor: streamline workflow save functionality and improve toast messages
This commit is contained in:
@@ -147,30 +147,44 @@ export function WorkflowWorkbench({
|
|||||||
toast.error("请填写工作流名称")
|
toast.error("请填写工作流名称")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const savedName = name.trim()
|
||||||
|
const savedDescription = description.trim()
|
||||||
setSaving(true)
|
setSaving(true)
|
||||||
try {
|
try {
|
||||||
if (active) {
|
if (active) {
|
||||||
await updateAIWorkflow({
|
await updateAIWorkflow({
|
||||||
id: active.id,
|
id: active.id,
|
||||||
name: name.trim(),
|
name: savedName,
|
||||||
description: description.trim(),
|
description: savedDescription,
|
||||||
definition,
|
definition,
|
||||||
})
|
})
|
||||||
await load()
|
setActive((current) =>
|
||||||
|
current
|
||||||
|
? {
|
||||||
|
...current,
|
||||||
|
name: savedName,
|
||||||
|
description: savedDescription,
|
||||||
|
draftDefinition: definition,
|
||||||
|
updatedAt: new Date().toISOString(),
|
||||||
|
}
|
||||||
|
: current
|
||||||
|
)
|
||||||
|
setName(savedName)
|
||||||
|
setDescription(savedDescription)
|
||||||
|
setDirty(false)
|
||||||
} else {
|
} else {
|
||||||
const created = await createAIWorkflow({
|
const created = await createAIWorkflow({
|
||||||
name: name.trim(),
|
name: savedName,
|
||||||
description: description.trim(),
|
description: savedDescription,
|
||||||
definition,
|
definition,
|
||||||
})
|
})
|
||||||
setActive(created)
|
setActive(created)
|
||||||
setName(created.name)
|
setName(created.name)
|
||||||
setDescription(created.description)
|
setDescription(created.description)
|
||||||
setDefinition(created.draftDefinition)
|
|
||||||
setDirty(false)
|
setDirty(false)
|
||||||
}
|
}
|
||||||
onSaved?.()
|
onSaved?.()
|
||||||
toast.success("草稿已保存")
|
toast.success("保存成功")
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error(error instanceof Error ? error.message : "保存失败")
|
toast.error(error instanceof Error ? error.message : "保存失败")
|
||||||
} finally {
|
} finally {
|
||||||
@@ -180,7 +194,7 @@ export function WorkflowWorkbench({
|
|||||||
|
|
||||||
async function publish() {
|
async function publish() {
|
||||||
if (!active) {
|
if (!active) {
|
||||||
toast.error("请先保存草稿")
|
toast.error("请先保存")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
setSaving(true)
|
setSaving(true)
|
||||||
@@ -208,17 +222,8 @@ export function WorkflowWorkbench({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-full min-h-0 flex-col overflow-hidden bg-background">
|
<div className="flex h-full min-h-0 flex-col overflow-hidden bg-background">
|
||||||
<header className="shrink-0 border-b px-6 py-4">
|
<header className="shrink-0 border-b px-4 py-2">
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-4">
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
onClick={() =>
|
|
||||||
onClose ? onClose() : router.push("/dashboard/ai-workflows")
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<ArrowLeftIcon className="size-4" />
|
|
||||||
</Button>
|
|
||||||
<div className="min-w-0 flex-1">
|
<div className="min-w-0 flex-1">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<h1 className="truncate text-lg font-semibold">
|
<h1 className="truncate text-lg font-semibold">
|
||||||
@@ -238,7 +243,7 @@ export function WorkflowWorkbench({
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex shrink-0 gap-2">
|
<div className="flex shrink-0 gap-2">
|
||||||
<Button variant="ghost" onClick={openMetadata}>
|
<Button variant="outline" onClick={openMetadata}>
|
||||||
编辑信息
|
编辑信息
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
@@ -246,7 +251,7 @@ export function WorkflowWorkbench({
|
|||||||
disabled={saving}
|
disabled={saving}
|
||||||
onClick={() => void save()}
|
onClick={() => void save()}
|
||||||
>
|
>
|
||||||
保存草稿
|
保存
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
disabled={saving || !active}
|
disabled={saving || !active}
|
||||||
@@ -275,7 +280,7 @@ export function WorkflowWorkbench({
|
|||||||
>
|
>
|
||||||
{loaded ? (
|
{loaded ? (
|
||||||
<OfficialWorkflowEditor
|
<OfficialWorkflowEditor
|
||||||
documentKey={String(active?.id ?? (workflowID ? `loading-${workflowID}` : "new"))}
|
documentKey={workflowID ? `workflow-${workflowID}` : "new"}
|
||||||
definition={definition}
|
definition={definition}
|
||||||
onDefinitionChange={handleDefinitionChange}
|
onDefinitionChange={handleDefinitionChange}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user