Skip to content

[dashboard] Always use these options for repository #17297

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

Merged
merged 1 commit into from
May 3, 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
22 changes: 18 additions & 4 deletions components/dashboard/src/start/start-workspace-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@
* See License.AGPL.txt in the project root for license information.
*/

import { GitpodServer } from "@gitpod/gitpod-protocol";
import { IDESettings } from "@gitpod/gitpod-protocol";

export interface StartWorkspaceOptions {
workspaceClass?: string;
ideSettings?: IDESettings;
autostart?: boolean;
}
export namespace StartWorkspaceOptions {
// The workspace class to use for the workspace. If not specified, the default workspace class is used.
export const WORKSPACE_CLASS = "workspaceClass";

// The editor to use for the workspace. If not specified, the default editor is used.
export const EDITOR = "editor";

export function parseSearchParams(search: string): GitpodServer.StartWorkspaceOptions {
// whether the workspace should automatically start
export const AUTOSTART = "autostart";

export function parseSearchParams(search: string): StartWorkspaceOptions {
const params = new URLSearchParams(search);
const options: GitpodServer.StartWorkspaceOptions = {};
const options: StartWorkspaceOptions = {};
const workspaceClass = params.get(StartWorkspaceOptions.WORKSPACE_CLASS);
if (workspaceClass) {
options.workspaceClass = workspaceClass;
Expand All @@ -34,10 +42,13 @@ export namespace StartWorkspaceOptions {
};
}
}
if (params.get(StartWorkspaceOptions.AUTOSTART) === "true") {
options.autostart = true;
}
return options;
}

export function toSearchParams(options: GitpodServer.StartWorkspaceOptions): string {
export function toSearchParams(options: StartWorkspaceOptions): string {
const params = new URLSearchParams();
if (options.workspaceClass) {
params.set(StartWorkspaceOptions.WORKSPACE_CLASS, options.workspaceClass);
Expand All @@ -47,6 +58,9 @@ export namespace StartWorkspaceOptions {
const latest = options.ideSettings.useLatestVersion;
params.set(StartWorkspaceOptions.EDITOR, latest ? ide + "-latest" : ide);
}
if (options.autostart) {
params.set(StartWorkspaceOptions.AUTOSTART, "true");
}
return params.toString();
}

Expand Down
22 changes: 19 additions & 3 deletions components/dashboard/src/user-settings/Preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import { PageWithSettingsSubMenu } from "./PageWithSettingsSubMenu";
import { ThemeSelector } from "../components/ThemeSelector";
import Alert from "../components/Alert";
import { Link } from "react-router-dom";
import { Heading2, Subheading } from "../components/typography/headings";
import { Heading2, Heading3, Subheading } from "../components/typography/headings";
import { useUserMaySetTimeout } from "../data/current-user/may-set-timeout-query";
import { Button } from "../components/Button";
import SelectIDE from "./SelectIDE";
import { InputField } from "../components/forms/InputField";
import { TextInput } from "../components/forms/TextInputField";
import { useToast } from "../components/toasts/Toasts";
import { useUpdateCurrentUserDotfileRepoMutation } from "../data/current-user/update-mutation";
import { AdditionalUserData } from "@gitpod/gitpod-protocol";

export type IDEChangedTrackLocation = "workspace_list" | "workspace_start" | "preferences";

Expand Down Expand Up @@ -67,12 +68,22 @@ export default function Preferences() {
[toast, setUser, workspaceTimeout],
);

const clearAutostartWorkspaceOptions = useCallback(async () => {
if (!user) {
return;
}
AdditionalUserData.set(user, { workspaceAutostartOptions: [] });
setUser(user);
await getGitpodService().server.updateLoggedInUser(user);
toast("Your autostart options were cleared.");
}, [setUser, toast, user]);

return (
<div>
<PageWithSettingsSubMenu>
<Heading2>Editor</Heading2>
<Heading2>New Workspaces</Heading2>
<Subheading>
Choose the editor for opening workspaces.{" "}
Choose your default editor.{" "}
<a
className="gp-link"
href="https://www.gitpod.io/docs/references/ides-and-editors"
Expand All @@ -83,6 +94,11 @@ export default function Preferences() {
</a>
</Subheading>
<SelectIDE location="preferences" />
<Heading3 className="mt-12">Autostart Options</Heading3>
<Subheading>Forget any saved autostart options for all repositories.</Subheading>
<Button className="mt-4" type="secondary" onClick={clearAutostartWorkspaceOptions}>
Reset Options
</Button>

<ThemeSelector className="mt-12" />

Expand Down
Loading