From 0c20837ee087f52463921750b0c47cd95e552e1e Mon Sep 17 00:00:00 2001 From: Milan Pavlik Date: Mon, 14 Mar 2022 16:20:19 +0000 Subject: [PATCH] Remove Prebuild logs from ProjectConfiguration view --- .../src/projects/ConfigureProject.tsx | 180 ++++-------------- .../dashboard/src/projects/Prebuilds.tsx | 119 +----------- 2 files changed, 41 insertions(+), 258 deletions(-) diff --git a/components/dashboard/src/projects/ConfigureProject.tsx b/components/dashboard/src/projects/ConfigureProject.tsx index d485b60805f030..174e5112e9ef14 100644 --- a/components/dashboard/src/projects/ConfigureProject.tsx +++ b/components/dashboard/src/projects/ConfigureProject.tsx @@ -5,16 +5,11 @@ */ import React, { Suspense, useContext, useEffect, useState } from "react"; -import { Project, StartPrebuildResult, WorkspaceInstance } from "@gitpod/gitpod-protocol"; -import PrebuildLogs from "../components/PrebuildLogs"; +import { Project } from "@gitpod/gitpod-protocol"; import TabMenuItem from "../components/TabMenuItem"; import { getGitpodService } from "../service/service"; import Spinner from "../icons/Spinner.svg"; import NoAccess from "../icons/NoAccess.svg"; -import PrebuildLogsEmpty from "../images/prebuild-logs-empty.svg"; -import PrebuildLogsEmptyDark from "../images/prebuild-logs-empty-dark.svg"; -import { ThemeContext } from "../theme-context"; -import { PrebuildInstanceStatus } from "./Prebuilds"; import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error"; import { openAuthorizeWindow } from "../provider-utils"; import { ProjectSettingsPage } from "./ProjectSettings"; @@ -30,15 +25,6 @@ const TASKS = { echo 'TODO: start app'`, }; -// const IMAGES = { -// Default: 'gitpod/workspace-full', -// '.NET': 'gitpod/workspace-dotnet', -// MongoDB: 'gitpod/workspace-mongodb', -// MySQL: 'gitpod/workspace-mysql', -// PostgreSQL: 'gitpod/workspace-postgres', -// 'Virtual Desktop (VNC)': 'gitpod/workspace-full-vnc', -// } - export default function () { const { project } = useContext(ProjectContext); const [gitpodYml, setGitpodYml] = useState(""); @@ -47,12 +33,7 @@ export default function () { const [selectedEditor, setSelectedEditor] = useState<".gitpod.yml" | ".gitpod.Dockerfile">(".gitpod.yml"); const [isEditorDisabled, setIsEditorDisabled] = useState(true); const [isDetecting, setIsDetecting] = useState(true); - const [prebuildWasTriggered, setPrebuildWasTriggered] = useState(false); - const [prebuildWasCancelled, setPrebuildWasCancelled] = useState(false); - const [startPrebuildResult, setStartPrebuildResult] = useState(); - const [prebuildInstance, setPrebuildInstance] = useState(); - const { isDark } = useContext(ThemeContext); - + const [progressMessage, setProgressMessage] = useState(""); const [showAuthBanner, setShowAuthBanner] = useState<{ host: string; scope?: string } | undefined>(undefined); const [buttonNewWorkspaceEnabled, setButtonNewWorkspaceEnabled] = useState(true); @@ -108,7 +89,7 @@ export default function () { , ); setGitpodYml(repoConfigString); @@ -128,7 +109,7 @@ export default function () { , ); setGitpodYml(guessedConfigString); @@ -138,7 +119,7 @@ export default function () { , ); setGitpodYml(TASKS.Other); @@ -176,66 +157,39 @@ export default function () { }); }; - const buildProject = async () => { + useEffect(() => { + document.title = "Configure Project — Gitpod"; + }, []); + + const onNewWorkspace = async () => { if (!project) { return; } - setEditorMessage(null); - if (!!startPrebuildResult) { - setStartPrebuildResult(undefined); - } - if (!!prebuildInstance) { - setPrebuildInstance(undefined); - } - try { - setPrebuildWasTriggered(true); - if (!isEditorDisabled) { - await getGitpodService().server.setProjectConfiguration(project.id, gitpodYml); - } - const result = await getGitpodService().server.triggerPrebuild(project.id, null); - setStartPrebuildResult(result); - } catch (error) { - setPrebuildWasTriggered(false); - setEditorMessage( - , - ); - } - }; - const cancelPrebuild = async () => { - if (!project || !startPrebuildResult) { - return; - } - setPrebuildWasCancelled(true); - try { - await getGitpodService().server.cancelPrebuild(project.id, startPrebuildResult.prebuildId); - } catch (error) { - setEditorMessage( - , - ); - } finally { - setPrebuildWasCancelled(false); - } - }; + setButtonNewWorkspaceEnabled(false); - const onInstanceUpdate = (instance: WorkspaceInstance) => { - setPrebuildInstance(instance); - }; + if (!isEditorDisabled) { + try { + setProgressMessage("Saving project configuration..."); + await getGitpodService().server.setProjectConfiguration(project.id, gitpodYml); - useEffect(() => { - document.title = "Configure Project — Gitpod"; - }, []); + setProgressMessage("Starting a new prebuild..."); + await getGitpodService().server.triggerPrebuild(project.id, null); + } catch (error) { + setEditorMessage( + , + ); + + setProgressMessage(""); + setButtonNewWorkspaceEnabled(true); + return; + } + } - 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()); @@ -244,25 +198,15 @@ export default function () { 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; }; return ( -
-
-
+
+
+
)}
-
-
- {startPrebuildResult ? ( - - ) : ( - !prebuildWasTriggered && ( -
- -

- No Recent Prebuild -

-

- Edit the project configuration on the left to get started.{" "} - - Learn more - -

-
- ) - )} -
-
- {prebuildWasTriggered && } -
- {prebuildWasTriggered && prebuildInstance?.status.phase !== "stopped" ? ( - - ) : ( - - )} - -
+
+
diff --git a/components/dashboard/src/projects/Prebuilds.tsx b/components/dashboard/src/projects/Prebuilds.tsx index a809613d020f99..1c5ce557946577 100644 --- a/components/dashboard/src/projects/Prebuilds.tsx +++ b/components/dashboard/src/projects/Prebuilds.tsx @@ -5,7 +5,7 @@ */ import moment from "moment"; -import { PrebuildWithStatus, PrebuiltWorkspaceState, Project, WorkspaceInstance } from "@gitpod/gitpod-protocol"; +import { PrebuildWithStatus, PrebuiltWorkspaceState, Project } from "@gitpod/gitpod-protocol"; import { useContext, useEffect, useState } from "react"; import { useLocation, useRouteMatch } from "react-router"; import Header from "../components/Header"; @@ -358,17 +358,12 @@ function PrebuildStatusDescription(props: { prebuild: PrebuildWithStatus }) { ); } - return Prebuild completed succesfully.; + return Prebuild completed successfully.; default: return Unknown prebuild status.; } } -function formatDuration(milliseconds: number) { - const hours = Math.floor(milliseconds / (1000 * 60 * 60)); - return (hours > 0 ? `${hours}:` : "") + moment(milliseconds).format("mm:ss"); -} - export function PrebuildStatus(props: { prebuild: PrebuildWithStatus }) { const prebuild = props.prebuild; @@ -386,113 +381,3 @@ export function PrebuildStatus(props: { prebuild: PrebuildWithStatus }) {
); } - -// Deprecated. Use PrebuildStatus instead. -export function PrebuildInstanceStatus(props: { prebuildInstance?: WorkspaceInstance; prebuild?: PrebuildWithStatus }) { - let status = <>; - let details = <>; - switch (props.prebuildInstance?.status.phase) { - case undefined: // Fall through - case "preparing": // Fall through - case "pending": // Fall through - case "creating": // Fall through - case "unknown": - status = ( -
- - PENDING -
- ); - details = ( -
- - Preparing prebuild ... -
- ); - break; - case "initializing": // Fall through - case "running": // Fall through - case "interrupted": // Fall through - case "stopping": - status = ( -
- - RUNNING -
- ); - details = ( -
- - Prebuild in progress ... -
- ); - break; - case "stopped": - status = ( -
- - READY -
- ); - details = ( -
- - - {!!props.prebuildInstance?.stoppedTime - ? formatDuration( - new Date(props.prebuildInstance.stoppedTime).getTime() - - new Date(props.prebuildInstance.creationTime).getTime(), - ) - : "..."} - -
- ); - break; - } - if (props.prebuildInstance?.status.conditions.stoppedByRequest) { - status = ( -
- - CANCELED -
- ); - details = ( -
- Prebuild canceled -
- ); - } else if ( - props.prebuildInstance?.status.conditions.failed || - props.prebuildInstance?.status.conditions.headlessTaskFailed - ) { - status = ( -
- - FAILED -
- ); - details = ( -
- Prebuild failed -
- ); - } else if (props.prebuildInstance?.status.conditions.timeout) { - status = ( -
- - FAILED -
- ); - details = ( -
- Prebuild timed out -
- ); - } - return ( -
-
{status}
-
{details}
-
- ); -}