From f7be96f07c5a07499f9a3ed38c080d3e2c304c2a Mon Sep 17 00:00:00 2001 From: Samir AMZANI Date: Tue, 1 Aug 2023 17:16:50 +0200 Subject: [PATCH] feat: enable conversion to 3.0.0 only when setting is enabled --- apps/studio/src/services/parser.service.ts | 6 ------ .../src/services/specification.service.ts | 20 +++++++++++++++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/apps/studio/src/services/parser.service.ts b/apps/studio/src/services/parser.service.ts index 6feb1f4210..0fd3a56501 100644 --- a/apps/studio/src/services/parser.service.ts +++ b/apps/studio/src/services/parser.service.ts @@ -169,10 +169,4 @@ export class ParserService extends AbstractService { }), ); } - - isV3(): boolean { - const { editor: { v3support } } = settingsState.getState(); - console.log(v3support) - return false; - } } \ No newline at end of file diff --git a/apps/studio/src/services/specification.service.ts b/apps/studio/src/services/specification.service.ts index 3018ed705b..9c792e6927 100644 --- a/apps/studio/src/services/specification.service.ts +++ b/apps/studio/src/services/specification.service.ts @@ -5,13 +5,15 @@ import { show } from '@ebay/nice-modal-react'; import { ConvertToLatestModal } from '../components/Modals'; -import { documentsState } from '../state'; +import { documentsState, settingsState } from '../state'; import type { SpecVersions } from '../types'; export class SpecificationService extends AbstractService { + private betaVersion = false; override onInit() { this.subcribeToDocuments(); + this.subscribeToSettings(); } get specs() { @@ -19,7 +21,13 @@ export class SpecificationService extends AbstractService { } get latestVersion(): SpecVersions { - return Object.keys(this.specs).pop() as SpecVersions; + return this.betaVersion ? + Object.keys(this.specs).pop() as SpecVersions : + Object.keys(this.specs).at(-2) as SpecVersions; + } + + updateBetaVersion(enable: boolean): void { + this.betaVersion = enable; } getSpec(version: SpecVersions) { @@ -42,6 +50,14 @@ export class SpecificationService extends AbstractService { }); } + private subscribeToSettings() { + settingsState.subscribe((state, prevState) => { + if (state.editor.v3support === prevState.editor.v3support) return; + const { editor: { v3support } } = settingsState.getState(); + this.updateBetaVersion(v3support); + }); + } + private tryInformAboutLatestVersion( version: string, ): boolean {