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): Update templates links #9024

Merged
merged 5 commits into from
Apr 3, 2024
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
3 changes: 2 additions & 1 deletion packages/editor-ui/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,8 @@ export type IPersonalizationLatestVersion = IPersonalizationSurveyAnswersV4;
export type IPersonalizationSurveyVersions =
| IPersonalizationSurveyAnswersV1
| IPersonalizationSurveyAnswersV2
| IPersonalizationSurveyAnswersV3;
| IPersonalizationSurveyAnswersV3
| IPersonalizationSurveyAnswersV4;

export type Roles = typeof ROLE;
export type IRole = Roles[keyof Roles];
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/components/MainSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export default defineComponent({
available:
this.settingsStore.isTemplatesEnabled && !this.templatesStore.hasCustomTemplatesHost,
link: {
href: this.templatesStore.getWebsiteTemplateRepositoryURL,
href: this.templatesStore.websiteTemplateRepositoryURL,
target: '_blank',
},
},
Expand Down
2 changes: 2 additions & 0 deletions packages/editor-ui/src/plugins/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import {
faHandHoldingUsd,
faHandScissors,
faHandPointLeft,
faHandshake,
faHashtag,
faHdd,
faHistory,
Expand Down Expand Up @@ -240,6 +241,7 @@ export const FontAwesomePlugin: Plugin<{}> = {
addIcon(faGraduationCap);
addIcon(faHandHoldingUsd);
addIcon(faHandScissors);
addIcon(faHandshake);
addIcon(faHandPointLeft);
addIcon(faHashtag);
addIcon(faHdd);
Expand Down
2 changes: 1 addition & 1 deletion packages/editor-ui/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export const routes = [
beforeEnter: (_to, _from, next) => {
const templatesStore = useTemplatesStore();
if (!templatesStore.hasCustomTemplatesHost) {
window.location.href = templatesStore.getWebsiteTemplateRepositoryURL;
window.location.href = templatesStore.websiteTemplateRepositoryURL;
} else {
next();
}
Expand Down
25 changes: 8 additions & 17 deletions packages/editor-ui/src/stores/templates.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const useTemplatesStore = defineStore(STORES.TEMPLATES, {
* Constructs URLSearchParams object based on the default parameters for the template repository
* and provided additional parameters
*/
getWebsiteTemplateRepositoryParameters() {
websiteTemplateRepositoryParameters() {
const rootStore = useRootStore();
const userStore = useUsersStore();
const workflowsStore = useWorkflowsStore();
Expand All @@ -131,8 +131,10 @@ export const useTemplatesStore = defineStore(STORES.TEMPLATES, {
utm_n8n_version: rootStore.versionCli,
utm_awc: String(workflowsStore.activeWorkflows.length),
};
if (userStore.currentUserCloudInfo?.role) {
defaultParameters.utm_user_role = userStore.currentUserCloudInfo.role;
const userRole: string | undefined =
userStore.currentUserCloudInfo?.role ?? userStore.currentUser?.personalizationAnswers?.role;
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the values the same in both cases? Should we normalize them here or prepare for both value in the templates site?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, they are not connected in any way and the website has a setting to map different survey roles to template category

if (userRole) {
defaultParameters.utm_user_role = userRole;
}
return (additionalParameters: Record<string, string> = {}) => {
return new URLSearchParams({
Expand All @@ -145,28 +147,17 @@ export const useTemplatesStore = defineStore(STORES.TEMPLATES, {
* Construct the URL for the template repository on the website
* @returns {string}
*/
getWebsiteTemplateRepositoryURL(): string {
websiteTemplateRepositoryURL(): string {
return `${
TEMPLATES_URLS.BASE_WEBSITE_URL
}?${this.getWebsiteTemplateRepositoryParameters().toString()}`;
},
/**
* Construct the URL for the template page on the website for a given template id
* @returns {function(string): string}
*/
getWebsiteTemplatePageURL() {
return (id: string) => {
return `${
TEMPLATES_URLS.BASE_WEBSITE_URL
}/${id}?${this.getWebsiteTemplateRepositoryParameters().toString()}`;
};
}?${this.websiteTemplateRepositoryParameters().toString()}`;
},
/**
* Construct the URL for the template category page on the website for a given category id
*/
getWebsiteCategoryURL() {
return (id: string) => {
return `${TEMPLATES_URLS.BASE_WEBSITE_URL}/?${this.getWebsiteTemplateRepositoryParameters({
return `${TEMPLATES_URLS.BASE_WEBSITE_URL}/?${this.websiteTemplateRepositoryParameters({
categories: id,
}).toString()}`;
};
Expand Down
20 changes: 13 additions & 7 deletions packages/editor-ui/src/views/WorkflowsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
</div>
<div v-if="!readOnlyEnv" :class="['text-center', 'mt-2xl', $style.actionsContainer]">
<a
v-if="userCloudAccount?.role === 'Sales'"
:href="getTemplateRepositoryURL('Sales')"
v-if="isSalesUser"
:href="getTemplateRepositoryURL()"
:class="$style.emptyStateCard"
target="_blank"
>
Expand All @@ -95,7 +95,7 @@
data-test-id="browse-sales-templates-card"
@click="trackCategoryLinkClick('Sales')"
>
<n8n-icon :class="$style.emptyStateCardIcon" icon="hand-holding-usd" />
<n8n-icon :class="$style.emptyStateCardIcon" icon="handshake" />
<n8n-text size="large" class="mt-xs" color="text-base">
{{
$locale.baseText('workflows.empty.browseTemplates', {
Expand Down Expand Up @@ -261,8 +261,14 @@ const WorkflowsView = defineComponent({
suggestedTemplates() {
return this.uiStore.suggestedTemplates;
},
userCloudAccount() {
return this.usersStore.currentUserCloudInfo;
userRole() {
const userRole: string | undefined =
this.usersStore.currentUserCloudInfo?.role ??
this.usersStore.currentUser?.personalizationAnswers?.role;
return userRole;
},
isSalesUser() {
return ['Sales', 'sales-and-marketing'].includes(this.userRole);
},
},
watch: {
Expand Down Expand Up @@ -299,8 +305,8 @@ const WorkflowsView = defineComponent({
source: 'Workflows list',
});
},
getTemplateRepositoryURL(category: string) {
return this.templatesStore.getWebsiteCategoryURL(category);
getTemplateRepositoryURL() {
return this.templatesStore.websiteTemplateRepositoryURL;
},
trackCategoryLinkClick(category: string) {
this.$telemetry.track(`User clicked Browse ${category} Templates`, {
Expand Down
Loading