mirror of
https://github.com/n8n-io/n8n.git
synced 2026-12-04 16:51:08 +00:00
feat(editor): Open template credential setup from collection (#7882)
Open the template credential setup when using a template from the
collection view.
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/46ccec7c-5a44-429e-99ad-1c10640e99e5
This commit is contained in:
1 parent
67702c2485
commit
627ddb91fb
8 files changed
+132
-48
No files matched your search
@@ -1,4 +1,9 @@
|
||||
import { CredentialsModal, MessageBox } from '../pages/modals';
|
||||
import {
|
||||
clickUseWorkflowButtonByTitle,
|
||||
visitTemplateCollectionPage,
|
||||
testData,
|
||||
} from '../pages/template-collection';
|
||||
import { TemplateCredentialSetupPage } from '../pages/template-credential-setup';
|
||||
import { TemplateWorkflowPage } from '../pages/template-workflow';
|
||||
import { WorkflowPage } from '../pages/workflow';
|
||||
@@ -28,6 +33,16 @@ describe('Template credentials setup', () => {
|
||||
.should('be.visible');
|
||||
});
|
||||
|
||||
it('can be opened from template collection page', () => {
|
||||
visitTemplateCollectionPage(testData.ecommerceStarterPack);
|
||||
templateCredentialsSetupPage.actions.enableFeatureFlag();
|
||||
clickUseWorkflowButtonByTitle('Promote new Shopify products on Twitter and Telegram');
|
||||
|
||||
templateCredentialsSetupPage.getters
|
||||
.title(`Setup 'Promote new Shopify products on Twitter and Telegram' template`)
|
||||
.should('be.visible');
|
||||
});
|
||||
|
||||
it('can be opened with a direct url', () => {
|
||||
templateCredentialsSetupPage.actions.visit(testTemplate.id);
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{"collection":{"id":1,"name":"eCommerce Starter Pack","description":"eCommerce operations are complex — but there are many things that you can automate to make your life easier. This collection provides a few ideas to get started.\n\nReduce manual work and the risk of human error by automating processes such as social media promotion of products, updating customer databases, and get notifications for important events.","totalViews":0,"createdAt":"2022-02-17T12:40:50.498Z","nodes":[{"id":20,"name":"n8n-nodes-base.if","defaults":{"name":"IF","color":"#408000"},"displayName":"IF","icon":"fa:map-signs","iconData":{"icon":"map-signs","type":"icon"},"typeVersion":1,"categories":[{"id":9,"name":"Core Nodes"}]},{"id":49,"name":"n8n-nodes-base.telegram","defaults":{"name":"Telegram"},"displayName":"Telegram","icon":"file:telegram.svg","iconData":{"type":"file","fileBuffer":"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgNjYgNjYiIGZpbGw9IiNmZmYiIGZpbGwtcnVsZT0iZXZlbm9kZCIgc3Ryb2tlPSIjMDAwIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiPjx1c2UgeGxpbms6aHJlZj0iI2EiIHg9Ii41IiB5PSIuNSIvPjxzeW1ib2wgaWQ9ImEiIG92ZXJmbG93PSJ2aXNpYmxlIj48ZyBzdHJva2U9Im5vbmUiIGZpbGwtcnVsZT0ibm9uemVybyI+PHBhdGggZD0iTTAgMzJjMCAxNy42NzMgMTQuMzI3IDMyIDMyIDMyczMyLTE0LjMyNyAzMi0zMlM0OS42NzMgMCAzMiAwIDAgMTQuMzI3IDAgMzIiIGZpbGw9IiMzN2FlZTIiLz48cGF0aCBkPSJNMjEuNjYxIDM0LjMzOGwzLjc5NyAxMC41MDhzLjQ3NS45ODMuOTgzLjk4MyA4LjA2OC03Ljg2NCA4LjA2OC03Ljg2NGw4LjQwNy0xNi4yMzctMjEuMTE5IDkuODk4eiIgZmlsbD0iI2M4ZGFlYSIvPjxwYXRoIGQ9Ik0yNi42OTUgMzcuMDM0bC0uNzI5IDcuNzQ2cy0uMzA1IDIuMzczIDIuMDY4IDBsNC42NDQtNC4yMDMiIGZpbGw9IiNhOWM2ZDgiLz48cGF0aCBkPSJNMjEuNzMgMzQuNzEybC03LjgwOS0yLjU0NXMtLjkzMi0uMzc4LS42MzMtMS4yMzdjLjA2Mi0uMTc3LjE4Ni0uMzI4LjU1OS0uNTg4IDEuNzMxLTEuMjA2IDMyLjAyOC0xMi4wOTYgMzIuMDI4LTEyLjA5NnMuODU2LS4yODggMS4zNjEtLjA5N2MuMjMxLjA4OC4zNzguMTg3LjUwMy41NDguMDQ1LjEzMi4wNzEuNDExLjA2OC42ODktLjAwMy4yMDEtLjAyNy4zODYtLjA0NS42NzgtLjE4NCAyLjk3OC01LjcwNiAyNS4xOTgtNS43MDYgMjUuMTk4cy0uMzMgMS4zLTEuNTE0IDEuMzQ1Yy0uNDMyLjAxNi0uOTU2LS4wNzEtMS41ODItLjYxLTIuMzIzLTEuOTk4LTEwLjM1Mi03LjM5NC0xMi4xMjYtOC41OGEuMzQuMzQgMCAwMS0uMTQ2LS4yMzljLS4wMjUtLjEyNS4xMDgtLjI4LjEwOC0uMjhzMTMuOTgtMTIuNDI3IDE0LjM1Mi0xMy43MzFjLjAyOS0uMTAxLS4wNzktLjE1MS0uMjI2LS4xMDctLjkyOS4zNDItMTcuMDI1IDEwLjUwNi0xOC44MDEgMTEuNjI5LS4xMDQuMDY2LS4zOTUuMDIzLS4zOTUuMDIzIi8+PC9nPjwvc3ltYm9sPjwvc3ZnPg=="},"typeVersion":1,"categories":[{"id":6,"name":"Communication"}]},{"id":107,"name":"n8n-nodes-base.shopifyTrigger","defaults":{"name":"Shopify Trigger"},"displayName":"Shopify Trigger","icon":"file:shopify.svg","iconData":{"type":"file","fileBuffer":"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgNTggNjYiIGZpbGw9IiNmZmYiIGZpbGwtcnVsZT0iZXZlbm9kZCIgc3Ryb2tlPSIjMDAwIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0ic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IDI1LjkxIDIuMjZ6IiBmaWxsPSIjOTViZjQ3Ii8+PHBhdGggZD0iTTQ4LjY5MSAxMS45NTdjLS4yMjUtLjAzNy01LjE3LS4zNzYtNS4xNy0uMzc2bC0zLjc3LTMuNzdhLjc1My43NTMgMCAwMC0uNTI3LS4yMjVMMzYuNDcyIDY0bDE5Ljc2My00LjI2LTYuOTgtNDcuMjE4YS42OC42OCAwIDAwLS41NjQtLjU2NHoiIGZpbGw9IiM1ZThlM2UiLz48cGF0aCBkPSJNMjkuNzU4IDIyLjlsLTIuNDU0IDcuMjQyYTExLjM2IDExLjM2IDAgMDAtNC43NTItMS4xMzNjLTMuODQ4IDAtNC4wMzYgMi40MTItNC4wMzYgMy4wMTggMCAzLjI5OCA4LjYzNiA0LjU2NCA4LjYzNiAxMi4zMzMgMCA2LjEtMy44ODUgMTAuMDMtOS4xIDEwLjAzLTYuMjYgMC05LjQ2Ny0zLjg4NS05LjQ2Ny0zLjg4NWwxLjY2NS01LjU1czMuMjggMi44MyA2LjA3MyAyLjgzYTIuNDcgMi40NyAwIDAwMi41NjQtMi40OWMwLTQuMzQtNy4xLTQuNTI3LTcuMS0xMS42MTggMC01Ljk2MiA0LjI5OC0xMS43NyAxMi45MzQtMTEuNzcgMy4zOTQuMDUgNS4wMTggMSA1LjAxOCAxeiIvPjwvZz48L3N5bWJvbD48L3N2Zz4="},"typeVersion":1,"categories":[{"id":2,"name":"Sales"}]},{"id":126,"name":"n8n-nodes-base.mautic","defaults":{"name":"Mautic"},"displayName":"Mautic","icon":"file:mautic.svg","iconData":{"type":"file","fileBuffer":"data:image/svg+xml;base64,PD94bWwgLine truncated
|
||||
@@ -0,0 +1,33 @@
|
||||
export function visitTemplateCollectionPage(withFixture: Fixture) {
|
||||
cy.intercept(
|
||||
'GET',
|
||||
`https://api.n8n.io/api/templates/collections/${testData.ecommerceStarterPack.id}`,
|
||||
{
|
||||
fixture: withFixture.fixture,
|
||||
},
|
||||
).as('getTemplateCollection');
|
||||
|
||||
cy.visit(`/collections/${withFixture.id}`);
|
||||
|
||||
cy.wait('@getTemplateCollection');
|
||||
}
|
||||
|
||||
export function clickUseWorkflowButtonByTitle(workflowTitle: string) {
|
||||
cy.getByTestId('template-card')
|
||||
.contains('[data-test-id=template-card]', workflowTitle)
|
||||
.realHover({ position: 'center' })
|
||||
.findChildByTestId('use-workflow-button')
|
||||
.click({ force: true });
|
||||
}
|
||||
|
||||
export type Fixture = {
|
||||
id: number;
|
||||
fixture: string;
|
||||
};
|
||||
|
||||
export const testData = {
|
||||
ecommerceStarterPack: {
|
||||
id: 1,
|
||||
fixture: 'Ecommerce_starter_pack_template_collection.json',
|
||||
},
|
||||
};
|
||||
@@ -7,6 +7,7 @@
|
||||
!loading && $style.loaded,
|
||||
]"
|
||||
@click="onCardClick"
|
||||
data-test-id="template-card"
|
||||
>
|
||||
<div :class="$style.loading" v-if="loading">
|
||||
<n8n-loading :rows="2" :shrinkLast="false" :loading="loading" />
|
||||
@@ -39,6 +40,7 @@
|
||||
outline
|
||||
label="Use workflow"
|
||||
@click.stop="onUseWorkflowClick"
|
||||
data-test-id="use-workflow-button"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -220,9 +220,7 @@ export const useTemplatesStore = defineStore(STORES.TEMPLATES, {
|
||||
this.currentSessionId = `templates-${Date.now()}`;
|
||||
}
|
||||
},
|
||||
async fetchTemplateById(
|
||||
templateId: string,
|
||||
): Promise<ITemplatesWorkflow | ITemplatesWorkflowFull> {
|
||||
async fetchTemplateById(templateId: string): Promise<ITemplatesWorkflowFull> {
|
||||
const settingsStore = useSettingsStore();
|
||||
const apiEndpoint: string = settingsStore.templatesHost;
|
||||
const versionCli: string = settingsStore.versionCli;
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import type { INodeUi, IWorkflowData, IWorkflowTemplate } from '@/Interface';
|
||||
import { getNewWorkflow } from '@/api/workflows';
|
||||
import { VIEWS } from '@/constants';
|
||||
import type { useRootStore } from '@/stores/n8nRoot.store';
|
||||
import type { useWorkflowsStore } from '@/stores/workflows.store';
|
||||
import { FeatureFlag, isFeatureFlagEnabled } from '@/utils/featureFlag';
|
||||
import { getFixedNodesList } from '@/utils/nodeViewUtils';
|
||||
import { replaceAllTemplateNodeCredentials } from '@/utils/templates/templateTransforms';
|
||||
import type { INodeCredentialsDetails } from 'n8n-workflow';
|
||||
import type { RouteLocationRaw, Router } from 'vue-router';
|
||||
|
||||
/**
|
||||
* Creates a new workflow from a template
|
||||
@@ -35,3 +38,32 @@ export async function createWorkflowFromTemplate(
|
||||
|
||||
return createdWorkflow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the template credential setup view (or workflow view
|
||||
* if the feature flag is disabled)
|
||||
*/
|
||||
export async function openTemplateCredentialSetup(opts: {
|
||||
templateId: string;
|
||||
router: Router;
|
||||
inNewBrowserTab?: boolean;
|
||||
}) {
|
||||
const { router, templateId, inNewBrowserTab = false } = opts;
|
||||
|
||||
const routeLocation: RouteLocationRaw = isFeatureFlagEnabled(FeatureFlag.templateCredentialsSetup)
|
||||
? {
|
||||
name: VIEWS.TEMPLATE_SETUP,
|
||||
params: { id: templateId },
|
||||
}
|
||||
: {
|
||||
name: VIEWS.TEMPLATE_IMPORT,
|
||||
params: { id: templateId },
|
||||
};
|
||||
|
||||
if (inNewBrowserTab) {
|
||||
const route = router.resolve(routeLocation);
|
||||
window.open(route.href, '_blank');
|
||||
} else {
|
||||
await router.push(routeLocation);
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,8 @@ import { setPageTitle } from '@/utils/htmlUtils';
|
||||
import { VIEWS } from '@/constants';
|
||||
import { useTemplatesStore } from '@/stores/templates.store';
|
||||
import { usePostHog } from '@/stores/posthog.store';
|
||||
import { FeatureFlag, isFeatureFlagEnabled } from '@/utils/featureFlag';
|
||||
import { openTemplateCredentialSetup } from '@/utils/templates/templateActions';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'TemplatesCollectionView',
|
||||
@@ -80,11 +82,13 @@ export default defineComponent({
|
||||
},
|
||||
computed: {
|
||||
...mapStores(useTemplatesStore, usePostHog),
|
||||
collection(): null | ITemplatesCollectionFull {
|
||||
collection(): ITemplatesCollectionFull | null {
|
||||
return this.templatesStore.getCollectionById(this.collectionId);
|
||||
},
|
||||
collectionId(): string {
|
||||
return this.$route.params.id;
|
||||
return Array.isArray(this.$route.params.id)
|
||||
? this.$route.params.id[0]
|
||||
: this.$route.params.id;
|
||||
},
|
||||
collectionWorkflows(): Array<ITemplatesWorkflow | ITemplatesWorkflowFull | null> | null {
|
||||
if (!this.collection) {
|
||||
@@ -116,17 +120,24 @@ export default defineComponent({
|
||||
onOpenTemplate({ event, id }: { event: MouseEvent; id: string }) {
|
||||
this.navigateTo(event, VIEWS.TEMPLATE, id);
|
||||
},
|
||||
onUseWorkflow({ event, id }: { event: MouseEvent; id: string }) {
|
||||
const telemetryPayload = {
|
||||
template_id: id,
|
||||
wf_template_repo_session_id: this.workflowsStore.currentSessionId,
|
||||
source: 'collection',
|
||||
};
|
||||
void this.$externalHooks().run('templatesCollectionView.onUseWorkflow', telemetryPayload);
|
||||
this.$telemetry.track('User inserted workflow template', telemetryPayload, {
|
||||
withPostHog: true,
|
||||
async onUseWorkflow({ event, id }: { event: MouseEvent; id: string }) {
|
||||
if (!isFeatureFlagEnabled(FeatureFlag.templateCredentialsSetup)) {
|
||||
const telemetryPayload = {
|
||||
template_id: id,
|
||||
wf_template_repo_session_id: this.templatesStore.currentSessionId,
|
||||
source: 'collection',
|
||||
};
|
||||
await this.$externalHooks().run('templatesCollectionView.onUseWorkflow', telemetryPayload);
|
||||
this.$telemetry.track('User inserted workflow template', telemetryPayload, {
|
||||
withPostHog: true,
|
||||
});
|
||||
}
|
||||
|
||||
await openTemplateCredentialSetup({
|
||||
router: this.$router,
|
||||
templateId: id,
|
||||
inNewBrowserTab: event.metaKey || event.ctrlKey,
|
||||
});
|
||||
this.navigateTo(event, VIEWS.TEMPLATE_IMPORT, id);
|
||||
},
|
||||
navigateTo(e: MouseEvent, page: string, id: string) {
|
||||
if (e.metaKey || e.ctrlKey) {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
data-test-id="use-template-button"
|
||||
:label="$locale.baseText('template.buttons.useThisWorkflowButton')"
|
||||
size="large"
|
||||
@click="openTemplateSetup(template.id, $event)"
|
||||
@click="openTemplateSetup(templateId, $event)"
|
||||
/>
|
||||
<n8n-loading :loading="!template" :rows="1" variant="button" />
|
||||
</div>
|
||||
@@ -63,12 +63,12 @@ import TemplateDetails from '@/components/TemplateDetails.vue';
|
||||
import TemplatesView from './TemplatesView.vue';
|
||||
import WorkflowPreview from '@/components/WorkflowPreview.vue';
|
||||
|
||||
import type { ITemplatesWorkflow, ITemplatesWorkflowFull } from '@/Interface';
|
||||
import type { ITemplatesWorkflowFull } from '@/Interface';
|
||||
import { workflowHelpers } from '@/mixins/workflowHelpers';
|
||||
import { setPageTitle } from '@/utils/htmlUtils';
|
||||
import { VIEWS } from '@/constants';
|
||||
import { useTemplatesStore } from '@/stores/templates.store';
|
||||
import { usePostHog } from '@/stores/posthog.store';
|
||||
import { openTemplateCredentialSetup } from '@/utils/templates/templateActions';
|
||||
import { FeatureFlag, isFeatureFlagEnabled } from '@/utils/featureFlag';
|
||||
|
||||
export default defineComponent({
|
||||
@@ -81,11 +81,13 @@ export default defineComponent({
|
||||
},
|
||||
computed: {
|
||||
...mapStores(useTemplatesStore, usePostHog),
|
||||
template(): ITemplatesWorkflow | ITemplatesWorkflowFull {
|
||||
return this.templatesStore.getTemplateById(this.templateId);
|
||||
template(): ITemplatesWorkflowFull | null {
|
||||
return this.templatesStore.getFullTemplateById(this.templateId);
|
||||
},
|
||||
templateId() {
|
||||
return this.$route.params.id;
|
||||
return Array.isArray(this.$route.params.id)
|
||||
? this.$route.params.id[0]
|
||||
: this.$route.params.id;
|
||||
},
|
||||
},
|
||||
data() {
|
||||
@@ -96,35 +98,25 @@ export default defineComponent({
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
openTemplateSetup(id: string, e: PointerEvent) {
|
||||
const telemetryPayload = {
|
||||
source: 'workflow',
|
||||
template_id: id,
|
||||
wf_template_repo_session_id: this.templatesStore.currentSessionId,
|
||||
};
|
||||
async openTemplateSetup(id: string, e: PointerEvent) {
|
||||
if (!isFeatureFlagEnabled(FeatureFlag.templateCredentialsSetup)) {
|
||||
const telemetryPayload = {
|
||||
source: 'workflow',
|
||||
template_id: id,
|
||||
wf_template_repo_session_id: this.templatesStore.currentSessionId,
|
||||
};
|
||||
|
||||
void this.$externalHooks().run('templatesWorkflowView.openWorkflow', telemetryPayload);
|
||||
this.$telemetry.track('User inserted workflow template', telemetryPayload, {
|
||||
withPostHog: true,
|
||||
});
|
||||
|
||||
if (isFeatureFlagEnabled(FeatureFlag.templateCredentialsSetup)) {
|
||||
if (e.metaKey || e.ctrlKey) {
|
||||
const route = this.$router.resolve({ name: VIEWS.TEMPLATE_SETUP, params: { id } });
|
||||
window.open(route.href, '_blank');
|
||||
return;
|
||||
} else {
|
||||
void this.$router.push({ name: VIEWS.TEMPLATE_SETUP, params: { id } });
|
||||
}
|
||||
} else {
|
||||
if (e.metaKey || e.ctrlKey) {
|
||||
const route = this.$router.resolve({ name: VIEWS.TEMPLATE_IMPORT, params: { id } });
|
||||
window.open(route.href, '_blank');
|
||||
return;
|
||||
} else {
|
||||
void this.$router.push({ name: VIEWS.TEMPLATE_IMPORT, params: { id } });
|
||||
}
|
||||
this.$telemetry.track('User inserted workflow template', telemetryPayload, {
|
||||
withPostHog: true,
|
||||
});
|
||||
await this.$externalHooks().run('templatesWorkflowView.openWorkflow', telemetryPayload);
|
||||
}
|
||||
|
||||
await openTemplateCredentialSetup({
|
||||
router: this.$router,
|
||||
templateId: id,
|
||||
inNewBrowserTab: e.metaKey || e.ctrlKey,
|
||||
});
|
||||
},
|
||||
onHidePreview() {
|
||||
this.showPreview = false;
|
||||
|
||||
Reference in new issue
Block a user