-
Notifications
You must be signed in to change notification settings - Fork 7.8k
/
useExecutionDebugging.ts
143 lines (127 loc) · 4.2 KB
/
useExecutionDebugging.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { h, computed } from 'vue';
import { useRouter } from 'vue-router';
import { useI18n, useMessage, useToast } from '@/composables';
import {
DEBUG_PAYWALL_MODAL_KEY,
EnterpriseEditionFeature,
MODAL_CONFIRM,
VIEWS,
} from '@/constants';
import { useSettingsStore, useUIStore, useWorkflowsStore } from '@/stores';
import type { INodeUi } from '@/Interface';
export const useExecutionDebugging = () => {
const router = useRouter();
const i18n = useI18n();
const message = useMessage();
const toast = useToast();
const workflowsStore = useWorkflowsStore();
const settingsStore = useSettingsStore();
const uiStore = useUIStore();
const isDebugEnabled = computed(() =>
settingsStore.isEnterpriseFeatureEnabled(EnterpriseEditionFeature.DebugInEditor),
);
const applyExecutionData = async (executionId: string): Promise<void> => {
const execution = await workflowsStore.getExecution(executionId);
const workflow = workflowsStore.getCurrentWorkflow();
const workflowNodes = workflowsStore.getNodes();
if (!execution?.data?.resultData) {
return;
}
const { runData } = execution.data.resultData;
const executionNodeNames = Object.keys(runData);
const missingNodeNames = executionNodeNames.filter(
(name) => !workflowNodes.some((node) => node.name === name),
);
// Using the pinned data of the workflow to check if the node is pinned
// because workflowsStore.getCurrentWorkflow() returns a cached workflow without the updated pinned data
const workflowPinnedNodeNames = Object.keys(workflowsStore.workflow.pinData ?? {});
const matchingPinnedNodeNames = executionNodeNames.filter((name) =>
workflowPinnedNodeNames.includes(name),
);
if (matchingPinnedNodeNames.length > 0) {
const confirmMessage = h('p', [
i18n.baseText('nodeView.confirmMessage.debug.message'),
h(
'ul',
{ class: 'mt-l ml-l' },
matchingPinnedNodeNames.map((name) => h('li', name)),
),
]);
const overWritePinnedDataConfirm = await message.confirm(
confirmMessage,
i18n.baseText('nodeView.confirmMessage.debug.headline'),
{
type: 'warning',
confirmButtonText: i18n.baseText('nodeView.confirmMessage.debug.confirmButtonText'),
cancelButtonText: i18n.baseText('nodeView.confirmMessage.debug.cancelButtonText'),
dangerouslyUseHTMLString: true,
customClass: 'matching-pinned-nodes-confirmation',
},
);
if (overWritePinnedDataConfirm === MODAL_CONFIRM) {
matchingPinnedNodeNames.forEach((name) => {
const node = workflowsStore.getNodeByName(name);
if (node) {
workflowsStore.unpinData({ node });
}
});
} else {
await router.push({
name: VIEWS.EXECUTION_PREVIEW,
params: { name: workflow.id, executionId },
});
return;
}
}
// Set execution data
workflowsStore.setWorkflowExecutionData(execution);
// Pin data of all nodes which do not have a parent node
workflowNodes
.filter((node: INodeUi) => !workflow.getParentNodes(node.name).length)
.forEach((node: INodeUi) => {
const nodeData = runData[node.name]?.[0].data?.main[0];
if (nodeData) {
workflowsStore.pinData({
node,
data: nodeData,
});
}
});
toast.showToast({
title: i18n.baseText('nodeView.showMessage.debug.title'),
message: i18n.baseText('nodeView.showMessage.debug.content'),
type: 'info',
});
if (missingNodeNames.length) {
toast.showToast({
title: i18n.baseText('nodeView.showMessage.debug.missingNodes.title'),
message: i18n.baseText('nodeView.showMessage.debug.missingNodes.content', {
interpolate: { nodeNames: missingNodeNames.join(', ') },
}),
type: 'warning',
});
}
};
const handleDebugLinkClick = (event: Event): void => {
if (!isDebugEnabled.value) {
uiStore.openModalWithData({
name: DEBUG_PAYWALL_MODAL_KEY,
data: {
title: i18n.baseText(uiStore.contextBasedTranslationKeys.feature.unavailable.title),
footerButtonAction: () => {
uiStore.closeModal(DEBUG_PAYWALL_MODAL_KEY);
void uiStore.goToUpgrade('debug', 'upgrade-debug');
},
},
});
event.preventDefault();
event.stopPropagation();
return;
}
workflowsStore.isInDebugMode = false;
};
return {
applyExecutionData,
handleDebugLinkClick,
};
};