UNPKG

@finos/legend-application

Version:
83 lines 3.24 kB
/** * Copyright (c) 2020-present, Goldman Sachs * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { compareSemVerVersions, guaranteeNonEmptyString, isSemVer, } from '@finos/legend-shared'; import { action, makeObservable, observable } from 'mobx'; export var RELEASE_UPDATE_TYPE; (function (RELEASE_UPDATE_TYPE) { RELEASE_UPDATE_TYPE["BUG_FIX"] = "BUG_FIX"; RELEASE_UPDATE_TYPE["ENHANCEMENT"] = "ENHANCEMENT"; })(RELEASE_UPDATE_TYPE || (RELEASE_UPDATE_TYPE = {})); export const collectReleaseNotes = (releaseNotes) => releaseNotes.map((release) => { guaranteeNonEmptyString(release.version, "Release notes 'version' is missing"); release.notes?.map((note) => { guaranteeNonEmptyString(note.type, "Release note 'type' is missing"); guaranteeNonEmptyString(note.description, "Release note 'description' is missing"); return note; }); return release; }); export const APPLICATION_LAST_OPENED_VERSION = 'application.lastOpenedVersion'; export class ReleaseNotesService { applicationStore; releaseNotes; showCurrentReleaseModal = true; showReleaseLog = false; isConfigured = false; constructor(applicationStore) { makeObservable(this, { showCurrentReleaseModal: observable, showReleaseLog: observable, isConfigured: observable, setShowCurrentRelease: action, configure: action, setReleaseLog: action, }); this.applicationStore = applicationStore; } configure(releaseNotes) { this.isConfigured = true; this.releaseNotes = collectReleaseNotes(releaseNotes); } setShowCurrentRelease(val) { this.showCurrentReleaseModal = val; } setReleaseLog(val) { this.showReleaseLog = val; } getViewedVersion() { return this.applicationStore.userDataService.getStringValue(APPLICATION_LAST_OPENED_VERSION); } updateViewedVersion() { this.applicationStore.userDataService.persistValue(APPLICATION_LAST_OPENED_VERSION, this.applicationStore.config.appVersion); } showVersion(versionNotes, lastOpenedVersion) { const version = versionNotes.version; if (isSemVer(version) && isSemVer(lastOpenedVersion)) { if (compareSemVerVersions(version, lastOpenedVersion) === 1) { return true; } } return false; } showableVersions() { const lastOpenedVersion = this.getViewedVersion(); if (!lastOpenedVersion) { return undefined; } return this.releaseNotes?.filter((val) => this.showVersion(val, lastOpenedVersion)); } } //# sourceMappingURL=ReleaseNotesService.js.map