refactor(editor): Add infix to Pinia stores (no-changelog) (#6149)
* ⚡ Add infix to Pinia stores * ⚡ Fix paths in mocks * 🐛 Fix import
This commit is contained in:
49
packages/editor-ui/src/stores/versions.store.ts
Normal file
49
packages/editor-ui/src/stores/versions.store.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { getNextVersions } from '@/api/versions';
|
||||
import { STORES } from '@/constants';
|
||||
import type { IVersion, IVersionNotificationSettings, IVersionsState } from '@/Interface';
|
||||
import { defineStore } from 'pinia';
|
||||
import { useRootStore } from './n8nRoot.store';
|
||||
|
||||
export const useVersionsStore = defineStore(STORES.VERSIONS, {
|
||||
state: (): IVersionsState => ({
|
||||
versionNotificationSettings: {
|
||||
enabled: false,
|
||||
endpoint: '',
|
||||
infoUrl: '',
|
||||
},
|
||||
nextVersions: [],
|
||||
currentVersion: undefined,
|
||||
}),
|
||||
getters: {
|
||||
hasVersionUpdates(): boolean {
|
||||
return this.nextVersions.length > 0;
|
||||
},
|
||||
areNotificationsEnabled(): boolean {
|
||||
return this.versionNotificationSettings.enabled;
|
||||
},
|
||||
infoUrl(): string {
|
||||
return this.versionNotificationSettings.infoUrl;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
setVersions({ versions, currentVersion }: { versions: IVersion[]; currentVersion: string }) {
|
||||
this.nextVersions = versions.filter((version) => version.name !== currentVersion);
|
||||
this.currentVersion = versions.find((version) => version.name === currentVersion);
|
||||
},
|
||||
setVersionNotificationSettings(settings: IVersionNotificationSettings) {
|
||||
this.versionNotificationSettings = settings;
|
||||
},
|
||||
async fetchVersions() {
|
||||
try {
|
||||
const { enabled, endpoint } = this.versionNotificationSettings;
|
||||
if (enabled && endpoint) {
|
||||
const rootStore = useRootStore();
|
||||
const currentVersion = rootStore.versionCli;
|
||||
const instanceId = rootStore.instanceId;
|
||||
const versions = await getNextVersions(endpoint, currentVersion, instanceId);
|
||||
this.setVersions({ versions, currentVersion });
|
||||
}
|
||||
} catch (e) {}
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user