From 4e0958cd24985ab02a5c2d227a1c6ff0f6ef948f Mon Sep 17 00:00:00 2001 From: oleg Date: Mon, 12 Feb 2024 10:45:05 +0100 Subject: [PATCH] refactor(editor): Refactor workflowHelpers mixin to composable (no-changelog) (#8600) --- .../AssignmentCollection/Assignment.vue | 2 +- .../__tests__/AssignmentCollection.test.ts | 2 +- .../components/AssignmentCollection/utils.ts | 2 +- .../CodeNodeEditor/CodeNodeEditor.vue | 3 +- .../src/components/ContactPromptModal.vue | 2 - .../components/DuplicateWorkflowDialog.vue | 12 +- .../ExecutionsInfoAccordion.vue | 14 +- .../ExecutionsView/ExecutionsList.vue | 11 +- .../ExpressionEditorModalInput.vue | 3 +- .../components/FilterConditions/Condition.vue | 4 +- .../FilterConditions/FilterConditions.vue | 2 +- .../InlineExpressionEditorInput.vue | 3 +- .../editor-ui/src/components/InputPanel.vue | 5 +- .../src/components/MainHeader/MainHeader.vue | 5 +- .../components/MainHeader/WorkflowDetails.vue | 16 +- packages/editor-ui/src/components/Node.vue | 3 +- .../src/components/NodeDetailsView.vue | 12 +- .../src/components/NodeExecuteButton.vue | 2 +- .../editor-ui/src/components/NodeWebhooks.vue | 16 +- .../src/components/ParameterInput.vue | 13 +- .../src/components/ParameterInputList.vue | 11 +- .../src/components/ParameterInputWrapper.vue | 14 +- .../src/components/PersonalizationModal.vue | 2 - .../ResourceLocator/ResourceLocator.vue | 21 +- .../ResourceMapper/ResourceMapper.vue | 2 +- packages/editor-ui/src/components/Sticky.vue | 5 +- .../editor-ui/src/components/TriggerPanel.vue | 30 +- .../editor-ui/src/components/ValueSurvey.vue | 2 - .../src/components/VariableSelector.vue | 22 +- .../src/components/WorkflowLMChat.vue | 22 +- .../__tests__/ResourceMapper.test.ts | 2 +- .../editor-ui/src/composables/useDebounce.ts | 2 +- .../src/composables/useWorkflowHelpers.ts | 1211 +++++++++++++++++ .../mixins/__tests__/workflowHelpers.spec.ts | 2 +- .../editor-ui/src/mixins/expressionManager.ts | 6 +- .../editor-ui/src/mixins/pushConnection.ts | 19 +- .../editor-ui/src/mixins/workflowActivate.ts | 11 +- .../editor-ui/src/mixins/workflowHelpers.ts | 1211 ----------------- packages/editor-ui/src/mixins/workflowRun.ts | 22 +- .../completions/__tests__/completions.test.ts | 2 +- .../completions/bracketAccess.completions.ts | 2 +- .../completions/datatype.completions.ts | 2 +- .../plugins/codemirror/completions/types.ts | 2 +- .../plugins/codemirror/completions/utils.ts | 2 +- packages/editor-ui/src/views/NodeView.vue | 127 +- .../src/views/TemplatesCollectionView.vue | 2 - .../src/views/TemplatesWorkflowView.vue | 2 - 47 files changed, 1487 insertions(+), 1403 deletions(-) create mode 100644 packages/editor-ui/src/composables/useWorkflowHelpers.ts delete mode 100644 packages/editor-ui/src/mixins/workflowHelpers.ts diff --git a/packages/editor-ui/src/components/AssignmentCollection/Assignment.vue b/packages/editor-ui/src/components/AssignmentCollection/Assignment.vue index 1d5d166fba0361..6634e747a6fd1e 100644 --- a/packages/editor-ui/src/components/AssignmentCollection/Assignment.vue +++ b/packages/editor-ui/src/components/AssignmentCollection/Assignment.vue @@ -4,7 +4,7 @@ import InputTriple from '@/components/InputTriple/InputTriple.vue'; import ParameterInputFull from '@/components/ParameterInputFull.vue'; import ParameterInputHint from '@/components/ParameterInputHint.vue'; import ParameterIssues from '@/components/ParameterIssues.vue'; -import { resolveParameter } from '@/mixins/workflowHelpers'; +import { resolveParameter } from '@/composables/useWorkflowHelpers'; import { isExpression } from '@/utils/expressions'; import { isObject } from '@jsplumb/util'; import type { AssignmentValue, INodeProperties } from 'n8n-workflow'; diff --git a/packages/editor-ui/src/components/AssignmentCollection/__tests__/AssignmentCollection.test.ts b/packages/editor-ui/src/components/AssignmentCollection/__tests__/AssignmentCollection.test.ts index fb425a6bc0617e..28b2e1755633f6 100644 --- a/packages/editor-ui/src/components/AssignmentCollection/__tests__/AssignmentCollection.test.ts +++ b/packages/editor-ui/src/components/AssignmentCollection/__tests__/AssignmentCollection.test.ts @@ -3,7 +3,7 @@ import { useNDVStore } from '@/stores/ndv.store'; import { createTestingPinia } from '@pinia/testing'; import userEvent from '@testing-library/user-event'; import { fireEvent, within } from '@testing-library/vue'; -import * as workflowHelpers from '@/mixins/workflowHelpers'; +import * as workflowHelpers from '@/composables/useWorkflowHelpers'; import AssignmentCollection from '../AssignmentCollection.vue'; import { createPinia, setActivePinia } from 'pinia'; diff --git a/packages/editor-ui/src/components/AssignmentCollection/utils.ts b/packages/editor-ui/src/components/AssignmentCollection/utils.ts index d4845aa59839e9..cb2ddd4b3c1ac7 100644 --- a/packages/editor-ui/src/components/AssignmentCollection/utils.ts +++ b/packages/editor-ui/src/components/AssignmentCollection/utils.ts @@ -1,6 +1,6 @@ import { isObject } from 'lodash-es'; import type { AssignmentValue, IDataObject } from 'n8n-workflow'; -import { resolveParameter } from '@/mixins/workflowHelpers'; +import { resolveParameter } from '@/composables/useWorkflowHelpers'; import { v4 as uuid } from 'uuid'; export function nameFromExpression(expression: string): string { diff --git a/packages/editor-ui/src/components/CodeNodeEditor/CodeNodeEditor.vue b/packages/editor-ui/src/components/CodeNodeEditor/CodeNodeEditor.vue index d45468210bf96f..8925f6e9cc8c96 100644 --- a/packages/editor-ui/src/components/CodeNodeEditor/CodeNodeEditor.vue +++ b/packages/editor-ui/src/components/CodeNodeEditor/CodeNodeEditor.vue @@ -63,7 +63,6 @@ import { python } from '@codemirror/lang-python'; import type { CodeExecutionMode, CodeNodeEditorLanguage } from 'n8n-workflow'; import { CODE_EXECUTION_MODES, CODE_LANGUAGES } from 'n8n-workflow'; -import { workflowHelpers } from '@/mixins/workflowHelpers'; // for json field completions import { ASK_AI_EXPERIMENT, CODE_NODE_TYPE } from '@/constants'; import { codeNodeEditorEventBus } from '@/event-bus'; import { useRootStore } from '@/stores/n8nRoot.store'; @@ -83,7 +82,7 @@ export default defineComponent({ components: { AskAI, }, - mixins: [linterExtension, completerExtension, workflowHelpers], + mixins: [linterExtension, completerExtension], props: { aiButtonEnabled: { type: Boolean, diff --git a/packages/editor-ui/src/components/ContactPromptModal.vue b/packages/editor-ui/src/components/ContactPromptModal.vue index c0ee2f70da50d9..dcf1e975980900 100644 --- a/packages/editor-ui/src/components/ContactPromptModal.vue +++ b/packages/editor-ui/src/components/ContactPromptModal.vue @@ -37,7 +37,6 @@ import { defineComponent } from 'vue'; import { mapStores } from 'pinia'; import type { IN8nPromptResponse } from '@/Interface'; import { VALID_EMAIL_REGEX } from '@/constants'; -import { workflowHelpers } from '@/mixins/workflowHelpers'; import Modal from '@/components/Modal.vue'; import { useSettingsStore } from '@/stores/settings.store'; import { useRootStore } from '@/stores/n8nRoot.store'; @@ -47,7 +46,6 @@ import { useToast } from '@/composables/useToast'; export default defineComponent({ name: 'ContactPromptModal', components: { Modal }, - mixins: [workflowHelpers], props: ['modalName'], setup() { return { diff --git a/packages/editor-ui/src/components/DuplicateWorkflowDialog.vue b/packages/editor-ui/src/components/DuplicateWorkflowDialog.vue index d769d8955fa049..20469d02258c99 100644 --- a/packages/editor-ui/src/components/DuplicateWorkflowDialog.vue +++ b/packages/editor-ui/src/components/DuplicateWorkflowDialog.vue @@ -51,7 +51,6 @@ import { defineComponent } from 'vue'; import { mapStores } from 'pinia'; import { MAX_WORKFLOW_NAME_LENGTH, PLACEHOLDER_EMPTY_WORKFLOW_ID } from '@/constants'; -import { workflowHelpers } from '@/mixins/workflowHelpers'; import { useToast } from '@/composables/useToast'; import TagsDropdown from '@/components/TagsDropdown.vue'; import Modal from '@/components/Modal.vue'; @@ -63,15 +62,20 @@ import { getWorkflowPermissions } from '@/permissions'; import { useUsersStore } from '@/stores/users.store'; import { createEventBus } from 'n8n-design-system/utils'; import { useCredentialsStore } from '@/stores/credentials.store'; +import { useWorkflowHelpers } from '@/composables/useWorkflowHelpers'; +import { useRouter } from 'vue-router'; export default defineComponent({ name: 'DuplicateWorkflow', components: { TagsDropdown, Modal }, - mixins: [workflowHelpers], props: ['modalName', 'isActive', 'data'], setup() { + const router = useRouter(); + const workflowHelpers = useWorkflowHelpers(router); + return { ...useToast(), + workflowHelpers, }; }, data() { @@ -156,13 +160,13 @@ export default defineComponent({ await this.workflowsStore.fetchWorkflow(this.data.id); workflowToUpdate = workflow; - this.removeForeignCredentialsFromWorkflow( + this.workflowHelpers.removeForeignCredentialsFromWorkflow( workflowToUpdate, this.credentialsStore.allCredentials, ); } - const saved = await this.saveAsNewWorkflow({ + const saved = await this.workflowHelpers.saveAsNewWorkflow({ name, data: workflowToUpdate, tags: this.currentTagIds, diff --git a/packages/editor-ui/src/components/ExecutionsView/ExecutionsInfoAccordion.vue b/packages/editor-ui/src/components/ExecutionsView/ExecutionsInfoAccordion.vue index 318ff4f5ba39f7..2b1cccc15156ce 100644 --- a/packages/editor-ui/src/components/ExecutionsView/ExecutionsInfoAccordion.vue +++ b/packages/editor-ui/src/components/ExecutionsView/ExecutionsInfoAccordion.vue @@ -45,7 +45,8 @@ import { useWorkflowsStore } from '@/stores/workflows.store'; import { PLACEHOLDER_EMPTY_WORKFLOW_ID, WORKFLOW_SETTINGS_MODAL_KEY } from '@/constants'; import type { IWorkflowSettings } from 'n8n-workflow'; import { deepCopy } from 'n8n-workflow'; -import { workflowHelpers } from '@/mixins/workflowHelpers'; +import { useWorkflowHelpers } from '@/composables/useWorkflowHelpers'; +import { useRouter } from 'vue-router'; interface IWorkflowSaveSettings { saveFailedExecutions: boolean; @@ -55,13 +56,20 @@ interface IWorkflowSaveSettings { export default defineComponent({ name: 'ExecutionsInfoAccordion', - mixins: [workflowHelpers], props: { initiallyExpanded: { type: Boolean, default: false, }, }, + setup() { + const router = useRouter(); + const workflowHelpers = useWorkflowHelpers(router); + + return { + workflowHelpers, + }; + }, data() { return { defaultValues: { @@ -211,7 +219,7 @@ export default defineComponent({ } else if (this.$route.params.name && this.$route.params.name !== 'new') { currentId = this.$route.params.name; } - const saved = await this.saveCurrentWorkflow({ + const saved = await this.workflowHelpers.saveCurrentWorkflow({ id: currentId, name: this.workflowName, tags: this.currentWorkflowTagIds, diff --git a/packages/editor-ui/src/components/ExecutionsView/ExecutionsList.vue b/packages/editor-ui/src/components/ExecutionsView/ExecutionsList.vue index 9b90bb4c58cb00..4a20a89a05e492 100644 --- a/packages/editor-ui/src/components/ExecutionsView/ExecutionsList.vue +++ b/packages/editor-ui/src/components/ExecutionsView/ExecutionsList.vue @@ -55,12 +55,11 @@ import { NodeHelpers } from 'n8n-workflow'; import { useMessage } from '@/composables/useMessage'; import { useToast } from '@/composables/useToast'; import { v4 as uuid } from 'uuid'; -import type { Route } from 'vue-router'; +import { useRouter, type Route } from 'vue-router'; import { executionHelpers } from '@/mixins/executionsHelpers'; import { range as _range } from 'lodash-es'; import { NO_NETWORK_ERROR_CODE } from '@/utils/apiUtils'; import { getNodeViewTab } from '@/utils/canvasUtils'; -import { workflowHelpers } from '@/mixins/workflowHelpers'; import { useWorkflowsStore } from '@/stores/workflows.store'; import { useUIStore } from '@/stores/ui.store'; import { useSettingsStore } from '@/stores/settings.store'; @@ -69,6 +68,7 @@ import { useTagsStore } from '@/stores/tags.store'; import { executionFilterToQueryFilter } from '@/utils/executionUtils'; import { useExternalHooks } from '@/composables/useExternalHooks'; import { useDebounce } from '@/composables/useDebounce'; +import { useWorkflowHelpers } from '@/composables/useWorkflowHelpers'; // Number of execution pages that are fetched before temporary execution card is shown const MAX_LOADING_ATTEMPTS = 5; @@ -80,13 +80,16 @@ export default defineComponent({ components: { ExecutionsSidebar, }, - mixins: [executionHelpers, workflowHelpers], + mixins: [executionHelpers], setup() { const externalHooks = useExternalHooks(); + const router = useRouter(); + const workflowHelpers = useWorkflowHelpers(router); const { callDebounced } = useDebounce(); return { externalHooks, + workflowHelpers, callDebounced, ...useToast(), ...useMessage(), @@ -168,7 +171,7 @@ export default defineComponent({ ); if (confirmModal === MODAL_CONFIRM) { - const saved = await this.saveCurrentWorkflow({}, false); + const saved = await this.workflowHelpers.saveCurrentWorkflow({}, false); if (saved) { await this.settingsStore.fetchPromptsData(); } diff --git a/packages/editor-ui/src/components/ExpressionEditorModal/ExpressionEditorModalInput.vue b/packages/editor-ui/src/components/ExpressionEditorModal/ExpressionEditorModalInput.vue index 52bac85329ceb9..a08d3d964a7996 100644 --- a/packages/editor-ui/src/components/ExpressionEditorModal/ExpressionEditorModalInput.vue +++ b/packages/editor-ui/src/components/ExpressionEditorModal/ExpressionEditorModalInput.vue @@ -8,7 +8,6 @@ import { EditorView, keymap } from '@codemirror/view'; import { EditorState, Prec } from '@codemirror/state'; import { history, redo, undo } from '@codemirror/commands'; -import { workflowHelpers } from '@/mixins/workflowHelpers'; import { expressionManager } from '@/mixins/expressionManager'; import { completionManager } from '@/mixins/completionManager'; import { expressionInputHandler } from '@/plugins/codemirror/inputHandlers/expression.inputHandler'; @@ -22,7 +21,7 @@ import type { IVariableItemSelected } from '@/Interface'; export default defineComponent({ name: 'ExpressionEditorModalInput', - mixins: [expressionManager, completionManager, workflowHelpers], + mixins: [expressionManager, completionManager], props: { modelValue: { type: String, diff --git a/packages/editor-ui/src/components/FilterConditions/Condition.vue b/packages/editor-ui/src/components/FilterConditions/Condition.vue index 98ecc417e628ad..7f6978c3a07b10 100644 --- a/packages/editor-ui/src/components/FilterConditions/Condition.vue +++ b/packages/editor-ui/src/components/FilterConditions/Condition.vue @@ -4,7 +4,7 @@ import InputTriple from '@/components/InputTriple/InputTriple.vue'; import ParameterInputFull from '@/components/ParameterInputFull.vue'; import ParameterIssues from '@/components/ParameterIssues.vue'; import { useI18n } from '@/composables/useI18n'; -import { resolveParameter } from '@/mixins/workflowHelpers'; +import { resolveParameter } from '@/composables/useWorkflowHelpers'; import { DateTime } from 'luxon'; import { FilterError, @@ -240,7 +240,7 @@ const onBlur = (): void => { @operatorChange="onOperatorChange" > -