feat(editor): Select credentials in template setup if theres only one (#7879)
Automatically select credentials in the template credential setup if
there's only one available.
NOTE! This feature is still behind a feature flag. To test, set:
```js
localStorage.setItem('template-credentials-setup', 'true')
```
https://github.com/n8n-io/n8n/assets/10324676/edc1f586-214f-4c37-b7ec-dd1786433dc1
This commit is contained in:
@@ -232,6 +232,34 @@ export const useSetupTemplateStore = defineStore('setupTemplate', () => {
|
||||
templateId.value = id;
|
||||
};
|
||||
|
||||
const ignoredAutoFillCredentialTypes = new Set([
|
||||
'httpBasicAuth',
|
||||
'httpCustomAuth',
|
||||
'httpDigestAuth',
|
||||
'httpHeaderAuth',
|
||||
'oAuth1Api',
|
||||
'oAuth2Api',
|
||||
'httpQueryAuth',
|
||||
]);
|
||||
|
||||
/**
|
||||
* Selects initial credentials for the template. Credentials
|
||||
* need to be loaded before this.
|
||||
*/
|
||||
const setInitialCredentialSelection = () => {
|
||||
for (const credUsage of credentialUsages.value) {
|
||||
if (ignoredAutoFillCredentialTypes.has(credUsage.credentialType)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const availableCreds = credentialsStore.getCredentialsByType(credUsage.credentialType);
|
||||
|
||||
if (availableCreds.length === 1) {
|
||||
selectedCredentialIdByName.value[credUsage.credentialName] = availableCreds[0].id;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Loads the template if it hasn't been loaded yet.
|
||||
*/
|
||||
@@ -241,6 +269,8 @@ export const useSetupTemplateStore = defineStore('setupTemplate', () => {
|
||||
}
|
||||
|
||||
await templatesStore.fetchTemplateById(templateId.value);
|
||||
|
||||
setInitialCredentialSelection();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -257,6 +287,8 @@ export const useSetupTemplateStore = defineStore('setupTemplate', () => {
|
||||
nodeTypesStore.loadNodeTypesIfNotLoaded(),
|
||||
loadTemplateIfNeeded(),
|
||||
]);
|
||||
|
||||
setInitialCredentialSelection();
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
@@ -341,6 +373,7 @@ export const useSetupTemplateStore = defineStore('setupTemplate', () => {
|
||||
skipSetup,
|
||||
init,
|
||||
loadTemplateIfNeeded,
|
||||
setInitialCredentialSelection,
|
||||
setTemplateId,
|
||||
setSelectedCredentialId,
|
||||
unsetSelectedCredential,
|
||||
|
||||
Reference in New Issue
Block a user