Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds "use latest dev" button #4142

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions website/src/website/pages/playground/PlaygroundModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -662,22 +672,26 @@ function findLastIndex<T>(
}

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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ export class PlaygroundPageContent extends React.Component<
.version ?? "url"}{" "}
override
</button>
<button
type="button"
className="btn btn-secondary"
onClick={() =>
model.serializer.useLatestDev()
}
>
Use latest dev
</button>
<button
type="button"
className="btn btn-secondary"
Expand Down
2 changes: 2 additions & 0 deletions website/src/website/pages/playground/getNpmVersionsSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export async function getNpmVersions(): Promise<string[]> {
return npmVersionsPromise!;
}

getNpmVersions();

async function loadNpmVersions(): Promise<string[]> {
if (npmVersionsPromise === undefined) {
npmVersionsPromise = _getNpmVersions();
Expand Down
Loading