From 3cbe31dd5e5180ce000a74a3dea1d78c1ca64e63 Mon Sep 17 00:00:00 2001 From: Mutasem Date: Thu, 8 Jul 2021 09:58:54 +0200 Subject: [PATCH] set env variables --- packages/editor-ui/src/Interface.ts | 8 +++ packages/editor-ui/src/api/versions.ts | 5 +- .../editor-ui/src/components/UpdatesPanel.vue | 9 +--- packages/editor-ui/src/constants.ts | 4 -- packages/editor-ui/src/modules/versions.ts | 24 +++++++-- packages/editor-ui/src/views/NodeView.vue | 51 +++++++++++-------- 6 files changed, 62 insertions(+), 39 deletions(-) diff --git a/packages/editor-ui/src/Interface.ts b/packages/editor-ui/src/Interface.ts index 3a0790cf48..81008201a8 100644 --- a/packages/editor-ui/src/Interface.ts +++ b/packages/editor-ui/src/Interface.ts @@ -445,6 +445,12 @@ export interface IPushDataConsoleMessage { message: string; } +export interface IVersionNotificationSettings { + enabled: boolean; + endpoint: string; + infoUrl: string; +} + export interface IN8nUISettings { endpointWebhook: string; endpointWebhookTest: string; @@ -463,6 +469,7 @@ export interface IN8nUISettings { n8nMetadata?: { [key: string]: string | number | undefined; }; + versionNotifications: IVersionNotificationSettings; } export interface IWorkflowSettings extends IWorkflowSettingsWorkflow { @@ -635,6 +642,7 @@ export interface IUiState { } export interface IVersionsState { + versionNotificationSettings: IVersionNotificationSettings; nextVersions: IVersion[]; currentVersion: IVersion | undefined; } diff --git a/packages/editor-ui/src/api/versions.ts b/packages/editor-ui/src/api/versions.ts index 67e7f25a5b..a6a3bf0c57 100644 --- a/packages/editor-ui/src/api/versions.ts +++ b/packages/editor-ui/src/api/versions.ts @@ -1,7 +1,6 @@ import { IVersion } from '@/Interface'; import { get } from './helpers'; -import { VERSIONS_BASE_URL } from '@/constants'; -export async function getNextVersions(version: string): Promise { - return await get(VERSIONS_BASE_URL, version); +export async function getNextVersions(endpoint: string, version: string): Promise { + return await get(endpoint, version); } diff --git a/packages/editor-ui/src/components/UpdatesPanel.vue b/packages/editor-ui/src/components/UpdatesPanel.vue index e5023db6d8..1e4bd9b42d 100644 --- a/packages/editor-ui/src/components/UpdatesPanel.vue +++ b/packages/editor-ui/src/components/UpdatesPanel.vue @@ -14,7 +14,7 @@

You’re on {{ currentVersion.name }}, which was released {{currentReleaseDate}} and is {{ nextVersions.length }} version{{nextVersions.length > 1 ? 's' : ''}} behind the latest and greatest n8n

- + How to update your n8n version @@ -38,7 +38,6 @@ import { format } from 'timeago.js'; import Modal from './Modal.vue'; import VersionCard from './VersionCard.vue'; -import { UPDATE_INFO_URL } from '@/constants'; export default Vue.extend({ name: 'UpdatesPanel', @@ -47,15 +46,11 @@ export default Vue.extend({ VersionCard, }, props: ['modalName', 'visible'], - data() { - return { - UPDATE_INFO_URL, - }; - }, computed: { ...mapGetters('versions', [ 'nextVersions', 'currentVersion', + 'infoUrl', ]), currentReleaseDate() { return format(this.currentVersion.createdAt); diff --git a/packages/editor-ui/src/constants.ts b/packages/editor-ui/src/constants.ts index 00c052c3e2..dee1e54061 100644 --- a/packages/editor-ui/src/constants.ts +++ b/packages/editor-ui/src/constants.ts @@ -49,7 +49,3 @@ export const HIDDEN_NODES = ['n8n-nodes-base.start']; export const WEBHOOK_NODE_NAME = 'n8n-nodes-base.webhook'; export const HTTP_REQUEST_NODE_NAME = 'n8n-nodes-base.httpRequest'; export const REQUEST_NODE_FORM_URL = 'https://n8n-community.typeform.com/to/K1fBVTZ3'; - -// versions -export const VERSIONS_BASE_URL = `https://api-staging.n8n.io/versions/`; -export const UPDATE_INFO_URL = 'https://docs.n8n.io/'; diff --git a/packages/editor-ui/src/modules/versions.ts b/packages/editor-ui/src/modules/versions.ts index 8e0f503837..630787e17f 100644 --- a/packages/editor-ui/src/modules/versions.ts +++ b/packages/editor-ui/src/modules/versions.ts @@ -1,5 +1,4 @@ import { getNextVersions } from '@/api/versions'; -import { versions } from 'process'; import { ActionContext, Module } from 'vuex'; import { IRootState, @@ -10,6 +9,11 @@ import { const module: Module = { namespaced: true, state: { + versionNotificationSettings: { + enabled: false, + endpoint: '', + infoUrl: '', + }, nextVersions: [], currentVersion: undefined, }, @@ -23,18 +27,30 @@ const module: Module = { currentVersion(state: IVersionsState) { return state.currentVersion; }, + areNotificationsEnabled(state: IVersionsState) { + return state.versionNotificationSettings.enabled; + }, + infoUrl(state: IVersionsState) { + return state.versionNotificationSettings.infoUrl; + }, }, mutations: { setVersions(state: IVersionsState, {versions, currentVersion}: {versions: IVersion[], currentVersion: string}) { state.nextVersions = versions.filter((version) => version.name !== currentVersion); state.currentVersion = versions.find((version) => version.name === currentVersion); }, + setVersionNotificationSettings(state: IVersionsState, settings: {enabled: true, endpoint: string, infoUrl: string}) { + state.versionNotificationSettings = settings; + }, }, actions: { async fetchVersions(context: ActionContext) { - const currentVersion = context.rootState.versionCli; - const versions = await getNextVersions(currentVersion); - context.commit('setVersions', {versions, currentVersion}); + const enabled = context.state.versionNotificationSettings.enabled; + if (enabled) { + const currentVersion = context.rootState.versionCli; + const versions = await getNextVersions(context.state.versionNotificationSettings.endpoint, currentVersion); + context.commit('setVersions', {versions, currentVersion}); + } }, }, }; diff --git a/packages/editor-ui/src/views/NodeView.vue b/packages/editor-ui/src/views/NodeView.vue index 77766c8107..ac96895229 100644 --- a/packages/editor-ui/src/views/NodeView.vue +++ b/packages/editor-ui/src/views/NodeView.vue @@ -2170,6 +2170,7 @@ export default mixins( this.$store.commit('setVersionCli', settings.versionCli); this.$store.commit('setOauthCallbackUrls', settings.oauthCallbackUrls); this.$store.commit('setN8nMetadata', settings.n8nMetadata || {}); + this.$store.commit('versions/setVersionNotificationSettings', settings.versionNotifications); }, async loadNodeTypes (): Promise { const nodeTypes = await this.restApi().getNodeTypes(); @@ -2194,8 +2195,36 @@ export default mixins( this.stopLoading(); } }, + async checkForNewVersions() { + const enabled = this.$store.getters['versions/areNotificationsEnabled']; + if (!enabled) { + return; + } + + await this.$store.dispatch('versions/fetchVersions'); + const currentVersion: IVersion | undefined = this.$store.getters['versions/currentVersion']; + const nextVersions: IVersion[] = this.$store.getters['versions/nextVersions']; + if (currentVersion && currentVersion.hasSecurityIssue && nextVersions.length) { + const fixVersion = currentVersion.securityIssueFixVersion; + let message = `Please update to latest version.`; + if (fixVersion) { + message = `Please update to version ${fixVersion} or higher.`; + } + + message = `${message} More info`; + this.$showWarning('Critical Update', message, { + onClick: () => { + this.$store.dispatch('ui/openUpdatesPanel'); + }, + closeOnClick: true, + customClass: 'clickable', + duration: 0, + }); + } + }, }, + async mounted () { this.$root.$on('importWorkflowData', async (data: IDataObject) => { const resData = await this.importWorkflowData(data.data as IWorkflowDataUpdate); @@ -2237,27 +2266,7 @@ export default mixins( this.stopLoading(); setTimeout(async () => { - await this.$store.dispatch('versions/fetchVersions'); - const currentVersion: IVersion | undefined = this.$store.getters['versions/currentVersion']; - const nextVersions: IVersion[] = this.$store.getters['versions/nextVersions']; - if (currentVersion && currentVersion.hasSecurityIssue && nextVersions.length) { - const fixVersion = currentVersion.securityIssueFixVersion; - let message = `Please update to latest version.`; - if (fixVersion) { - message = `Please update to version ${fixVersion} or higher.`; - } - - message = `${message} More info`; - this.$showWarning('Critical Update', message, { - onClick: () => { - this.$store.dispatch('ui/openUpdatesPanel'); - }, - closeOnClick: true, - customClass: 'clickable', - duration: 0, - }); - } - + this.checkForNewVersions(); }, 0); });