Skip to content

Commit

Permalink
⚡ Handling credential dropdown UI for multiple credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
MiloradFilipovic committed Jan 11, 2023
1 parent 18ed51a commit 0519fd3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/editor-ui/src/components/NodeCredentials.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:key="credentialTypeDescription.name"
>
<n8n-input-label
:label="getCredentialsFieldLabel(credentialTypeNames[credentialTypeDescription.name])"
:label="getCredentialsFieldLabel(credentialTypeDescription)"
:bold="false"
:set="(issues = getIssues(credentialTypeDescription.name))"
size="small"
Expand Down Expand Up @@ -109,7 +109,7 @@ import { useNodeTypesStore } from '@/stores/nodeTypes';
import { useCredentialsStore } from '@/stores/credentials';
import { useNDVStore } from '@/stores/ndv';
import { KEEP_AUTH_IN_NDV_FOR_NODES } from '@/constants';
import { getMainAuthField, getNodeCredentialForAuthType } from '@/utils';
import { getAuthTypeForNodeCredential, getCredentialsRelatedFields, getMainAuthField, getNodeCredentialForAuthType } from '@/utils';
interface CredentialDropdownOption extends ICredentialsResponse {
typeDisplayName: string;
Expand Down Expand Up @@ -495,11 +495,19 @@ export default mixins(genericHelpers, nodeHelpers, restApi, showMessage).extend(
});
this.subscribedToCredentialType = credentialType;
},
getCredentialsFieldLabel(credentialType: string): string {
if (KEEP_AUTH_IN_NDV_FOR_NODES.includes(this.node.type || '')) {
getCredentialsFieldLabel(credentialType: INodeCredentialDescription): string {
const credentialTypeName = this.credentialTypeNames[credentialType.name];
const nodeType = this.nodeTypesStore.getNodeType(this.node.type, this.node.typeVersion);
const mainAuthField = nodeType ? getMainAuthField(nodeType) : null;
const mainAuthFieldName = mainAuthField ? mainAuthField.name : '';
if (
KEEP_AUTH_IN_NDV_FOR_NODES.includes(this.node.type || '') ||
!(mainAuthFieldName in (credentialType.displayOptions?.show || {}))
) {
return this.$locale.baseText('nodeCredentials.credentialFor', {
interpolate: {
credentialType,
credentialType: credentialTypeName,
},
});
}
Expand Down
19 changes: 19 additions & 0 deletions packages/editor-ui/src/utils/nodeTypesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,3 +423,22 @@ export const getNodeAuthFields = (nodeType: INodeTypeDescription | null): INodeP
}
return authFields;
};

export const getCredentialsRelatedFields = (
nodeType: INodeTypeDescription | null,
credentialType: INodeCredentialDescription | null,
): INodeProperties[] => {
let fields: INodeProperties[] = [];
if (
nodeType &&
credentialType &&
credentialType.displayOptions &&
credentialType.displayOptions.show
) {
Object.keys(credentialType.displayOptions.show).forEach((option) => {
console.log(option);
fields = fields.concat(nodeType.properties.filter((prop) => prop.name === option));
});
}
return fields;
};

0 comments on commit 0519fd3

Please sign in to comment.