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): Show error in RLC if credentials are not set #6108

Merged
merged 1 commit into from
Apr 27, 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
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
<n8n-text color="text-dark" align="center" tag="div">
{{ $locale.baseText('resourceLocator.mode.list.error.title') }}
</n8n-text>
<n8n-text size="small" color="text-base" v-if="hasCredential">
<n8n-text size="small" color="text-base" v-if="hasCredential || credentialsNotSet">
{{ $locale.baseText('resourceLocator.mode.list.error.description.part1') }}
<a @click="openCredential">{{
$locale.baseText('resourceLocator.mode.list.error.description.part2')
<a v-if="credentialsNotSet" @click="createNewCredential">{{
$locale.baseText('resourceLocator.mode.list.error.description.part2.noCredentials')
}}</a>
<a v-else-if="hasCredential" @click="openCredential">{{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to not repeat template parts you could use the condition inside a common click handler, even inline

Suggested change
<a v-else-if="hasCredential" @click="openCredential">{{
<a @click="() => hasCredential ? openCredential() : createNewCredential()">{{

Actually this doesn't look much nicer but at least fewer lines. I leave it up to you

$locale.baseText('resourceLocator.mode.list.error.description.part2.hasCredentials')
}}</a>
</n8n-text>
</div>
Expand Down Expand Up @@ -157,7 +160,12 @@ import { debounceHelper } from '@/mixins/debounce';
import stringify from 'fast-json-stable-stringify';
import { workflowHelpers } from '@/mixins/workflowHelpers';
import { nodeHelpers } from '@/mixins/nodeHelpers';
import { getAppNameFromNodeName, isResourceLocatorValue, hasOnlyListMode } from '@/utils';
import {
getAppNameFromNodeName,
isResourceLocatorValue,
hasOnlyListMode,
getMainAuthField,
} from '@/utils';
import { mapStores } from 'pinia';
import { useUIStore } from '@/stores/ui';
import { useWorkflowsStore } from '@/stores/workflows';
Expand Down Expand Up @@ -282,6 +290,17 @@ export default mixins(debounceHelper, workflowHelpers, nodeHelpers).extend({
}
return !!(node && node.credentials && Object.keys(node.credentials).length === 1);
},
credentialsNotSet(): boolean {
const nodeType = this.nodeTypesStore.getNodeType(this.node?.type);
if (nodeType) {
const usesCredentials =
nodeType.credentials !== undefined && nodeType.credentials.length > 0;
if (usesCredentials && !this.node?.credentials) {
return true;
}
}
return false;
},
inputPlaceholder(): string {
if (this.currentMode.placeholder) {
return this.currentMode.placeholder;
Expand Down Expand Up @@ -503,6 +522,18 @@ export default mixins(debounceHelper, workflowHelpers, nodeHelpers).extend({
const id = node.credentials[credentialKey].id;
this.uiStore.openExistingCredential(id);
},
createNewCredential(): void {
const nodeType = this.nodeTypesStore.getNodeType(this.node?.type);
if (!nodeType) {
return;
}
const mainAuthType = getMainAuthField(nodeType);
const showAuthSelector =
mainAuthType !== null &&
Array.isArray(mainAuthType.options) &&
mainAuthType.options?.length > 0;
this.uiStore.openNewCredential('', showAuthSelector);
},
findModeByName(name: string): INodePropertyMode | null {
if (this.parameter.modes) {
return this.parameter.modes.find((mode: INodePropertyMode) => mode.name === name) || null;
Expand Down
3 changes: 2 additions & 1 deletion packages/editor-ui/src/plugins/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,8 @@
"resourceLocator.mode.list.disabled.title": "Change to Fixed mode to choose From List",
"resourceLocator.mode.list.error.title": "Could not load list",
"resourceLocator.mode.list.error.description.part1": "Please",
"resourceLocator.mode.list.error.description.part2": "check your credential",
"resourceLocator.mode.list.error.description.part2.hasCredentials": "check your credential",
"resourceLocator.mode.list.error.description.part2.noCredentials": "add your credential",
"resourceLocator.mode.list.noResults": "No results",
"resourceLocator.mode.list.openUrl": "Open URL",
"resourceLocator.mode.list.placeholder": "Choose...",
Expand Down