refactor(editor): Go to upgrade page (#5994)
* refactor(editor): Go to upgrade page * test(editor): add UI store upgrade link tests * fix(editor): update execution filter links * fix(editor): update unit test * fix(editor): update unit test * fix(editor): remove unused variables
This commit is contained in:
53
packages/editor-ui/src/stores/__tests__/ui.test.ts
Normal file
53
packages/editor-ui/src/stores/__tests__/ui.test.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { createPinia, setActivePinia } from 'pinia';
|
||||
import { useUIStore } from '@/stores/ui';
|
||||
import { useSettingsStore } from '@/stores/settings';
|
||||
import { merge } from 'lodash-es';
|
||||
import { SETTINGS_STORE_DEFAULT_STATE } from '@/__tests__/utils';
|
||||
|
||||
let uiStore: ReturnType<typeof useUIStore>;
|
||||
let settingsStore: ReturnType<typeof useSettingsStore>;
|
||||
|
||||
describe('UI store', () => {
|
||||
beforeEach(() => {
|
||||
setActivePinia(createPinia());
|
||||
uiStore = useUIStore();
|
||||
settingsStore = useSettingsStore();
|
||||
});
|
||||
|
||||
test.each([
|
||||
[
|
||||
'default',
|
||||
'production',
|
||||
'https://subscription.n8n.io?instanceid=123abc&version=0.223.0&source=test_source',
|
||||
],
|
||||
[
|
||||
'default',
|
||||
'development',
|
||||
'https://staging-subscription.n8n.io?instanceid=123abc&version=0.223.0&source=test_source',
|
||||
],
|
||||
[
|
||||
'desktop_win',
|
||||
'production',
|
||||
'https://n8n.io/pricing/?utm_source=n8n-internal&utm_medium=desktop&utm_campaign=utm-test-campaign',
|
||||
],
|
||||
['cloud', 'production', 'https://app.n8n.cloud/manage?edition=cloud'],
|
||||
])(
|
||||
'"upgradeLinkUrl" should generate the correct URL for "%s" deployment and "%s" license environment',
|
||||
(type, environment, expectation) => {
|
||||
settingsStore.setSettings(
|
||||
merge({}, SETTINGS_STORE_DEFAULT_STATE.settings, {
|
||||
deployment: {
|
||||
type,
|
||||
},
|
||||
license: {
|
||||
environment,
|
||||
},
|
||||
instanceId: '123abc',
|
||||
versionCli: '0.223.0',
|
||||
}),
|
||||
);
|
||||
|
||||
expect(uiStore.upgradeLinkUrl('test_source', 'utm-test-campaign')).toBe(expectation);
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -48,6 +48,8 @@ import { useRootStore } from './n8nRootStore';
|
||||
import { getCurlToJson } from '@/api/curlHelper';
|
||||
import { useWorkflowsStore } from './workflows';
|
||||
import { useSettingsStore } from './settings';
|
||||
import { useUsageStore } from './usage';
|
||||
import { i18n as locale, BaseTextKey } from '@/plugins/i18n';
|
||||
|
||||
export const useUIStore = defineStore(STORES.UI, {
|
||||
state: (): UIState => ({
|
||||
@@ -311,6 +313,22 @@ export const useUIStore = defineStore(STORES.UI, {
|
||||
return false;
|
||||
};
|
||||
},
|
||||
upgradeLinkUrl() {
|
||||
return (source: string, utm_campaign: string): string => {
|
||||
const usageStore = useUsageStore();
|
||||
const linkUrlTranslationKey = this.contextBasedTranslationKeys
|
||||
.upgradeLinkUrl as BaseTextKey;
|
||||
let linkUrl = locale.baseText(linkUrlTranslationKey);
|
||||
|
||||
if (linkUrlTranslationKey.endsWith('.upgradeLinkUrl')) {
|
||||
linkUrl = `${usageStore.viewPlansUrl}&source=${source}`;
|
||||
} else if (linkUrlTranslationKey.endsWith('.desktop')) {
|
||||
linkUrl = `${linkUrl}&utm_campaign=${utm_campaign || source}`;
|
||||
}
|
||||
|
||||
return linkUrl;
|
||||
};
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
setMode(name: string, mode: string): void {
|
||||
@@ -460,5 +478,8 @@ export const useUIStore = defineStore(STORES.UI, {
|
||||
const rootStore = useRootStore();
|
||||
return await getCurlToJson(rootStore.getRestApiContext, curlCommand);
|
||||
},
|
||||
goToUpgrade(source: string, utm_campaign: string): void {
|
||||
window.open(this.upgradeLinkUrl(source, utm_campaign), '_blank');
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user