Skip to content

[dashboard] Remove the auto start option #18645

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

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ export const useCreateWorkspaceMutation = () => {
onError: (error) => {
setIsStarting(false);
},
onSuccess: (result) => {
if (result && result.createdWorkspaceId) {
// successfully started a workspace, wait a bit before we allow to start another one
setTimeout(() => {
setIsStarting(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like isStarting will remain true now even after it's done. Maybe we can just use the isLoading state now instead - isStarting: mutation.isLoading?

}, 4000);
} else {
setIsStarting(false);
}
},
});
return {
createWorkspace: (options: GitpodServer.CreateWorkspaceOptions) => {
Expand Down
15 changes: 10 additions & 5 deletions components/dashboard/src/start/start-workspace-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface StartWorkspaceOptions {
}
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";
export const WORKSPACE_CLASS = "workspaceclass";

// The editor to use for the workspace. If not specified, the default editor is used.
export const EDITOR = "editor";
Expand All @@ -22,7 +22,12 @@ export namespace StartWorkspaceOptions {
export const AUTOSTART = "autostart";

export function parseSearchParams(search: string): StartWorkspaceOptions {
const params = new URLSearchParams(search);
const original = new URLSearchParams(search);
const params = new URLSearchParams();
// translate to lower case
for (const [key, value] of original.entries()) {
params.set(key.toLowerCase(), value);
}
const options: StartWorkspaceOptions = {};
const workspaceClass = params.get(StartWorkspaceOptions.WORKSPACE_CLASS);
if (workspaceClass) {
Expand All @@ -43,7 +48,7 @@ export namespace StartWorkspaceOptions {
}
}
if (params.get(StartWorkspaceOptions.AUTOSTART)) {
options.autostart = params.get(StartWorkspaceOptions.AUTOSTART) === "true";
options.autostart = params.get(StartWorkspaceOptions.AUTOSTART) !== "false";
}
return options;
}
Expand All @@ -58,8 +63,8 @@ export namespace StartWorkspaceOptions {
const latest = options.ideSettings.useLatestVersion;
params.set(StartWorkspaceOptions.EDITOR, latest ? ide + "-latest" : ide);
}
if (options.autostart) {
params.set(StartWorkspaceOptions.AUTOSTART, "true");
if (options.autostart !== undefined) {
params.set(StartWorkspaceOptions.AUTOSTART, options.autostart.toString());
}
return params.toString();
}
Expand Down
107 changes: 43 additions & 64 deletions components/dashboard/src/workspaces/CreateWorkspacePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,33 @@ import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
import { Deferred } from "@gitpod/gitpod-protocol/lib/util/deferred";
import { FC, FunctionComponent, useCallback, useContext, useEffect, useMemo, useState } from "react";
import { useHistory, useLocation } from "react-router";
import { Link } from "react-router-dom";
import Alert from "../components/Alert";
import { AuthorizeGit, useNeedsGitAuthorization } from "../components/AuthorizeGit";
import { Button } from "../components/Button";
import { LinkButton } from "../components/LinkButton";
import Modal from "../components/Modal";
import RepositoryFinder from "../components/RepositoryFinder";
import SelectIDEComponent from "../components/SelectIDEComponent";
import SelectWorkspaceClassComponent from "../components/SelectWorkspaceClassComponent";
import { UsageLimitReachedModal } from "../components/UsageLimitReachedModal";
import { CheckboxInputField } from "../components/forms/CheckboxInputField";
import { InputField } from "../components/forms/InputField";
import { Heading1 } from "../components/typography/headings";
import { useAuthProviders } from "../data/auth-providers/auth-provider-query";
import { useCurrentOrg } from "../data/organizations/orgs-query";
import { useListProjectsQuery } from "../data/projects/list-projects-query";
import { useCreateWorkspaceMutation } from "../data/workspaces/create-workspace-mutation";
import { useListWorkspacesQuery } from "../data/workspaces/list-workspaces-query";
import { useWorkspaceContext } from "../data/workspaces/resolve-context-query";
import { useDirtyState } from "../hooks/use-dirty-state";
import { openAuthorizeWindow } from "../provider-utils";
import { getGitpodService, gitpodHostUrl } from "../service/service";
import { StartWorkspaceError } from "../start/StartPage";
import { VerifyModal } from "../start/VerifyModal";
import { StartWorkspaceOptions } from "../start/start-workspace-options";
import { UserContext, useCurrentUser } from "../user-context";
import { SelectAccountModal } from "../user-settings/SelectAccountModal";
import { settingsPathPreferences } from "../user-settings/settings.routes";
import { WorkspaceEntry } from "./WorkspaceEntry";
import { AuthorizeGit, useNeedsGitAuthorization } from "../components/AuthorizeGit";
import { settingsPathIntegrations } from "../user-settings/settings.routes";
import { useDirtyState } from "../hooks/use-dirty-state";
import { LinkButton } from "../components/LinkButton";
import { InputField } from "../components/forms/InputField";
import Alert from "../components/Alert";
import { WorkspaceEntry } from "./WorkspaceEntry";

export function CreateWorkspacePage() {
const { user, setUser } = useContext(UserContext);
Expand All @@ -48,8 +45,14 @@ export function CreateWorkspacePage() {
const workspaces = useListWorkspacesQuery({ limit: 50 });
const location = useLocation();
const history = useHistory();
const [contextURL, setContextURL] = useState<string | undefined>(
StartWorkspaceOptions.parseContextUrl(location.hash),
);
const props = StartWorkspaceOptions.parseSearchParams(location.search);
const [autostart, setAutostart] = useState<boolean | undefined>(props.autostart);
// we autostart when a contextURL is provided via the URL hash and autostart is not explicitly set to false
const [autostart, setAutostart] = useState<boolean | undefined>(
contextURL !== undefined && props.autostart !== false,
);
const createWorkspaceMutation = useCreateWorkspaceMutation();

const defaultLatestIde =
Expand All @@ -65,11 +68,7 @@ export function CreateWorkspacePage() {
const defaultWorkspaceClass = props.workspaceClass;
const [selectedWsClass, setSelectedWsClass, selectedWsClassIsDirty] = useDirtyState(defaultWorkspaceClass);
const [errorWsClass, setErrorWsClass] = useState<string | undefined>(undefined);
const [contextURL, setContextURL] = useState<string | undefined>(
StartWorkspaceOptions.parseContextUrl(location.hash),
);
const workspaceContext = useWorkspaceContext(contextURL);
const [rememberOptions, setRememberOptions] = useState(false);
const needsGitAuthorization = useNeedsGitAuthorization();

const storeAutoStartOptions = useCallback(async () => {
Expand All @@ -87,24 +86,22 @@ export function CreateWorkspacePage() {
// we only keep the last 20 options
workspaceAutoStartOptions = workspaceAutoStartOptions.slice(-40);

if (rememberOptions) {
workspaceAutoStartOptions.push({
cloneURL,
organizationId: currentOrg.id,
ideSettings: {
defaultIde: selectedIde,
useLatestVersion: useLatestIde,
},
workspaceClass: selectedWsClass,
});
}
workspaceAutoStartOptions.push({
cloneURL,
organizationId: currentOrg.id,
ideSettings: {
defaultIde: selectedIde,
useLatestVersion: useLatestIde,
},
workspaceClass: selectedWsClass,
});
AdditionalUserData.set(user, {
workspaceAutostartOptions: workspaceAutoStartOptions,
});
setUser(user);
await getGitpodService().server.updateLoggedInUser(user);
console.log("Stored autostart options", workspaceAutoStartOptions);
}, [currentOrg, rememberOptions, selectedIde, selectedWsClass, setUser, useLatestIde, user, workspaceContext.data]);
}, [currentOrg, selectedIde, selectedWsClass, setUser, useLatestIde, user, workspaceContext.data]);

// see if we have a matching project based on context url and project's repo url
const project = useMemo(() => {
Expand Down Expand Up @@ -274,7 +271,6 @@ export function CreateWorkspacePage() {
(e) => e.cloneURL === cloneURL && e.organizationId === currentOrg?.id,
);
if (rememberedOptions) {
setRememberOptions(true);
if (!selectedIdeIsDirty) {
setSelectedIde(rememberedOptions.ideSettings?.defaultIde, false);
setUseLatestIde(!!rememberedOptions.ideSettings?.useLatestVersion);
Expand All @@ -287,12 +283,15 @@ export function CreateWorkspacePage() {
setAutostart(true);
}
} else {
setRememberOptions(false);
// reset the ide settings to the user's default IF they haven't changed it manually
if (!selectedIdeIsDirty) {
setSelectedIde(defaultIde, false);
setUseLatestIde(defaultLatestIde);
}

if (!selectedWsClassIsDirty) {
setSelectedWsClass(defaultWorkspaceClass, false);
}
}
// we only update the remembered options when the workspaceContext changes
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -313,7 +312,14 @@ export function CreateWorkspacePage() {

// Derive if the continue button is disabled based on current state
const continueButtonDisabled = useMemo(() => {
if (workspaceContext.isLoading || !contextURL || contextURL.length === 0 || !!errorIde || !!errorWsClass) {
if (
createWorkspaceMutation.isStarting ||
workspaceContext.isLoading ||
!contextURL ||
contextURL.length === 0 ||
!!errorIde ||
!!errorWsClass
) {
return true;
}
if (workspaceContext.error) {
Expand All @@ -326,7 +332,14 @@ export function CreateWorkspacePage() {
}

return false;
}, [contextURL, errorIde, errorWsClass, workspaceContext.error, workspaceContext.isLoading]);
}, [
contextURL,
createWorkspaceMutation.isStarting,
errorIde,
errorWsClass,
workspaceContext.error,
workspaceContext.isLoading,
]);

if (SelectAccountPayload.is(selectAccountError)) {
return (
Expand Down Expand Up @@ -418,13 +431,6 @@ export function CreateWorkspacePage() {
</Button>
</div>

{workspaceContext.data && (
<RememberOptions
disabled={workspaceContext.isLoading || createWorkspaceMutation.isStarting}
checked={rememberOptions}
onChange={setRememberOptions}
/>
)}
{existingWorkspaces.length > 0 && !createWorkspaceMutation.isStarting && (
<div className="w-full flex flex-col justify-end px-6">
<p className="mt-6 text-center text-base">Running workspaces on this revision</p>
Expand All @@ -446,33 +452,6 @@ export function CreateWorkspacePage() {
);
}

function RememberOptions(params: { disabled?: boolean; checked: boolean; onChange: (checked: boolean) => void }) {
const { disabled, checked, onChange } = params;

return (
<>
<div className={"w-full flex justify-center mt-3 px-8 mx-2"}>
<CheckboxInputField
label="Autostart with these options for this repository."
checked={checked}
disabled={disabled}
topMargin={false}
onChange={onChange}
/>
</div>
<div className={"w-full flex justify-center px-8 mx-2"}>
<p className="text-gray-400 dark:text-gray-500 text-sm">
Don't worry, you can reset this anytime in your{" "}
<Link to={settingsPathPreferences} className="gp-link">
preferences
</Link>
.
</p>
</div>
</>
);
}

function tryAuthorize(host: string, scopes?: string[]): Promise<SelectAccountPayload | undefined> {
const result = new Deferred<SelectAccountPayload | undefined>();
openAuthorizeWindow({
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion components/usage-api/typescript/src/usage/v1/usage.pb.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.