fix(editor): Move versions check to init function and refactor store (no-changelog) (#8067)

This commit is contained in:
Alex Grozav
2023-12-20 12:49:40 +02:00
committed by GitHub
parent faadfd6d4a
commit fcff34c401
10 changed files with 223 additions and 84 deletions

View File

@@ -1,8 +1,10 @@
import { getNextVersions } from '@/api/versions';
import { STORES } from '@/constants';
import { STORES, VERSIONS_MODAL_KEY } from '@/constants';
import type { IVersion, IVersionNotificationSettings, IVersionsState } from '@/Interface';
import { defineStore } from 'pinia';
import { useRootStore } from './n8nRoot.store';
import { useToast } from '@/composables/useToast';
import { useUIStore } from '@/stores/ui.store';
export const useVersionsStore = defineStore(STORES.VERSIONS, {
state: (): IVersionsState => ({
@@ -45,5 +47,40 @@ export const useVersionsStore = defineStore(STORES.VERSIONS, {
}
} catch (e) {}
},
async checkForNewVersions() {
const enabled = this.areNotificationsEnabled;
if (!enabled) {
return;
}
const { showToast } = useToast();
const uiStore = useUIStore();
await this.fetchVersions();
const currentVersion = this.currentVersion;
const nextVersions = this.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} <a class="primary-color">More info</a>`;
showToast({
title: 'Critical update available',
message,
onClick: () => {
uiStore.openModal(VERSIONS_MODAL_KEY);
},
closeOnClick: true,
customClass: 'clickable',
type: 'warning',
duration: 0,
});
}
},
},
});