Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(editor): Supress validation errors for freshly added nodes #5149

Merged
merged 5 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions cypress/e2e/5-ndv.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,41 @@ describe('NDV', () => {
ndv.getters.dataContainer().should('contain', 'start');
});
});

it('should show correct validation state for resource locator params', () => {
workflowPage.actions.addNodeToCanvas('Typeform', true);
ndv.getters.container().should('be.visible');
cy.get('.has-issues').should('have.length', 0);
cy.get('[class*=hasIssues]').should('have.length', 0);
ndv.getters.backToCanvas().click();
// Both credentials and resource locator errors should be visible
workflowPage.actions.openNodeNdv('Typeform');
cy.get('.has-issues').should('have.length', 1);
cy.get('[class*=hasIssues]').should('have.length', 1);
});

it('should show validation errors only after blur or re-opening of NDV', () => {
workflowPage.actions.addNodeToCanvas('Manual Trigger');
workflowPage.actions.addNodeToCanvas('Airtable', true);
ndv.getters.container().should('be.visible');
cy.get('.has-issues').should('have.length', 0);
workflowPage.getters.ndvParameterInput('table').find('input').eq(1).focus().blur()
workflowPage.getters.ndvParameterInput('application').find('input').eq(1).focus().blur()
cy.get('.has-issues').should('have.length', 2);
ndv.getters.backToCanvas().click();
workflowPage.actions.openNodeNdv('Airtable');
cy.get('.has-issues').should('have.length', 3);
cy.get('[class*=hasIssues]').should('have.length', 1);
});

