From ca80f70823cae6cba41762e65d753396232f8dc0 Mon Sep 17 00:00:00 2001 From: Alex Tugarev Date: Thu, 28 Oct 2021 15:11:03 +0000 Subject: [PATCH] [projects] always enable New Workspace button on config page --- .../src/projects/ConfigureProject.tsx | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/components/dashboard/src/projects/ConfigureProject.tsx b/components/dashboard/src/projects/ConfigureProject.tsx index 42d6e82327f2ec..0fa3f2518230e0 100644 --- a/components/dashboard/src/projects/ConfigureProject.tsx +++ b/components/dashboard/src/projects/ConfigureProject.tsx @@ -43,8 +43,10 @@ const TASKS = { - init: pip install -r requirements.txt command: python main.py`, Other: `tasks: - - init: # TODO: install dependencies, build project - command: # TODO: start app` + - init: | + echo 'TODO: build project' + command: | + echo 'TODO: start app'` } // const IMAGES = { @@ -75,6 +77,7 @@ export default function () { const { isDark } = useContext(ThemeContext); const [showAuthBanner, setShowAuthBanner] = useState<{ host: string } | undefined>(undefined); + const [buttonNewWorkspaceEnabled, setButtonNewWorkspaceEnabled] = useState(true); useEffect(() => { // Disable editing while loading, or when the config comes from Git. @@ -164,11 +167,10 @@ export default function () { }); }; - const buildProject = async (event: React.MouseEvent) => { + const buildProject = async () => { if (!project) { return; } - // (event.target as HTMLButtonElement).disabled = true; setEditorMessage(null); if (!!startPrebuildResult) { setStartPrebuildResult(undefined); @@ -209,6 +211,26 @@ export default function () { useEffect(() => { document.title = 'Configure Project — Gitpod' }, []); + const onNewWorkspace = async () => { + setButtonNewWorkspaceEnabled(false); + const redirectToNewWorkspace = () => { + // instead of `history.push` we want forcibly to redirect here in order to avoid a following redirect from `/` -> `/projects` (cf. App.tsx) + const url = new URL(window.location.toString()); + url.pathname = "/"; + url.hash = project?.cloneUrl!; + window.location.href = url.toString(); + } + + if (prebuildInstance?.status.phase === "stopped" && !prebuildInstance?.status.conditions.failed && !prebuildInstance?.status.conditions.headlessTaskFailed) { + redirectToNewWorkspace(); + return; + } + if (!prebuildWasTriggered) { + await buildProject(); + } + redirectToNewWorkspace(); + } + return <>
@@ -257,14 +279,12 @@ export default function () {
{prebuildWasTriggered && }
- {((!isDetecting && isEditorDisabled) || (prebuildInstance?.status.phase === "stopped" && !prebuildInstance?.status.conditions.failed && !prebuildInstance?.status.conditions.headlessTaskFailed)) - ? - : } {(prebuildWasTriggered && prebuildInstance?.status.phase !== "stopped") ? - : } + : } +