mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-29 18:52:19 +00:00
Add finally handler for rename tree node action (#1403)
* Add finally handler for rename tree node action * nit
This commit is contained in:
@@ -80,9 +80,11 @@ const errorHandling = useErrorHandling()
|
|||||||
const handleRename = errorHandling.wrapWithErrorHandlingAsync(
|
const handleRename = errorHandling.wrapWithErrorHandlingAsync(
|
||||||
async (newName: string) => {
|
async (newName: string) => {
|
||||||
await props.node.handleRename(props.node, newName)
|
await props.node.handleRename(props.node, newName)
|
||||||
renameEditingNode.value = null
|
|
||||||
},
|
},
|
||||||
props.node.handleError
|
props.node.handleError,
|
||||||
|
() => {
|
||||||
|
renameEditingNode.value = null
|
||||||
|
}
|
||||||
)
|
)
|
||||||
const container = ref<HTMLElement | null>(null)
|
const container = ref<HTMLElement | null>(null)
|
||||||
const canDrop = ref(false)
|
const canDrop = ref(false)
|
||||||
|
|||||||
@@ -177,12 +177,12 @@ const renderTreeNode = (node: TreeNode): TreeExplorerNode<ComfyWorkflow> => {
|
|||||||
const actions = node.leaf
|
const actions = node.leaf
|
||||||
? {
|
? {
|
||||||
handleClick,
|
handleClick,
|
||||||
handleRename: (
|
handleRename: async (
|
||||||
node: TreeExplorerNode<ComfyWorkflow>,
|
node: TreeExplorerNode<ComfyWorkflow>,
|
||||||
newName: string
|
newName: string
|
||||||
) => {
|
) => {
|
||||||
const workflow = node.data
|
const workflow = node.data
|
||||||
workflow.rename(newName)
|
await workflow.rename(newName)
|
||||||
},
|
},
|
||||||
handleDelete: workflow.isTemporary
|
handleDelete: workflow.isTemporary
|
||||||
? undefined
|
? undefined
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ import { useI18n } from 'vue-i18n'
|
|||||||
import { useTreeExpansion } from '@/hooks/treeHooks'
|
import { useTreeExpansion } from '@/hooks/treeHooks'
|
||||||
import { app } from '@/scripts/app'
|
import { app } from '@/scripts/app'
|
||||||
import { findNodeByKey } from '@/utils/treeUtil'
|
import { findNodeByKey } from '@/utils/treeUtil'
|
||||||
import { useErrorHandling } from '@/hooks/errorHooks'
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
filteredNodeDefs: ComfyNodeDefImpl[]
|
filteredNodeDefs: ComfyNodeDefImpl[]
|
||||||
@@ -212,13 +211,11 @@ defineExpose({
|
|||||||
addNewBookmarkFolder
|
addNewBookmarkFolder
|
||||||
})
|
})
|
||||||
|
|
||||||
const handleRename = useErrorHandling().wrapWithErrorHandling(
|
const handleRename = (node: TreeNode, newName: string) => {
|
||||||
(node: TreeNode, newName: string) => {
|
if (node.data && node.data.isDummyFolder) {
|
||||||
if (node.data && node.data.isDummyFolder) {
|
nodeBookmarkStore.renameBookmarkFolder(node.data, newName)
|
||||||
nodeBookmarkStore.renameBookmarkFolder(node.data, newName)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
|
|
||||||
const showCustomizationDialog = ref(false)
|
const showCustomizationDialog = ref(false)
|
||||||
const initialIcon = ref(nodeBookmarkStore.defaultBookmarkIcon)
|
const initialIcon = ref(nodeBookmarkStore.defaultBookmarkIcon)
|
||||||
|
|||||||
@@ -15,25 +15,34 @@ export function useErrorHandling() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const wrapWithErrorHandling =
|
const wrapWithErrorHandling =
|
||||||
(action: (...args: any[]) => any, errorHandler?: (error: any) => void) =>
|
(
|
||||||
|
action: (...args: any[]) => any,
|
||||||
|
errorHandler?: (error: any) => void,
|
||||||
|
finallyHandler?: () => void
|
||||||
|
) =>
|
||||||
(...args: any[]) => {
|
(...args: any[]) => {
|
||||||
try {
|
try {
|
||||||
return action(...args)
|
return action(...args)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
;(errorHandler ?? toastErrorHandler)(e)
|
;(errorHandler ?? toastErrorHandler)(e)
|
||||||
|
} finally {
|
||||||
|
finallyHandler?.()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const wrapWithErrorHandlingAsync =
|
const wrapWithErrorHandlingAsync =
|
||||||
(
|
(
|
||||||
action: ((...args: any[]) => Promise<any>) | ((...args: any[]) => any),
|
action: ((...args: any[]) => Promise<any>) | ((...args: any[]) => any),
|
||||||
errorHandler?: (error: any) => void
|
errorHandler?: (error: any) => void,
|
||||||
|
finallyHandler?: () => void
|
||||||
) =>
|
) =>
|
||||||
async (...args: any[]) => {
|
async (...args: any[]) => {
|
||||||
try {
|
try {
|
||||||
return await action(...args)
|
return await action(...args)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
;(errorHandler ?? toastErrorHandler)(e)
|
;(errorHandler ?? toastErrorHandler)(e)
|
||||||
|
} finally {
|
||||||
|
finallyHandler?.()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user