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): Recommend and pre-select auth type with overrides #5684

Merged
merged 2 commits into from
Mar 17, 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
1 change: 1 addition & 0 deletions packages/editor-ui/src/plugins/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@
"credentialEdit.credentialConfig.missingCredentialType": "This credential's type isn't available. This usually happens when a previously installed community or custom node was uninstalled.",
"credentialEdit.credentialConfig.authTypeSelectorLabel": "Connect using",
"credentialEdit.credentialConfig.authTypeSelectorTooltip": "The authentication method to use for the connection",
"credentialEdit.credentialConfig.recommendedAuthTypeSuffix": "(recommended)",
"credentialEdit.credentialEdit.confirmMessage.beforeClose1.cancelButtonText": "Keep Editing",
"credentialEdit.credentialEdit.confirmMessage.beforeClose1.confirmButtonText": "Close",
"credentialEdit.credentialEdit.confirmMessage.beforeClose1.headline": "Close without saving?",
Expand Down
36 changes: 29 additions & 7 deletions packages/editor-ui/src/utils/nodeTypesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ import {
INodePropertyCollection,
} from 'n8n-workflow';
import { isResourceLocatorValue, isJsonKeyObject } from '@/utils';
import { useCredentialsStore } from '@/stores/credentials';
import { i18n as locale } from '@/plugins/i18n';
import { useSettingsStore } from '@/stores/settings';

/*
Constants and utility functions mainly used to get information about
Expand Down Expand Up @@ -381,6 +384,9 @@ export const getNodeAuthOptions = (
if (!nodeType) {
return [];
}
const recommendedSuffix = locale.baseText(
'credentialEdit.credentialConfig.recommendedAuthTypeSuffix',
);
let options: NodeAuthenticationOption[] = [];
const authProp = getMainAuthField(nodeType);
// Some nodes have multiple auth fields with same name but different display options so need
Expand All @@ -392,18 +398,34 @@ export const getNodeAuthOptions = (
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,
})) || [],
field.options.map((option) => {
// Check if credential type associated with this auth option has overwritten properties
let hasOverrides = false;
if (useSettingsStore().isCloudDeployment) {
const cred = getNodeCredentialForSelectedAuthType(nodeType, option.value);
if (cred) {
hasOverrides =
useCredentialsStore().getCredentialTypeByName(cred.name).__overwrittenProperties !==
undefined;
}
}
return {
name:
// Add recommended suffix if credentials have overrides and option is not already recommended
hasOverrides && !option.name.endsWith(recommendedSuffix)
? `${option.name} ${recommendedSuffix}`
: option.name,
value: option.value,
// Also add in the display options so we can hide/show the option if necessary
displayOptions: field.displayOptions,
};
}) || [],
);
}
});
// sort so recommended options are first
options.forEach((item, i) => {
if (item.name.includes('(recommended)')) {
if (item.name.includes(recommendedSuffix)) {
options.splice(i, 1);
options.unshift(item);
}
Expand Down