From 596cf07e42155338d6997edc1aff66db77d1edc2 Mon Sep 17 00:00:00 2001 From: Alex Grozav Date: Thu, 15 Jun 2023 15:30:05 +0300 Subject: [PATCH] feat: Replace all Vue.set usages with direct assignment and spread operator (no-changelog) (#6280) * refactor: replace all Vue.set usages with direct assignment and spread operator * chore: fix linting issue * fix: fix updateNodeAtIndex function * fix: various post-refactoring fixes * fix: refactor recently added Vue.set directive --- cypress/e2e/12-canvas.cy.ts | 3 +- cypress/e2e/14-mapping.cy.ts | 33 ++- cypress/pages/ndv.ts | 36 ++- packages/editor-ui/src/Interface.ts | 11 +- .../CredentialEdit/AuthTypeSelector.vue | 13 +- .../CredentialEdit/CredentialConfig.vue | 2 +- .../CredentialEdit/CredentialEdit.vue | 55 +++- .../src/components/ExecutionsList.vue | 23 +- .../src/components/NodeDetailsView.vue | 4 +- .../editor-ui/src/components/NodeSettings.vue | 86 ++++-- .../EventDestinationSettingsModal.ee.vue | 10 +- .../src/components/TagsContainer.vue | 4 +- .../src/components/WorkflowSettings.vue | 10 +- .../editor-ui/src/stores/credentials.store.ts | 42 +-- .../editor-ui/src/stores/n8nRoot.store.ts | 27 +- packages/editor-ui/src/stores/ndv.store.ts | 64 +++-- .../editor-ui/src/stores/nodeTypes.store.ts | 3 +- .../editor-ui/src/stores/settings.store.ts | 19 +- packages/editor-ui/src/stores/tags.store.ts | 10 +- .../editor-ui/src/stores/templates.store.ts | 74 +++-- packages/editor-ui/src/stores/ui.store.ts | 79 ++++-- packages/editor-ui/src/stores/users.store.ts | 19 +- .../src/stores/workflows.ee.store.ts | 39 ++- .../editor-ui/src/stores/workflows.store.ts | 261 +++++++++++++----- 24 files changed, 620 insertions(+), 307 deletions(-) diff --git a/cypress/e2e/12-canvas.cy.ts b/cypress/e2e/12-canvas.cy.ts index 29869e4434..65428acda8 100644 --- a/cypress/e2e/12-canvas.cy.ts +++ b/cypress/e2e/12-canvas.cy.ts @@ -29,7 +29,6 @@ describe('Canvas Node Manipulation and Navigation', () => { WorkflowPage.actions.visit(); }); - it('should add switch node and test connections', () => { WorkflowPage.actions.addNodeToCanvas(SWITCH_NODE_NAME, true); @@ -114,7 +113,7 @@ describe('Canvas Node Manipulation and Navigation', () => { WorkflowPage.actions.zoomToFit(); cy.get('.plus-draggable-endpoint').filter(':visible').should('not.have.class', 'ep-success'); - cy.get('.jtk-connector.success').should('have.length', 3); + cy.get('.jtk-connector.success').should('have.length', 4); cy.get('.jtk-connector').should('have.length', 4); }); diff --git a/cypress/e2e/14-mapping.cy.ts b/cypress/e2e/14-mapping.cy.ts index b66e909b59..c7035396d3 100644 --- a/cypress/e2e/14-mapping.cy.ts +++ b/cypress/e2e/14-mapping.cy.ts @@ -16,12 +16,10 @@ describe('Data mapping', () => { beforeEach(() => { workflowPage.actions.visit(); - cy.window().then( - (win) => { - // @ts-ignore - win.preventNodeViewBeforeUnload = true; - }, - ); + cy.window().then((win) => { + // @ts-ignore + win.preventNodeViewBeforeUnload = true; + }); }); it('maps expressions from table header', () => { @@ -303,19 +301,28 @@ describe('Data mapping', () => { ndv.getters.parameterInput('keepOnlySet').find('input[type="checkbox"]').should('exist'); ndv.getters.parameterInput('keepOnlySet').find('input[type="text"]').should('not.exist'); - ndv.getters.inputDataContainer().should('exist').find('span').contains('count').realMouseDown().realMouseMove(100, 100); + ndv.getters + .inputDataContainer() + .should('exist') + .find('span') + .contains('count') + .realMouseDown() + .realMouseMove(100, 100); cy.wait(50); ndv.getters.parameterInput('keepOnlySet').find('input[type="checkbox"]').should('not.exist'); - ndv.getters.parameterInput('keepOnlySet').find('input[type="text"]') + ndv.getters + .parameterInput('keepOnlySet') + .find('input[type="text"]') .should('exist') .invoke('css', 'border') .then((border) => expect(border).to.include('dashed rgb(90, 76, 194)')); - ndv.getters.parameterInput('value').find('input[type="text"]') - .should('exist') - .invoke('css', 'border') - .then((border) => expect(border).to.include('dashed rgb(90, 76, 194)')); + ndv.getters + .parameterInput('value') + .find('input[type="text"]') + .should('exist') + .invoke('css', 'border') + .then((border) => expect(border).to.include('dashed rgb(90, 76, 194)')); }); - }); diff --git a/cypress/pages/ndv.ts b/cypress/pages/ndv.ts index f23eb97f4f..2a9b6edc4f 100644 --- a/cypress/pages/ndv.ts +++ b/cypress/pages/ndv.ts @@ -13,14 +13,17 @@ export class NDV extends BasePage { outputPanel: () => cy.getByTestId('output-panel'), executingLoader: () => cy.getByTestId('ndv-executing'), inputDataContainer: () => this.getters.inputPanel().findChildByTestId('ndv-data-container'), - inputDisplayMode: () => this.getters.inputPanel().findChildByTestId('ndv-run-data-display-mode').first(), + inputDisplayMode: () => + this.getters.inputPanel().findChildByTestId('ndv-run-data-display-mode').first(), outputDataContainer: () => this.getters.outputPanel().findChildByTestId('ndv-data-container'), - outputDisplayMode: () => this.getters.outputPanel().findChildByTestId('ndv-run-data-display-mode').first(), + outputDisplayMode: () => + this.getters.outputPanel().findChildByTestId('ndv-run-data-display-mode').first(), pinDataButton: () => cy.getByTestId('ndv-pin-data'), editPinnedDataButton: () => cy.getByTestId('ndv-edit-pinned-data'), pinnedDataEditor: () => this.getters.outputPanel().find('.cm-editor .cm-scroller'), runDataPaneHeader: () => cy.getByTestId('run-data-pane-header'), - savePinnedDataButton: () => this.getters.runDataPaneHeader().find('button').filter(':visible').contains('Save'), + savePinnedDataButton: () => + this.getters.runDataPaneHeader().find('button').filter(':visible').contains('Save'), outputTableRows: () => this.getters.outputDataContainer().find('table tr'), outputTableHeaders: () => this.getters.outputDataContainer().find('table thead th'), outputTableRow: (row: number) => this.getters.outputTableRows().eq(row), @@ -52,10 +55,13 @@ export class NDV extends BasePage { outputBranches: () => this.getters.outputPanel().findChildByTestId('branches'), inputBranches: () => this.getters.inputPanel().findChildByTestId('branches'), resourceLocator: (paramName: string) => cy.getByTestId(`resource-locator-${paramName}`), - resourceLocatorInput: (paramName: string) => this.getters.resourceLocator(paramName).find('[data-test-id="rlc-input-container"]'), - resourceLocatorDropdown: (paramName: string) => this.getters.resourceLocator(paramName).find('[data-test-id="resource-locator-dropdown"]'), + resourceLocatorInput: (paramName: string) => + this.getters.resourceLocator(paramName).find('[data-test-id="rlc-input-container"]'), + resourceLocatorDropdown: (paramName: string) => + this.getters.resourceLocator(paramName).find('[data-test-id="resource-locator-dropdown"]'), resourceLocatorErrorMessage: () => cy.getByTestId('rlc-error-container'), - resourceLocatorModeSelector: (paramName: string) => this.getters.resourceLocator(paramName).find('[data-test-id="rlc-mode-selector"]'), + resourceLocatorModeSelector: (paramName: string) => + this.getters.resourceLocator(paramName).find('[data-test-id="rlc-mode-selector"]'), }; actions = { @@ -82,7 +88,9 @@ export class NDV extends BasePage { this.getters.editPinnedDataButton().click(); this.getters.pinnedDataEditor().click(); - this.getters.pinnedDataEditor().type(`{selectall}{backspace}${JSON.stringify(data).replace(new RegExp('{', 'g'), '{{}')}`); + this.getters + .pinnedDataEditor() + .type(`{selectall}{backspace}${JSON.stringify(data).replace(new RegExp('{', 'g'), '{{}')}`); this.actions.savePinnedData(); }, @@ -131,15 +139,11 @@ export class NDV extends BasePage { }, changeInputRunSelector: (runName: string) => { this.getters.inputRunSelector().click(); - cy.get('.el-select-dropdown:visible .el-select-dropdown__item') - .contains(runName) - .click(); + cy.get('.el-select-dropdown:visible .el-select-dropdown__item').contains(runName).click(); }, changeOutputRunSelector: (runName: string) => { this.getters.outputRunSelector().click(); - cy.get('.el-select-dropdown:visible .el-select-dropdown__item') - .contains(runName) - .click(); + cy.get('.el-select-dropdown:visible .el-select-dropdown__item').contains(runName).click(); }, toggleOutputRunLinking: () => { this.getters.outputRunSelector().find('button').click(); @@ -159,7 +163,10 @@ export class NDV extends BasePage { this.getters.resourceLocatorInput(paramName).type(value); }, validateExpressionPreview: (paramName: string, value: string) => { - this.getters.parameterExpressionPreview(paramName).find('span').should('include.html', asEncodedHTML(value)); + this.getters + .parameterExpressionPreview(paramName) + .find('span') + .should('include.html', asEncodedHTML(value)); }, }; } @@ -172,4 +179,3 @@ function asEncodedHTML(str: string): string { .replace(/"/g, '"') .replace(/ /g, ' '); } - diff --git a/packages/editor-ui/src/Interface.ts b/packages/editor-ui/src/Interface.ts index 6b4e872bec..b79ca557a0 100644 --- a/packages/editor-ui/src/Interface.ts +++ b/packages/editor-ui/src/Interface.ts @@ -975,13 +975,10 @@ export interface ITagsState { fetchedUsageCount: boolean; } -export type Modals = - | { - [key: string]: ModalState; - } - | { - [CREDENTIAL_EDIT_MODAL_KEY]: NewCredentialsModal; - }; +export type Modals = { + [CREDENTIAL_EDIT_MODAL_KEY]: NewCredentialsModal; + [key: string]: ModalState; +}; export type ModalState = { open: boolean; diff --git a/packages/editor-ui/src/components/CredentialEdit/AuthTypeSelector.vue b/packages/editor-ui/src/components/CredentialEdit/AuthTypeSelector.vue index b38dba6d49..8a74217fb8 100644 --- a/packages/editor-ui/src/components/CredentialEdit/AuthTypeSelector.vue +++ b/packages/editor-ui/src/components/CredentialEdit/AuthTypeSelector.vue @@ -11,7 +11,6 @@ import { } from '@/utils'; import type { INodeProperties, INodeTypeDescription, NodeParameterValue } from 'n8n-workflow'; import { computed, onMounted, ref } from 'vue'; -import Vue from 'vue'; export interface Props { credentialType: Object; @@ -27,7 +26,7 @@ const ndvStore = useNDVStore(); const props = defineProps(); const selected = ref(''); -const authRelatedFieldsValues = ref({} as { [key: string]: NodeParameterValue }); +const authRelatedFieldsValues = ref<{ [key: string]: NodeParameterValue }>({}); onMounted(() => { if (activeNodeType.value?.credentials) { @@ -43,7 +42,10 @@ onMounted(() => { // Populate default values of related fields authRelatedFields.value.forEach((field) => { - Vue.set(authRelatedFieldsValues.value, field.name, field.default); + authRelatedFieldsValues.value = { + ...authRelatedFieldsValues.value, + [field.name]: field.default as NodeParameterValue, + }; }); }); @@ -102,7 +104,10 @@ function onAuthTypeChange(newType: string): void { } function valueChanged(data: IUpdateInformation): void { - Vue.set(authRelatedFieldsValues.value, data.name, data.value); + authRelatedFieldsValues.value = { + ...authRelatedFieldsValues.value, + [data.name]: data.value as NodeParameterValue, + }; } defineExpose({ diff --git a/packages/editor-ui/src/components/CredentialEdit/CredentialConfig.vue b/packages/editor-ui/src/components/CredentialEdit/CredentialConfig.vue index 4071970fca..e33117ea65 100644 --- a/packages/editor-ui/src/components/CredentialEdit/CredentialConfig.vue +++ b/packages/editor-ui/src/components/CredentialEdit/CredentialConfig.vue @@ -264,7 +264,7 @@ export default defineComponent({ ); }, credentialTypeName(): string { - return (this.credentialType as ICredentialType).name; + return (this.credentialType as ICredentialType)?.name; }, credentialOwnerName(): string { return this.credentialsStore.getCredentialOwnerNameById(`${this.credentialId}`); diff --git a/packages/editor-ui/src/components/CredentialEdit/CredentialEdit.vue b/packages/editor-ui/src/components/CredentialEdit/CredentialEdit.vue index 28e7c2ea3d..37202c4eee 100644 --- a/packages/editor-ui/src/components/CredentialEdit/CredentialEdit.vue +++ b/packages/editor-ui/src/components/CredentialEdit/CredentialEdit.vue @@ -109,7 +109,6 @@