refactor(editor): Refactor workflowHelpers mixin to composable (no-changelog) (#8600)
This commit is contained in:
@@ -2,7 +2,7 @@ import { createPinia, setActivePinia } from 'pinia';
|
||||
import { useSettingsStore } from '@/stores/settings.store';
|
||||
import { useWorkflowsStore } from '@/stores/workflows.store';
|
||||
import { setupServer } from '@/__tests__/server';
|
||||
import { executeData } from '@/mixins/workflowHelpers';
|
||||
import { executeData } from '@/composables/useWorkflowHelpers';
|
||||
import type { IExecutionResponse } from '@/Interface';
|
||||
|
||||
describe('workflowHelpers', () => {
|
||||
|
||||
@@ -6,16 +6,15 @@ import type { IDataObject } from 'n8n-workflow';
|
||||
import { Expression, ExpressionExtensions } from 'n8n-workflow';
|
||||
import { ensureSyntaxTree } from '@codemirror/language';
|
||||
|
||||
import { workflowHelpers } from '@/mixins/workflowHelpers';
|
||||
import { useNDVStore } from '@/stores/ndv.store';
|
||||
import { EXPRESSION_EDITOR_PARSER_TIMEOUT } from '@/constants';
|
||||
|
||||
import type { EditorView } from '@codemirror/view';
|
||||
import type { TargetItem } from '@/Interface';
|
||||
import type { Html, Plaintext, RawSegment, Resolvable, Segment } from '@/types/expressions';
|
||||
import { useWorkflowHelpers } from '@/composables/useWorkflowHelpers';
|
||||
|
||||
export const expressionManager = defineComponent({
|
||||
mixins: [workflowHelpers],
|
||||
props: {
|
||||
targetItem: {
|
||||
type: Object as PropType<TargetItem | null>,
|
||||
@@ -197,6 +196,7 @@ export const expressionManager = defineComponent({
|
||||
|
||||
try {
|
||||
const ndvStore = useNDVStore();
|
||||
const workflowHelpers = useWorkflowHelpers(this.$router);
|
||||
if (!ndvStore.activeNode) {
|
||||
// e.g. credential modal
|
||||
result.resolved = Expression.resolveWithoutWorkflow(resolvable, this.additionalData);
|
||||
@@ -211,7 +211,7 @@ export const expressionManager = defineComponent({
|
||||
additionalKeys: this.additionalData,
|
||||
};
|
||||
}
|
||||
result.resolved = this.resolveExpression('=' + resolvable, undefined, opts);
|
||||
result.resolved = workflowHelpers.resolveExpression('=' + resolvable, undefined, opts);
|
||||
}
|
||||
} catch (error) {
|
||||
result.resolved = `[${error.message}]`;
|
||||
|
||||
@@ -8,7 +8,6 @@ import type {
|
||||
import { useNodeHelpers } from '@/composables/useNodeHelpers';
|
||||
import { useTitleChange } from '@/composables/useTitleChange';
|
||||
import { useToast } from '@/composables/useToast';
|
||||
import { workflowHelpers } from '@/mixins/workflowHelpers';
|
||||
|
||||
import type {
|
||||
ExpressionError,
|
||||
@@ -39,14 +38,19 @@ import { useOrchestrationStore } from '@/stores/orchestration.store';
|
||||
import { usePushConnectionStore } from '@/stores/pushConnection.store';
|
||||
import { useCollaborationStore } from '@/stores/collaboration.store';
|
||||
import { useExternalHooks } from '@/composables/useExternalHooks';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useWorkflowHelpers } from '@/composables/useWorkflowHelpers';
|
||||
|
||||
export const pushConnection = defineComponent({
|
||||
mixins: [workflowHelpers],
|
||||
setup() {
|
||||
const router = useRouter();
|
||||
const workflowHelpers = useWorkflowHelpers(router);
|
||||
const nodeHelpers = useNodeHelpers();
|
||||
return {
|
||||
...useTitleChange(),
|
||||
...useToast(),
|
||||
nodeHelpers: useNodeHelpers(),
|
||||
nodeHelpers,
|
||||
workflowHelpers,
|
||||
};
|
||||
},
|
||||
data() {
|
||||
@@ -312,7 +316,7 @@ export const pushConnection = defineComponent({
|
||||
|
||||
codeNodeEditorEventBus.emit('error-line-number', lineNumber || 'final');
|
||||
|
||||
const workflow = this.getCurrentWorkflow();
|
||||
const workflow = this.workflowHelpers.getCurrentWorkflow();
|
||||
if (runDataExecuted.waitTill !== undefined) {
|
||||
const activeExecutionId = this.workflowsStore.activeExecutionId;
|
||||
const workflowSettings = this.workflowsStore.workflowSettings;
|
||||
@@ -328,7 +332,8 @@ export const pushConnection = defineComponent({
|
||||
globalLinkActionsEventBus.emit('registerGlobalLinkAction', {
|
||||
key: 'open-settings',
|
||||
action: async () => {
|
||||
if (this.workflowsStore.isNewWorkflow) await this.saveAsNewWorkflow();
|
||||
if (this.workflowsStore.isNewWorkflow)
|
||||
await this.workflowHelpers.saveAsNewWorkflow();
|
||||
this.uiStore.openModal(WORKFLOW_SETTINGS_MODAL_KEY);
|
||||
},
|
||||
});
|
||||
@@ -357,7 +362,7 @@ export const pushConnection = defineComponent({
|
||||
) {
|
||||
const error = runDataExecuted.data.resultData.error as ExpressionError;
|
||||
|
||||
void this.getWorkflowDataToSave().then((workflowData) => {
|
||||
void this.workflowHelpers.getWorkflowDataToSave().then((workflowData) => {
|
||||
const eventData: IDataObject = {
|
||||
caused_by_credential: false,
|
||||
error_message: error.description,
|
||||
@@ -366,7 +371,7 @@ export const pushConnection = defineComponent({
|
||||
node_graph_string: JSON.stringify(
|
||||
TelemetryHelpers.generateNodesGraph(
|
||||
workflowData as IWorkflowBase,
|
||||
this.getNodeTypes(),
|
||||
this.workflowHelpers.getNodeTypes(),
|
||||
).nodeGraph,
|
||||
),
|
||||
workflow_id: this.workflowsStore.workflowId,
|
||||
|
||||
@@ -2,7 +2,6 @@ import { defineComponent } from 'vue';
|
||||
import { mapStores } from 'pinia';
|
||||
import { useStorage } from '@/composables/useStorage';
|
||||
|
||||
import { workflowHelpers } from '@/mixins/workflowHelpers';
|
||||
import { useToast } from '@/composables/useToast';
|
||||
|
||||
import {
|
||||
@@ -14,11 +13,15 @@ import { useUIStore } from '@/stores/ui.store';
|
||||
import { useSettingsStore } from '@/stores/settings.store';
|
||||
import { useWorkflowsStore } from '@/stores/workflows.store';
|
||||
import { useExternalHooks } from '@/composables/useExternalHooks';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useWorkflowHelpers } from '@/composables/useWorkflowHelpers';
|
||||
|
||||
export const workflowActivate = defineComponent({
|
||||
mixins: [workflowHelpers],
|
||||
setup() {
|
||||
const router = useRouter();
|
||||
const workflowHelpers = useWorkflowHelpers(router);
|
||||
return {
|
||||
workflowHelpers,
|
||||
...useToast(),
|
||||
};
|
||||
},
|
||||
@@ -45,7 +48,7 @@ export const workflowActivate = defineComponent({
|
||||
|
||||
let currWorkflowId: string | undefined = workflowId;
|
||||
if (!currWorkflowId || currWorkflowId === PLACEHOLDER_EMPTY_WORKFLOW_ID) {
|
||||
const saved = await this.saveCurrentWorkflow();
|
||||
const saved = await this.workflowHelpers.saveCurrentWorkflow();
|
||||
if (!saved) {
|
||||
this.updatingWorkflowActivation = false;
|
||||
return;
|
||||
@@ -92,7 +95,7 @@ export const workflowActivate = defineComponent({
|
||||
return;
|
||||
}
|
||||
|
||||
await this.updateWorkflow(
|
||||
await this.workflowHelpers.updateWorkflow(
|
||||
{ workflowId: currWorkflowId, active: newActiveState },
|
||||
!this.uiStore.stateIsDirty,
|
||||
);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,7 +18,6 @@ import {
|
||||
|
||||
import { useToast } from '@/composables/useToast';
|
||||
import { useNodeHelpers } from '@/composables/useNodeHelpers';
|
||||
import { workflowHelpers } from '@/mixins/workflowHelpers';
|
||||
|
||||
import { FORM_TRIGGER_NODE_TYPE, WAIT_NODE_TYPE } from '@/constants';
|
||||
import { useTitleChange } from '@/composables/useTitleChange';
|
||||
@@ -27,16 +26,20 @@ import { useUIStore } from '@/stores/ui.store';
|
||||
import { useWorkflowsStore } from '@/stores/workflows.store';
|
||||
import { openPopUpWindow } from '@/utils/executionUtils';
|
||||
import { useExternalHooks } from '@/composables/useExternalHooks';
|
||||
import { useWorkflowHelpers } from '@/composables/useWorkflowHelpers';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
export const workflowRun = defineComponent({
|
||||
mixins: [workflowHelpers],
|
||||
setup() {
|
||||
const nodeHelpers = useNodeHelpers();
|
||||
const router = useRouter();
|
||||
const workflowHelpers = useWorkflowHelpers(router);
|
||||
|
||||
return {
|
||||
...useTitleChange(),
|
||||
...useToast(),
|
||||
nodeHelpers,
|
||||
workflowHelpers,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -81,7 +84,7 @@ export const workflowRun = defineComponent({
|
||||
| { triggerNode: string; nodeData: ITaskData; source?: string }
|
||||
| { source?: string },
|
||||
): Promise<IExecutionPushResponse | undefined> {
|
||||
const workflow = this.getCurrentWorkflow();
|
||||
const workflow = this.workflowHelpers.getCurrentWorkflow();
|
||||
|
||||
if (this.uiStore.isActionActive('workflowRunning')) {
|
||||
return;
|
||||
@@ -97,7 +100,10 @@ export const workflowRun = defineComponent({
|
||||
const issuesExist = this.workflowsStore.nodesIssuesExist;
|
||||
if (issuesExist) {
|
||||
// If issues exist get all of the issues of all nodes
|
||||
const workflowIssues = this.checkReadyForExecution(workflow, options.destinationNode);
|
||||
const workflowIssues = this.workflowHelpers.checkReadyForExecution(
|
||||
workflow,
|
||||
options.destinationNode,
|
||||
);
|
||||
if (workflowIssues !== null) {
|
||||
const errorMessages = [];
|
||||
let nodeIssues: string[];
|
||||
@@ -143,7 +149,7 @@ export const workflowRun = defineComponent({
|
||||
nodeName: options.destinationNode,
|
||||
});
|
||||
|
||||
await this.getWorkflowDataToSave().then((workflowData) => {
|
||||
await this.workflowHelpers.getWorkflowDataToSave().then((workflowData) => {
|
||||
this.$telemetry.track('Workflow execution preflight failed', {
|
||||
workflow_id: workflow.id,
|
||||
workflow_name: workflow.name,
|
||||
@@ -152,7 +158,7 @@ export const workflowRun = defineComponent({
|
||||
node_graph_string: JSON.stringify(
|
||||
TelemetryHelpers.generateNodesGraph(
|
||||
workflowData as IWorkflowBase,
|
||||
this.getNodeTypes(),
|
||||
this.workflowHelpers.getNodeTypes(),
|
||||
).nodeGraph,
|
||||
),
|
||||
error_node_types: JSON.stringify(trackErrorNodeTypes),
|
||||
@@ -231,10 +237,10 @@ export const workflowRun = defineComponent({
|
||||
}
|
||||
|
||||
if (this.workflowsStore.isNewWorkflow) {
|
||||
await this.saveCurrentWorkflow();
|
||||
await this.workflowHelpers.saveCurrentWorkflow();
|
||||
}
|
||||
|
||||
const workflowData = await this.getWorkflowDataToSave();
|
||||
const workflowData = await this.workflowHelpers.getWorkflowDataToSave();
|
||||
|
||||
const startRunData: IStartRunData = {
|
||||
workflowData,
|
||||
|
||||
Reference in New Issue
Block a user