Add finally handler for rename tree node action (#1403)

* Add finally handler for rename tree node action

* nit
This commit is contained in:
Chenlei Hu
2024-11-02 11:39:15 -04:00
committed by GitHub
parent caa3ac2068
commit cc420b70a5
4 changed files with 21 additions and 13 deletions

View File

@@ -80,9 +80,11 @@ const errorHandling = useErrorHandling()
const handleRename = errorHandling.wrapWithErrorHandlingAsync(
async (newName: string) => {
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 canDrop = ref(false)

View File

@@ -177,12 +177,12 @@ const renderTreeNode = (node: TreeNode): TreeExplorerNode<ComfyWorkflow> => {
const actions = node.leaf
? {
handleClick,
handleRename: (
handleRename: async (
node: TreeExplorerNode<ComfyWorkflow>,
newName: string
) => {
const workflow = node.data
workflow.rename(newName)
await workflow.rename(newName)
},
handleDelete: workflow.isTemporary
? undefined

View File

@@ -39,7 +39,6 @@ import { useI18n } from 'vue-i18n'
import { useTreeExpansion } from '@/hooks/treeHooks'
import { app } from '@/scripts/app'
import { findNodeByKey } from '@/utils/treeUtil'
import { useErrorHandling } from '@/hooks/errorHooks'
const props = defineProps<{
filteredNodeDefs: ComfyNodeDefImpl[]
@@ -212,13 +211,11 @@ defineExpose({
addNewBookmarkFolder
})
const handleRename = useErrorHandling().wrapWithErrorHandling(
(node: TreeNode, newName: string) => {
if (node.data && node.data.isDummyFolder) {
nodeBookmarkStore.renameBookmarkFolder(node.data, newName)
}
const handleRename = (node: TreeNode, newName: string) => {
if (node.data && node.data.isDummyFolder) {
nodeBookmarkStore.renameBookmarkFolder(node.data, newName)
}
)
}
const showCustomizationDialog = ref(false)
const initialIcon = ref(nodeBookmarkStore.defaultBookmarkIcon)

View File

@@ -15,25 +15,34 @@ export function useErrorHandling() {
}
const wrapWithErrorHandling =
(action: (...args: any[]) => any, errorHandler?: (error: any) => void) =>
(
action: (...args: any[]) => any,
errorHandler?: (error: any) => void,
finallyHandler?: () => void
) =>
(...args: any[]) => {
try {
return action(...args)
} catch (e) {
;(errorHandler ?? toastErrorHandler)(e)
} finally {
finallyHandler?.()
}
}
const wrapWithErrorHandlingAsync =
(
action: ((...args: any[]) => Promise<any>) | ((...args: any[]) => any),
errorHandler?: (error: any) => void
errorHandler?: (error: any) => void,
finallyHandler?: () => void
) =>
async (...args: any[]) => {
try {
return await action(...args)
} catch (e) {
;(errorHandler ?? toastErrorHandler)(e)
} finally {
finallyHandler?.()
}
}