Skip to content

Commit

Permalink
feat(editor): Update templates links (#9024)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiloradFilipovic authored and netroy committed Apr 3, 2024
1 parent aac77e1 commit 4619dec
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
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;
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

0 comments on commit 4619dec

Please sign in to comment.