fix(editor): Move versions check to init function and refactor store (no-changelog) (#8067)
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user