it('should show all validation errors when opening pasted node', () => {
cy.fixture('Test_workflow_ndv_errors.json').then((data) => {
cy.get('body').paste(JSON.stringify(data));
workflowPage.getters.canvasNodes().should('have.have.length', 1);
workflowPage.actions.openNodeNdv('Airtable');
cy.get('.has-issues').should('have.length', 3);
cy.get('[class*=hasIssues]').should('have.length', 1);
});
});

});
32 changes: 32 additions & 0 deletions cypress/fixtures/Test_workflow_ndv_errors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"meta": {
"instanceId": "3204fc455f5cbeb4e71fdbd3b1dfaf0b088088dea3e639de49e61462b80ffc1d"
},
"nodes": [
{
"parameters": {
"application": {
"__rl": true,
"mode": "url",
"value": "",
"__regex": "https://airtable.com/([a-zA-Z0-9]{2,})"
},
"table": {
"__rl": true,
"mode": "url",
"value": "",
"__regex": "https://airtable.com/[a-zA-Z0-9]{2,}/([a-zA-Z0-9]{2,})"
}
},
"id": "e0c0cf7e-aa98-4b72-9645-6e64e2902bd1",
"name": "Airtable",
"type": "n8n-nodes-base.airtable",
"typeVersion": 1,
"position": [
380,
180
]
}
],
"connections": {}
}
5 changes: 3 additions & 2 deletions cypress/pages/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ export class WorkflowPage extends BasePage {
this.getters.nodeCreatorSearchBar().type('{enter}');
cy.get('body').type('{esc}');
},
addNodeToCanvas: (nodeDisplayName: string) => {
addNodeToCanvas: (nodeDisplayName: string, preventNdvClose?: boolean) => {
this.getters.nodeCreatorPlusButton().click();
this.getters.nodeCreatorSearchBar().type(nodeDisplayName);
this.getters.nodeCreatorSearchBar().type('{enter}');
cy.get('body').type('{esc}');

if (!preventNdvClose) cy.get('body').type('{esc}');
},
openNodeNdv: (nodeTypeName: string) => {
this.getters.canvasNodeByName(nodeTypeName).dblclick();
Expand Down
1 change: 1 addition & 0 deletions packages/editor-ui/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ export interface ITemplatesNode extends IVersionNode {

export interface INodeMetadata {
parametersLastUpdatedAt?: number;
pristine: boolean;
}

export interface IUsedCredential {
Expand Down
28 changes: 21 additions & 7 deletions packages/editor-ui/src/components/NodeCredentials.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
size="small"
/>
</div>
<div v-else :class="issues.length ? $style.hasIssues : $style.input">
<div v-else :class="issues.length && !hideIssues ? $style.hasIssues : $style.input">
<n8n-select
:value="getSelectedId(credentialTypeDescription.name)"
@change="(value) => onCredentialSelected(credentialTypeDescription.name, value)"
@blur="$emit('blur', 'credentials')"
:placeholder="getSelectPlaceholder(credentialTypeDescription.name, issues)"
size="small"
>
Expand All @@ -49,7 +50,7 @@
</n8n-option>
</n8n-select>

<div :class="$style.warning" v-if="issues.length">
<div :class="$style.warning" v-if="issues.length && !hideIssues">
<n8n-tooltip placement="top">
<template #content>
<titled-list
Expand Down Expand Up @@ -82,6 +83,7 @@
</template>

<script lang="ts">
import { PropType } from 'vue';
import { restApi } from '@/mixins/restApi';
import {
ICredentialsResponse,
Expand All @@ -108,11 +110,23 @@ import { useCredentialsStore } from '@/stores/credentials';

export default mixins(genericHelpers, nodeHelpers, restApi, showMessage).extend({
name: 'NodeCredentials',
props: [
'readonly',
'node', // INodeUi
'overrideCredType', // cred type
],
props: {
readonly: {
type: Boolean,
default: false,
},
node: {
type: Object as PropType<INodeUi>,
required: true,
},
overrideCredType: {
type: String,
},
hideIssues: {
type: Boolean,
default: false,
},
},
components: {
TitledList,
},
Expand Down
27 changes: 26 additions & 1 deletion packages/editor-ui/src/components/NodeSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,18 @@
:hideDelete="true"
:nodeValues="nodeValues"
:isReadOnly="isReadOnly"
:hiddenIssuesInputs="hiddenIssuesInputs"
path="parameters"
@valueChanged="valueChanged"
@activate="onWorkflowActivate"
@parameterBlur="onParameterBlur"
>
<node-credentials
:node="node"
:readonly="isReadOnly"
@credentialSelected="credentialSelected"
@blur="onParameterBlur"
:hide-issues="hiddenIssuesInputs.includes('credentials')"
/>
</parameter-input-list>
<div v-if="parametersNoneSetting.length === 0" class="no-parameters">
Expand All @@ -124,16 +128,20 @@
:parameters="parametersSetting"
:nodeValues="nodeValues"
:isReadOnly="isReadOnly"
:hiddenIssuesInputs="hiddenIssuesInputs"
path="parameters"
@valueChanged="valueChanged"
@parameterBlur="onParameterBlur"
/>
<parameter-input-list
:parameters="nodeSettings"
:hideDelete="true"
:nodeValues="nodeValues"
:isReadOnly="isReadOnly"
:hiddenIssuesInputs="hiddenIssuesInputs"
path=""
@valueChanged="valueChanged"
@parameterBlur="onParameterBlur"
/>
</div>
</div>
Expand Down Expand Up @@ -414,6 +422,7 @@ export default mixins(externalHooks, nodeHelpers).extend({
COMMUNITY_NODES_INSTALLATION_DOCS_URL,
CUSTOM_NODES_DOCS_URL,
MAIN_NODE_PANEL_WIDTH,
hiddenIssuesInputs: [] as string[],
mutdmour marked this conversation as resolved.
Show resolved Hide resolved
};
},
watch: {
Expand Down Expand Up @@ -445,10 +454,25 @@ export default mixins(externalHooks, nodeHelpers).extend({
},
},
methods: {
populateHiddenIssuesSet() {
if (!this.node || !this.workflowsStore.isNodePristine(this.node.name)) return;

this.hiddenIssuesInputs.push('credentials');
this.parametersNoneSetting.forEach((parameter) => {
this.hiddenIssuesInputs.push(parameter.name);
});

this.workflowsStore.setNodePristine(this.node.name, false);
},
onParameterBlur(parameterName: string) {
this.hiddenIssuesInputs = this.hiddenIssuesInputs.filter((name) => name !== parameterName);
},
onWorkflowActivate() {
this.hiddenIssuesInputs = [];
this.$emit('activate');
},
onNodeExecute() {
this.hiddenIssuesInputs = [];
this.$emit('execute');
},
setValue(name: string, value: NodeParameterValue) {
Expand All @@ -457,7 +481,7 @@ export default mixins(externalHooks, nodeHelpers).extend({

let isArray = false;
if (lastNamePart !== undefined && lastNamePart.includes('[')) {
// It incldues an index so we have to extract it
// It includes an index so we have to extract it
const lastNameParts = lastNamePart.match(/(.*)\[(\d+)\]$/);
if (lastNameParts) {
nameParts.push(lastNameParts[1]);
Expand Down Expand Up @@ -835,6 +859,7 @@ export default mixins(externalHooks, nodeHelpers).extend({
},
},
mounted() {
this.populateHiddenIssuesSet();
this.setNodeValues();
if (this.eventBus) {
(this.eventBus as Vue).$on('openSettings', () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/editor-ui/src/components/ParameterInputFull.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
:activeDrop="activeDrop"
:forceShowExpression="forceShowExpression"
:hint="hint"
:hide-issues="hideIssues"
@valueChanged="valueChanged"
@textInput="onTextInput"
@focus="onFocus"
Expand Down Expand Up @@ -118,6 +119,10 @@ export default mixins(showMessage).extend({
type: Boolean,
default: false,
},
hideIssues: {
type: Boolean,
default: false,
},
parameter: {
type: Object as PropType<INodeProperties>,
},
Expand Down Expand Up @@ -196,6 +201,7 @@ export default mixins(showMessage).extend({
if (!this.parameter.noDataExpression) {
this.ndvStore.setMappableNDVInputFocus('');
}
this.$emit('blur');
},
onMenuExpanded(expanded: boolean) {
this.menuExpanded = expanded;
Expand Down
55 changes: 38 additions & 17 deletions packages/editor-ui/src/components/ParameterInputList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@

<parameter-input-full
:parameter="parameter"
:hide-issues="hiddenIssuesInputs.includes(parameter.name)"
:value="getParameterValue(nodeValues, parameter.name, path)"
:displayOptions="true"
:path="getPath(parameter.name)"
:isReadOnly="isReadOnly"
@valueChanged="valueChanged"
@blur="onParameterBlur(parameter.name)"
/>
</div>
</div>
Expand All @@ -108,13 +110,7 @@
</template>

<script lang="ts">
import {
deepCopy,
INodeParameters,
INodeProperties,
INodeTypeDescription,
NodeParameterValue,
} from 'n8n-workflow';
import { deepCopy, INodeParameters, INodeProperties, NodeParameterValue } from 'n8n-workflow';

import { INodeUi, IUpdateInformation } from '@/Interface';

Expand All @@ -126,8 +122,8 @@ import ImportParameter from '@/components/ImportParameter.vue';
import { get, set } from 'lodash';

import mixins from 'vue-typed-mixins';
import { Component } from 'vue';
import { mapState, mapStores } from 'pinia';
import { Component, PropType } from 'vue';
import { mapStores } from 'pinia';
import { useNDVStore } from '@/stores/ndv';
import { useNodeTypesStore } from '@/stores/nodeTypes';

Expand All @@ -140,14 +136,36 @@ export default mixins(workflowHelpers).extend({
CollectionParameter: () => import('./CollectionParameter.vue') as Promise<Component>,
ImportParameter,
},
props: [
'nodeValues', // INodeParameters
'parameters', // INodeProperties
'path', // string
'hideDelete', // boolean
'indent',
'isReadOnly',
],
props: {
OlegIvaniv marked this conversation as resolved.
Show resolved Hide resolved
nodeValues: {
type: Object as PropType<INodeParameters>,
required: true,
},
parameters: {
type: Array as PropType<INodeProperties[]>,
required: true,
},
path: {
type: String,
default: '',
},
hideDelete: {
type: Boolean,
default: false,
},
indent: {
type: Boolean,
default: false,
},
isReadOnly: {
type: Boolean,
default: false,
},
hiddenIssuesInputs: {
type: Array as PropType<string[]>,
default: () => [],
},
},
computed: {
...mapStores(useNodeTypesStore, useNDVStore),
nodeTypeVersion(): number | null {
Expand Down Expand Up @@ -187,6 +205,9 @@ export default mixins(workflowHelpers).extend({
},
},
methods: {
onParameterBlur(parameterName: string) {
this.$emit('parameterBlur', parameterName);
},
getCredentialsDependencies() {
const dependencies = new Set();
const nodeType = this.nodeTypesStore.getNodeType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ export default mixins(debounceHelper, workflowHelpers, nodeHelpers).extend({
if (!this.isSearchable || this.currentQueryError) {
this.showResourceDropdown = false;
}
this.$emit('blur');
},
},
});
Expand Down
Loading