Skip to content
Open
Changes from 1 commit
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
38 changes: 18 additions & 20 deletions packages/ui/src/views/canvas/CanvasHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,17 @@ const CanvasHeader = ({ chatflow, isAgentCanvas, isAgentflowV2, handleSaveFlow,
<Stack flexDirection='row' justifyContent='space-between' sx={{ width: '100%' }}>
<Stack flexDirection='row' sx={{ width: '100%', maxWidth: '50%' }}>
<Box>
<ButtonBase title='Back' sx={{ borderRadius: '50%' }}>
<ButtonBase
title='Back'
sx={{ borderRadius: '50%' }}
onClick={() => {
if (window.history.state && window.history.state.idx > 0) {
navigate(-1)
} else {
navigate('/', { replace: true })
}
}}
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

For improved readability and to keep the JSX cleaner, you could extract this logic into a named function within the CanvasHeader component.

For example, you could define:

const handleBackClick = () => {
    if (window.history.state && window.history.state.idx > 0) {
        navigate(-1);
    } else {
        navigate('/', { replace: true });
    }
};

And then use onClick={handleBackClick} in the ButtonBase component. This is especially helpful for logic that isn't a simple one-liner and improves maintainability.

Copy link
Copy Markdown
Author

@eren-karakus0 eren-karakus0 Feb 22, 2026

Choose a reason for hiding this comment

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

Extracted it into a named handleBackClick function, consistent with the existing handler pattern in the component (submitFlowName, onAPIDialogClick, etc). Fixed in 5c58b66.

>
<Avatar
variant='rounded'
sx={{
Expand All @@ -268,13 +278,6 @@ const CanvasHeader = ({ chatflow, isAgentCanvas, isAgentflowV2, handleSaveFlow,
}
}}
color='inherit'
onClick={() => {
if (window.history.state && window.history.state.idx > 0) {
navigate(-1)
} else {
navigate('/', { replace: true })
}
}}
>
<IconChevronLeft stroke={1.5} size='1.3rem' />
</Avatar>
Expand All @@ -297,7 +300,7 @@ const CanvasHeader = ({ chatflow, isAgentCanvas, isAgentflowV2, handleSaveFlow,
</Typography>
{chatflow?.id && (
<Available permission={savePermission}>
<ButtonBase title='Edit Name' sx={{ borderRadius: '50%' }}>
<ButtonBase title='Edit Name' sx={{ borderRadius: '50%' }} onClick={() => setEditingFlowName(true)}>
<Avatar
variant='rounded'
sx={{
Expand All @@ -313,7 +316,6 @@ const CanvasHeader = ({ chatflow, isAgentCanvas, isAgentflowV2, handleSaveFlow,
}
}}
color='inherit'
onClick={() => setEditingFlowName(true)}
>
<IconPencil stroke={1.5} size='1.3rem' />
</Avatar>
Expand Down Expand Up @@ -341,7 +343,7 @@ const CanvasHeader = ({ chatflow, isAgentCanvas, isAgentflowV2, handleSaveFlow,
}
}}
/>
<ButtonBase title='Save Name' sx={{ borderRadius: '50%' }}>
<ButtonBase title='Save Name' sx={{ borderRadius: '50%' }} onClick={submitFlowName}>
<Avatar
variant='rounded'
sx={{
Expand All @@ -357,12 +359,11 @@ const CanvasHeader = ({ chatflow, isAgentCanvas, isAgentflowV2, handleSaveFlow,
}
}}
color='inherit'
onClick={submitFlowName}
>
<IconCheck stroke={1.5} size='1.3rem' />
</Avatar>
</ButtonBase>
<ButtonBase title='Cancel' sx={{ borderRadius: '50%' }}>
<ButtonBase title='Cancel' sx={{ borderRadius: '50%' }} onClick={() => setEditingFlowName(false)}>
<Avatar
variant='rounded'
sx={{
Expand All @@ -378,7 +379,6 @@ const CanvasHeader = ({ chatflow, isAgentCanvas, isAgentflowV2, handleSaveFlow,
}
}}
color='inherit'
onClick={() => setEditingFlowName(false)}
>
<IconX stroke={1.5} size='1.3rem' />
</Avatar>
Expand All @@ -389,7 +389,7 @@ const CanvasHeader = ({ chatflow, isAgentCanvas, isAgentflowV2, handleSaveFlow,
</Stack>
<Box>
{chatflow?.id && (
<ButtonBase title='API Endpoint' sx={{ borderRadius: '50%', mr: 2 }}>
<ButtonBase title='API Endpoint' sx={{ borderRadius: '50%', mr: 2 }} onClick={onAPIDialogClick}>
<Avatar
variant='rounded'
sx={{
Expand All @@ -404,14 +404,13 @@ const CanvasHeader = ({ chatflow, isAgentCanvas, isAgentflowV2, handleSaveFlow,
}
}}
color='inherit'
onClick={onAPIDialogClick}
>
<IconCode stroke={1.5} size='1.3rem' />
</Avatar>
</ButtonBase>
)}
<Available permission={savePermission}>
<ButtonBase title={`Save ${title}`} sx={{ borderRadius: '50%', mr: 2 }}>
<ButtonBase title={`Save ${title}`} sx={{ borderRadius: '50%', mr: 2 }} onClick={onSaveChatflowClick}>
<Avatar
variant='rounded'
sx={{
Expand All @@ -426,13 +425,12 @@ const CanvasHeader = ({ chatflow, isAgentCanvas, isAgentflowV2, handleSaveFlow,
}
}}
color='inherit'
onClick={onSaveChatflowClick}
>
<IconDeviceFloppy stroke={1.5} size='1.3rem' />
</Avatar>
</ButtonBase>
</Available>
<ButtonBase ref={settingsRef} title='Settings' sx={{ borderRadius: '50%' }}>
<ButtonBase ref={settingsRef} title='Settings' sx={{ borderRadius: '50%' }} onClick={() => setSettingsOpen(!isSettingsOpen)}>
<Avatar
variant='rounded'
sx={{
Expand All @@ -446,7 +444,7 @@ const CanvasHeader = ({ chatflow, isAgentCanvas, isAgentflowV2, handleSaveFlow,
color: theme.palette.canvasHeader.settingsLight
}
}}
onClick={() => setSettingsOpen(!isSettingsOpen)}
color='inherit'
>
<IconSettings stroke={1.5} size='1.3rem' />
</Avatar>
Expand Down