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
10 changes: 7 additions & 3 deletions packages/ui/src/ui-component/button/FlowListMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const StyledMenu = styled((props) => (
}
}))

export default function FlowListMenu({ chatflow, isAgentCanvas, isAgentflowV2, setError, updateFlowsApi }) {
export default function FlowListMenu({ chatflow, isAgentCanvas, isAgentflowV2, setError, updateFlowsApi, onRefresh }) {
const { confirm } = useConfirm()
const dispatch = useDispatch()
const updateChatflowApi = useApi(chatflowsApi.updateChatflow)
Expand Down Expand Up @@ -241,7 +241,10 @@ export default function FlowListMenu({ chatflow, isAgentCanvas, isAgentflowV2, s
if (isConfirmed) {
try {
await chatflowsApi.deleteChatflow(chatflow.id)
if (isAgentCanvas && isAgentflowV2) {
// Use onRefresh callback if available (for agentflows with pagination), otherwise fallback to updateFlowsApi
if (onRefresh) {
onRefresh()
} else if (isAgentCanvas && isAgentflowV2) {
await updateFlowsApi.request('AGENTFLOW')
} else {
await updateFlowsApi.request(isAgentCanvas ? 'MULTIAGENT' : undefined)
Expand Down Expand Up @@ -454,5 +457,6 @@ FlowListMenu.propTypes = {
isAgentCanvas: PropTypes.bool,
isAgentflowV2: PropTypes.bool,
setError: PropTypes.func,
updateFlowsApi: PropTypes.object
updateFlowsApi: PropTypes.object,
onRefresh: PropTypes.func
}
3 changes: 3 additions & 0 deletions packages/ui/src/ui-component/table/FlowListTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const FlowListTable = ({
isLoading,
filterFunction,
updateFlowsApi,
onRefresh,
setError,
isAgentCanvas,
isAgentflowV2
Expand Down Expand Up @@ -331,6 +332,7 @@ export const FlowListTable = ({
chatflow={row}
setError={setError}
updateFlowsApi={updateFlowsApi}
onRefresh={onRefresh}
/>
</Stack>
</StyledTableCell>
Expand All @@ -353,6 +355,7 @@ FlowListTable.propTypes = {
isLoading: PropTypes.bool,
filterFunction: PropTypes.func,
updateFlowsApi: PropTypes.object,
onRefresh: PropTypes.func,
setError: PropTypes.func,
isAgentCanvas: PropTypes.bool,
isAgentflowV2: PropTypes.bool
Expand Down
29 changes: 21 additions & 8 deletions packages/ui/src/views/agentflows/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ const Agentflows = () => {
getAllAgentflows.request(nextView === 'v2' ? 'AGENTFLOW' : 'MULTIAGENT', params)
}

const refreshAgentflows = () => {
refresh(currentPage, pageLimit, agentflowVersion)
}

const handleChange = (event, nextView) => {
if (nextView === null) return
localStorage.setItem('flowDisplayStyle', nextView)
Expand Down Expand Up @@ -138,21 +142,27 @@ const Agentflows = () => {
setTotal(getAllAgentflows.data?.total)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The setTotal call here might not correctly reflect the total number of items when getAllAgentflows.data is a plain array. According to the root cause, the backend might return a plain array instead of an object with data and total properties. If getAllAgentflows.data is a plain array, getAllAgentflows.data?.total will be undefined, leading to an incorrect total count for pagination. You should adjust this line to use the length of flowsArray if getAllAgentflows.data is an array, or getAllAgentflows.data?.total otherwise.

Suggested change
setTotal(getAllAgentflows.data?.total)
setTotal(Array.isArray(getAllAgentflows.data) ? getAllAgentflows.data.length : getAllAgentflows.data?.total)

const images = {}
const icons = {}
for (let i = 0; i < agentflows.length; i += 1) {
const flowDataStr = agentflows[i].flowData

// Safety check: handle both array and object response formats
const flowsArray = Array.isArray(getAllAgentflows.data)
? getAllAgentflows.data
: (agentflows || [])

for (let i = 0; i < flowsArray.length; i += 1) {
const flowDataStr = flowsArray[i].flowData
const flowData = JSON.parse(flowDataStr)
const nodes = flowData.nodes || []
images[agentflows[i].id] = []
icons[agentflows[i].id] = []
images[flowsArray[i].id] = []
icons[flowsArray[i].id] = []
for (let j = 0; j < nodes.length; j += 1) {
if (nodes[j].data.name === 'stickyNote' || nodes[j].data.name === 'stickyNoteAgentflow') continue
const foundIcon = AGENTFLOW_ICONS.find((icon) => icon.name === nodes[j].data.name)
if (foundIcon) {
icons[agentflows[i].id].push(foundIcon)
icons[flowsArray[i].id].push(foundIcon)
} else {
const imageSrc = `${baseURL}/api/v1/node-icon/${nodes[j].data.name}`
if (!images[agentflows[i].id].some((img) => img.imageSrc === imageSrc)) {
images[agentflows[i].id].push({
if (!images[flowsArray[i].id].some((img) => img.imageSrc === imageSrc)) {
images[flowsArray[i].id].push({
imageSrc,
label: nodes[j].data.label
})
Expand All @@ -163,7 +173,9 @@ const Agentflows = () => {
setImages(images)
setIcons(icons)
} catch (e) {
console.error(e)
console.error('❌ Error processing agentflows data:', e)
console.error('Data that caused error:', getAllAgentflows.data)
console.error('Error stack:', e.stack)
Comment on lines +176 to +178
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Adding more detailed error logging, including the problematic data and the error stack, is a good practice. This significantly improves the debuggability of the application when unexpected data formats or errors occur during agentflow processing.

}
}
}, [getAllAgentflows.data])
Expand Down Expand Up @@ -324,6 +336,7 @@ const Agentflows = () => {
isLoading={isLoading}
filterFunction={filterFlows}
updateFlowsApi={getAllAgentflows}
onRefresh={refreshAgentflows}
setError={setError}
/>
)}
Expand Down