Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/ui/src/views/agentflowsv2/Canvas.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ const AgentflowCanvas = () => {
}

const handleSaveFlow = (chatflowName) => {
if (createNewChatflowApi.loading) return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current guard only checks createNewChatflowApi.loading, which prevents duplicate requests when creating a new flow. However, if the user is updating an existing flow, updateChatflowApi is used instead. To prevent concurrent update requests, we should guard against both loading states.

Suggested change
if (createNewChatflowApi.loading) return
if (createNewChatflowApi.loading || updateChatflowApi.loading) return

if (reactFlowInstance) {
const nodes = reactFlowInstance.getNodes().map((node) => {
const nodeData = cloneDeep(node.data)
Expand Down Expand Up @@ -707,6 +708,7 @@ const AgentflowCanvas = () => {
<CanvasHeader
chatflow={chatflow}
handleSaveFlow={handleSaveFlow}
isSaving={createNewChatflowApi.loading}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Pass both createNewChatflowApi.loading and updateChatflowApi.loading to isSaving so that the save button is also disabled during update operations.

Suggested change
isSaving={createNewChatflowApi.loading}
isSaving={createNewChatflowApi.loading || updateChatflowApi.loading}

handleDeleteFlow={handleDeleteFlow}
handleLoadFlow={handleLoadFlow}
isAgentCanvas={true}
Expand Down
6 changes: 4 additions & 2 deletions packages/ui/src/views/canvas/CanvasHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const LockedScheduleSwitch = styled(ScheduleSwitch, { shouldForwardProp: (prop)

// ==============================|| CANVAS HEADER ||============================== //

const CanvasHeader = ({ chatflow, isAgentCanvas, isAgentflowV2, handleSaveFlow, handleDeleteFlow, handleLoadFlow }) => {
const CanvasHeader = ({ chatflow, isAgentCanvas, isAgentflowV2, handleSaveFlow, handleDeleteFlow, handleLoadFlow, isSaving }) => {
const theme = useTheme()
const dispatch = useDispatch()
const navigate = useNavigate()
Expand Down Expand Up @@ -319,11 +319,13 @@ const CanvasHeader = ({ chatflow, isAgentCanvas, isAgentflowV2, handleSaveFlow,
}

const onSaveChatflowClick = () => {
if (isSaving) return
if (chatflow.id) handleSaveFlow(flowName)
else setFlowDialogOpen(true)
}

const onConfirmSaveName = (flowName) => {
if (isSaving) return
setFlowDialogOpen(false)
setSavePermission(isAgentCanvas ? 'agentflows:update' : 'chatflows:update')
handleSaveFlow(flowName)
Expand Down Expand Up @@ -593,7 +595,7 @@ const CanvasHeader = ({ chatflow, isAgentCanvas, isAgentflowV2, handleSaveFlow,
</ButtonBase>
)}
<Available permission={savePermission}>
<ButtonBase title={`Save ${title}`} sx={{ borderRadius: '50%', mr: 2 }}>
<ButtonBase title={`Save ${title}`} disabled={isSaving} sx={{ borderRadius: '50%', mr: 2 }}>
<Avatar
variant='rounded'
sx={{
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/views/canvas/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ const Canvas = () => {
}

const handleSaveFlow = async (chatflowName) => {
if (createNewChatflowApi.loading) return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the agentflow canvas, the guard here should also prevent concurrent saves when updating an existing flow. Since the update flow in this canvas involves checking if the chatflow has changed first, we should guard against createNewChatflowApi.loading, updateChatflowApi.loading, and getHasChatflowChangedApi.loading.

Suggested change
if (createNewChatflowApi.loading) return
if (createNewChatflowApi.loading || updateChatflowApi.loading || getHasChatflowChangedApi.loading) return

if (reactFlowInstance) {
const nodes = reactFlowInstance.getNodes().map((node) => {
const nodeData = cloneDeep(node.data)
Expand Down Expand Up @@ -574,6 +575,7 @@ const Canvas = () => {
<CanvasHeader
chatflow={chatflow}
handleSaveFlow={handleSaveFlow}
isSaving={createNewChatflowApi.loading}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Pass all relevant loading states to isSaving to ensure the save button is disabled during both creation and update operations.

Suggested change
isSaving={createNewChatflowApi.loading}
isSaving={createNewChatflowApi.loading || updateChatflowApi.loading || getHasChatflowChangedApi.loading}

handleDeleteFlow={handleDeleteFlow}
handleLoadFlow={handleLoadFlow}
isAgentCanvas={isAgentCanvas}
Expand Down