From d994904b59b45d87050b93ced74b9ec0c6d6f4e6 Mon Sep 17 00:00:00 2001 From: Milorad Filipovic Date: Fri, 30 Dec 2022 16:59:27 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Fixing=20node=20auth=20options=20lo?= =?UTF-8?q?gic=20for=20multiple=20auth=20fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../editor-ui/src/utils/nodeTypesUtils.ts | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/packages/editor-ui/src/utils/nodeTypesUtils.ts b/packages/editor-ui/src/utils/nodeTypesUtils.ts index 746ae44fb83d5..f5ee0517bb681 100644 --- a/packages/editor-ui/src/utils/nodeTypesUtils.ts +++ b/packages/editor-ui/src/utils/nodeTypesUtils.ts @@ -317,16 +317,22 @@ export const getNodeAuthOptions = ( if (nodeType) { let options: NodeAuthenticationOption[] = []; const authProp = getMainAuthField(nodeType); - if (authProp && authProp.options) { - options = options.concat( - authProp.options.map((option) => ({ - name: option.name, - value: option.value, - // Also add in the display options so we can hide/show the option if necessary - displayOptions: authProp.displayOptions, - })) || [], - ); - } + // Some nodes have multiple auth fields with same name but different display options so need + // take them all into account + const authProps = getNodeAuthFields(nodeType).filter((prop) => prop.name === authProp?.name); + + authProps.forEach((field) => { + if (field.options) { + options = options.concat( + field.options.map((option) => ({ + name: option.name, + value: option.value, + // Also add in the display options so we can hide/show the option if necessary + displayOptions: field.displayOptions, + })) || [], + ); + } + }); return options; } return []; @@ -403,9 +409,13 @@ export const getNodeAuthFields = (nodeType: INodeTypeDescription | null): INodeP nodeType.credentials.forEach((cred) => { if (cred.displayOptions && cred.displayOptions.show) { Object.keys(cred.displayOptions.show).forEach((option) => { - const nodeFieldForName = nodeType.properties.find((prop) => prop.name === option); - if (nodeFieldForName && !authFields.find((f) => f.name === option)) { - authFields.push(nodeFieldForName); + const nodeFieldsForName = nodeType.properties.filter((prop) => prop.name === option); + if (nodeFieldsForName) { + nodeFieldsForName.forEach((nodeField) => { + if (!authFields.includes(nodeField)) { + authFields.push(nodeField); + } + }); } }); }