From 57ac88c182f9bea9a07603587fb2e813b5c8c4f5 Mon Sep 17 00:00:00 2001 From: Henning Dieterichs Date: Mon, 28 Aug 2023 20:48:44 +0200 Subject: [PATCH] Adds "use latest dev" button --- .../pages/playground/PlaygroundModel.ts | 32 +++++++++++++------ .../playground/PlaygroundPageContent.tsx | 9 ++++++ .../pages/playground/getNpmVersionsSync.ts | 2 ++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/website/src/website/pages/playground/PlaygroundModel.ts b/website/src/website/pages/playground/PlaygroundModel.ts index 7096c30626..db067c6614 100644 --- a/website/src/website/pages/playground/PlaygroundModel.ts +++ b/website/src/website/pages/playground/PlaygroundModel.ts @@ -404,6 +404,16 @@ class StateUrlSerializer implements IHistoryModel { this.historyId++; } + @action + useLatestDev(): void { + this._sourceOverride = undefined; + this.model.settings.setSettings({ + ...this.model.settings.settings, + ...Source.useLatestDev().toPartialSettings(), + }); + this.historyId++; + } + @action saveSourceOverride(): void { if (this._sourceOverride) { @@ -662,22 +672,26 @@ function findLastIndex( } class Source { + public static useLatestDev(sourceLanguagesStr?: string): Source { + // Assume the versions are already loaded + const versions = getNpmVersionsSync(undefined); + const version = versions.find((v) => v.indexOf("-dev-") !== -1); + return new Source(version, undefined, sourceLanguagesStr); + } + + public static useLatest(sourceLanguagesStr?: string): Source { + return new Source(monacoEditorVersion, undefined, sourceLanguagesStr); + } + public static parse( sourceStr: string | undefined, sourceLanguagesStr: string | undefined ): Source { if (sourceStr === "latest-dev") { - // The versions are already loaded - const versions = getNpmVersionsSync(undefined); - const version = versions.find((v) => v.indexOf("-dev-") !== -1); - return new Source(version, undefined, sourceLanguagesStr); + return Source.useLatestDev(sourceLanguagesStr); } if (sourceStr === "latest") { - return new Source( - monacoEditorVersion, - undefined, - sourceLanguagesStr - ); + return Source.useLatest(sourceLanguagesStr); } if (sourceStr && sourceStr.startsWith("v")) { diff --git a/website/src/website/pages/playground/PlaygroundPageContent.tsx b/website/src/website/pages/playground/PlaygroundPageContent.tsx index 66b5e3f71e..ac5129cf6e 100644 --- a/website/src/website/pages/playground/PlaygroundPageContent.tsx +++ b/website/src/website/pages/playground/PlaygroundPageContent.tsx @@ -192,6 +192,15 @@ export class PlaygroundPageContent extends React.Component< .version ?? "url"}{" "} override +