Path: blob/main/components/dashboard/src/start/start-workspace-options.ts
2500 views
/**1* Copyright (c) 2022 Gitpod GmbH. All rights reserved.2* Licensed under the GNU Affero General Public License (AGPL).3* See License.AGPL.txt in the project root for license information.4*/56import { IDESettings } from "@gitpod/gitpod-protocol";78export interface StartWorkspaceOptions {9workspaceClass?: string;10ideSettings?: IDESettings;11autostart?: boolean;12showExamples?: boolean;13}14export namespace StartWorkspaceOptions {15// The workspace class to use for the workspace. If not specified, the default workspace class is used.16export const WORKSPACE_CLASS = "workspaceClass";1718// The editor to use for the workspace. If not specified, the default editor is used.19export const EDITOR = "editor";2021// whether the workspace should automatically start22export const AUTOSTART = "autostart";2324// whether to show example repositories25export const SHOW_EXAMPLES = "showExamples";2627export function parseSearchParams(search: string): StartWorkspaceOptions {28const params = new URLSearchParams(search);29const options: StartWorkspaceOptions = {};30const workspaceClass = params.get(StartWorkspaceOptions.WORKSPACE_CLASS);31if (workspaceClass) {32options.workspaceClass = workspaceClass;33}34const editorParam = params.get(StartWorkspaceOptions.EDITOR);35if (editorParam) {36if (editorParam?.endsWith("-latest")) {37options.ideSettings = {38defaultIde: editorParam.slice(0, -7),39useLatestVersion: true,40};41} else {42options.ideSettings = {43defaultIde: editorParam,44useLatestVersion: false,45};46}47}48if (params.get(StartWorkspaceOptions.AUTOSTART)) {49options.autostart = params.get(StartWorkspaceOptions.AUTOSTART) === "true";50}5152if (params.get(StartWorkspaceOptions.SHOW_EXAMPLES)) {53options.showExamples = params.get(StartWorkspaceOptions.SHOW_EXAMPLES) === "true";54}5556return options;57}5859export function toSearchParams(options: StartWorkspaceOptions): string {60const params = new URLSearchParams();61if (options.workspaceClass) {62params.set(StartWorkspaceOptions.WORKSPACE_CLASS, options.workspaceClass);63}64if (options.ideSettings && options.ideSettings.defaultIde) {65const ide = options.ideSettings.defaultIde;66const latest = options.ideSettings.useLatestVersion;67params.set(StartWorkspaceOptions.EDITOR, latest ? ide + "-latest" : ide);68}69if (options.autostart) {70params.set(StartWorkspaceOptions.AUTOSTART, "true");71}72if (options.showExamples) {73params.set(StartWorkspaceOptions.SHOW_EXAMPLES, "true");74}75return params.toString();76}7778export function parseContextUrl(locationHash: string): string {79let result = locationHash.replace(/^[#/]+/, "").trim();80return result;81}82}838485