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

fix(editor): Fix parameter reset on credential change in Discord node #9137

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion cypress/e2e/5-ndv.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { getVisibleSelect } from '../utils';
import { MANUAL_TRIGGER_NODE_DISPLAY_NAME } from '../constants';
import { NDV, WorkflowPage } from '../pages';
import { NodeCreator } from '../pages/features/node-creator';
import { clickCreateNewCredential } from '../composables/ndv';
import { setCredentialValues } from '../composables/modals/credential-modal';

const workflowPage = new WorkflowPage();
const ndv = new NDV();
Expand Down Expand Up @@ -633,7 +635,7 @@ describe('NDV', () => {
ndv.getters.nodeRunErrorIndicator().should('exist');
});

it('Should handle mismatched option attributes', () => {
it('Should clear mismatched collection parameters', () => {
workflowPage.actions.addInitialNodeToCanvas('LDAP', {
keepNdvOpen: true,
action: 'Create a new entry',
Expand All @@ -656,6 +658,21 @@ describe('NDV', () => {
ndv.getters.resourceLocatorInput('documentId').find('input').should('have.value', TEST_DOC_ID);
});

it('Should not clear resource/operation after credential change', () => {
workflowPage.actions.addInitialNodeToCanvas('Discord', {
keepNdvOpen: true,
action: 'Send a message',
});

clickCreateNewCredential();
setCredentialValues({
botToken: 'sk_test_123',
});

ndv.getters.parameterInput('resource').find('input').should('have.value', 'Message');
ndv.getters.parameterInput('operation').find('input').should('have.value', 'Send');
});

it('Should open appropriate node creator after clicking on connection hint link', () => {
const nodeCreator = new NodeCreator();
const hintMapper = {
Expand Down
28 changes: 22 additions & 6 deletions packages/editor-ui/src/components/NodeSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,14 @@ import type {
NodeParameterValue,
ConnectionTypes,
} from 'n8n-workflow';
import { NodeHelpers, NodeConnectionType, deepCopy } from 'n8n-workflow';
import {
NodeHelpers,
NodeConnectionType,
deepCopy,
isINodePropertyCollectionList,
isINodePropertiesList,
isINodePropertyOptionsList,
} from 'n8n-workflow';
import type {
INodeUi,
INodeUpdatePropertiesInformation,
Expand Down Expand Up @@ -997,13 +1004,22 @@ export default defineComponent({
return;
}
// Every value should be a possible option
const hasValidOptions = Object.keys(nodeParameterValues).every(
(key) => (prop.options ?? []).find((option) => option.name === key) !== undefined,
);
let hasValidOptions = true;

if (isINodePropertyCollectionList(prop.options) || isINodePropertiesList(prop.options)) {
hasValidOptions = Object.keys(nodeParameterValues).every(
(key) => (prop.options ?? []).find((option) => option.name === key) !== undefined,
);
} else if (isINodePropertyOptionsList(prop.options)) {
hasValidOptions = !!prop.options.find(
(option) => option.value === nodeParameterValues[prop.name],
);
}

if (
!hasValidOptions ||
showCondition !== updatedParameter.value ||
hideCondition === updatedParameter.value
(showCondition && !showCondition.includes(updatedParameter.value)) ||
(hideCondition && hideCondition.includes(updatedParameter.value))
) {
unset(nodeParameterValues as object, prop.name);
}
Expand Down