Skip to content
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

Prebuilds Page #4876

Merged
merged 3 commits into from
Jul 26, 2021
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
13 changes: 7 additions & 6 deletions components/dashboard/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const ConfigureProject = React.lazy(() => import(/* webpackPrefetch: true */ './
const Projects = React.lazy(() => import(/* webpackPrefetch: true */ './projects/Projects'));
const Project = React.lazy(() => import(/* webpackPrefetch: true */ './projects/Project'));
const Prebuilds = React.lazy(() => import(/* webpackPrefetch: true */ './projects/Prebuilds'));
const Prebuild = React.lazy(() => import(/* webpackPrefetch: true */ './projects/Prebuild'));
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Fetching active branches and prebuilds requires a noticable amount of time, 5 seconds or more. Is there anything we could do in this iteration to make this smoother? If not, let's add a follow up issue for adding a loading indicator in a future iteration. ⏱️

const Settings = React.lazy(() => import(/* webpackPrefetch: true */ './projects/Settings'));
Copy link
Contributor

Choose a reason for hiding this comment

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

question: We no longer need the Settings tab for this iteration, right? If so, let's remove this here or in a follow up issue.

const InstallGitHubApp = React.lazy(() => import(/* webpackPrefetch: true */ './prebuilds/InstallGitHubApp'));
const FromReferrer = React.lazy(() => import(/* webpackPrefetch: true */ './FromReferrer'));
Expand Down Expand Up @@ -199,24 +200,24 @@ function App() {
<Route exact path={`/${team.slug}`}>
<Redirect to={`/${team.slug}/projects`} />
</Route>
<Route exact path={`/${team.slug}/:maybeProject/:subResource?`} render={(props) => {
const { maybeProject, subResource } = props.match.params;
<Route exact path={`/${team.slug}/:maybeProject/:resourceOrPrebuild?`} render={(props) => {
const { maybeProject, resourceOrPrebuild } = props.match.params;
if (maybeProject === "projects") {
return <Projects />;
}
if (maybeProject === "members") {
return <Members />;
}
if (subResource === "configure") {
if (resourceOrPrebuild === "configure") {
return <ConfigureProject />;
}
if (subResource === "prebuilds") {
if (resourceOrPrebuild === "prebuilds") {
return <Prebuilds />;
}
if (subResource === "settings") {
if (resourceOrPrebuild === "settings") {
return <Settings />;
}
return <Project />;
return resourceOrPrebuild ? <Prebuild /> : <Project />;
}} />
</Route>)}
<Route path="*" render={
Expand Down
43 changes: 29 additions & 14 deletions components/dashboard/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useLocation, useRouteMatch } from "react-router";
import { Location } from "history";
import gitpodIcon from './icons/gitpod.svg';
import CaretDown from "./icons/CaretDown.svg";
import CaretUpDown from "./icons/CaretUpDown.svg";
import { getGitpodService, gitpodHostUrl } from "./service/service";
import { UserContext } from "./user-context";
import { TeamsContext, getCurrentTeam } from "./teams/teams-context";
Expand All @@ -27,26 +28,33 @@ interface Entry {
alternatives?: string[]
}

function isSelected(entry: Entry, location: Location<any>) {
const all = [entry.link, ...(entry.alternatives||[])];
const path = location.pathname.toLowerCase();
return all.some(n => n === path || n+'/' === path);
}

export default function Menu() {
const { user } = useContext(UserContext);
const { teams } = useContext(TeamsContext);
const history = useHistory();
const location = useLocation();

const match = useRouteMatch<{ team: string, resource: string }>("/:team/:resource");
const match = useRouteMatch<{ segment1?: string, segment2?: string, segment3?: string }>("/:segment1/:segment2?/:segment3?");
const projectName = (() => {
const resource = match?.params?.resource;
if (resource !== "projects" && resource !== "members") {
const resource = match?.params?.segment2;
if (resource && !["projects", "members", "users", "workspaces"].includes(resource)) {
return resource;
}
})();
const prebuildId = (() => {
const resource = projectName && match?.params?.segment3;
if (resource !== "prebuilds" && resource !== "settings" && resource !== "configure") {
return resource;
}
})();

function isSelected(entry: Entry, location: Location<any>) {
const all = [entry.link, ...(entry.alternatives||[])].map(l => l.toLowerCase());
const path = location.pathname.toLowerCase();
return all.some(n => n === path || n+'/' === path);
}

const userFullName = user?.fullName || user?.name || '...';
const showTeamsUI = user?.rolesOrPermissions?.includes('teams-and-projects');
const team = getCurrentTeam(location, teams);
Expand Down Expand Up @@ -135,7 +143,6 @@ export default function Menu() {
<div className="flex p-1 pl-3 ">
<div className="flex h-full rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 px-2 py-1">
<Link to={team ? `/${team.slug}/projects` : "/workspaces"}>

<span className="text-base text-gray-600 dark:text-gray-400 font-semibold">{team?.name || userFullName}</span>
</Link>
</div>
Expand Down Expand Up @@ -171,14 +178,22 @@ export default function Menu() {
onClick: () => history.push("/teams/new"),
}
]}>
<div className="flex h-full p-2 mt-0.5">
<img className="filter-grayscale m-auto" src={CaretDown} />
<div className="flex h-full px-2 py-1.5">
<img className="filter-grayscale m-auto" src={CaretUpDown} />
</div>
</ContextMenu>
</div>
{ projectName && (
<div className="flex h-full rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 px-2 py-1">
<Link to={`/${team?.slug}/${projectName}${prebuildId ? "/prebuilds" : ""}`}>
<span className="text-base text-gray-600 dark:text-gray-400 font-semibold">{projectName}</span>
</Link>
</div>
)}
{ prebuildId && (
<div className="flex h-full ml-2 py-1">
<span className="text-base text-gray-600 dark:text-gray-400 font-semibold">{projectName}</span>
<img className="mr-3 filter-grayscale m-auto transform -rotate-90" src={CaretDown} />
<span className="text-base text-gray-600 dark:text-gray-400 font-semibold">{prebuildId}</span>
</div>
)}
</div>
Expand Down Expand Up @@ -237,8 +252,8 @@ export default function Menu() {
</div>
</div>
</div>
{!isMinimalUI && showTeamsUI && <div className="flex">
{leftMenu.map(entry => <TabMenuItem name={entry.title} selected={isSelected(entry, location)} link={entry.link}/>)}
{!isMinimalUI && showTeamsUI && !prebuildId && <div className="flex">
{leftMenu.map((entry: Entry) => <TabMenuItem name={entry.title} selected={isSelected(entry, location)} link={entry.link}/>)}
</div>}
</header>
{showTeamsUI && <Separator />}
Expand Down
10 changes: 6 additions & 4 deletions components/dashboard/src/components/DropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ export interface DropDownProps {
prefix?: string;
contextMenuWidth?: string;
activeEntry?: string,
entries: {
title: string,
onClick: ()=>void
}[];
entries: DropDownEntry[];
}

export interface DropDownEntry {
title: string,
onClick: ()=>void
}

function Arrow(props: {up: boolean}) {
Expand Down
8 changes: 4 additions & 4 deletions components/dashboard/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
import Separator from "./Separator";

export interface HeaderProps {
title: string;
subtitle: string;
title: string | React.ReactElement;
subtitle: string | React.ReactElement;
}

export default function Header(p: HeaderProps) {
return <div className="lg:px-28 px-10 border-gray-200 dark:border-gray-800">
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: We'll need a spacing of 4 below the header here. mayeb this is something we need to add on the header component?

BEFORE AFTER
header-before header-after

<div className="flex pb-8 pt-6">
<div className="">
<h1 className="tracking-tight">{p.title}</h1>
<h2 className="tracking-wide">{p.subtitle}</h2>
{typeof p.title === "string" ? (<h1 className="tracking-tight">{p.title}</h1>) : p.title}
{typeof p.subtitle === "string" ? (<h2 className="tracking-wide">{p.subtitle}</h2>) : p.subtitle}
Copy link
Contributor

Choose a reason for hiding this comment

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

thought: Adding this comment to the closest related element. Do you think a) renaming the header title and adding a link to the project in the overview page could help here? Bringing this up as there's no other indication what this is list contains besides the active branches reference in the seach input below? Feel free to leave this as is for now.

BEFORE AFTER
header-before header-after

</div>
</div>
<Separator />
Expand Down
20 changes: 9 additions & 11 deletions components/dashboard/src/components/PrebuildLogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import EventEmitter from "events";
import React, { Suspense, useEffect, useState } from "react";
import { Workspace, WorkspaceInstance, DisposableCollection, WorkspaceImageBuild, GitpodServer, HEADLESS_LOG_STREAM_STATUS_CODE_REGEX } from "@gitpod/gitpod-protocol";
import { Workspace, WorkspaceInstance, DisposableCollection, WorkspaceImageBuild, HEADLESS_LOG_STREAM_STATUS_CODE_REGEX } from "@gitpod/gitpod-protocol";
import { getGitpodService } from "../service/service";

const WorkspaceLogs = React.lazy(() => import('./WorkspaceLogs'));
Expand All @@ -15,8 +15,7 @@ export default function PrebuildLogs(props: { workspaceId?: string }) {
const [ workspace, setWorkspace ] = useState<Workspace | undefined>();
const [ workspaceInstance, setWorkspaceInstance ] = useState<WorkspaceInstance | undefined>();
const [ error, setError ] = useState<Error | undefined>();
const logsEmitter = new EventEmitter();
const service = getGitpodService();
const [ logsEmitter ] = useState(new EventEmitter());
Copy link
Member Author

Choose a reason for hiding this comment

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

@jankeromnes logs were sent to the wrong emitter. const values should not be state. now I can see logs and log output for prebuilds 👍🏻

Copy link
Contributor

Choose a reason for hiding this comment

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

Aha, exciting!


useEffect(() => {
const disposables = new DisposableCollection();
Expand All @@ -25,12 +24,12 @@ export default function PrebuildLogs(props: { workspaceId?: string }) {
return;
}
try {
const info = await service.server.getWorkspace(props.workspaceId);
const info = await getGitpodService().server.getWorkspace(props.workspaceId);
if (info.latestInstance) {
setWorkspace(info.workspace);
setWorkspaceInstance(info.latestInstance);
}
disposables.push(service.registerClient({
disposables.push(getGitpodService().registerClient({
onInstanceUpdate: setWorkspaceInstance,
onWorkspaceImageBuildLogs: (info: WorkspaceImageBuild.StateInfo, content?: WorkspaceImageBuild.LogContent) => {
if (!content) {
Expand All @@ -40,7 +39,7 @@ export default function PrebuildLogs(props: { workspaceId?: string }) {
},
}));
if (info.latestInstance) {
disposables.push(watchHeadlessLogs(service.server, info.latestInstance.id, chunk => {
disposables.push(watchHeadlessLogs(info.latestInstance.id, chunk => {
logsEmitter.emit('logs', chunk);
}, async () => workspaceInstance?.status.phase === 'stopped'));
}
Expand All @@ -64,7 +63,7 @@ export default function PrebuildLogs(props: { workspaceId?: string }) {
// Preparing means that we haven't actually started the workspace instance just yet, but rather
// are still preparing for launch. This means we're building the Docker image for the workspace.
case "preparing":
service.server.watchWorkspaceImageBuildLogs(workspace!.id);
getGitpodService().server.watchWorkspaceImageBuildLogs(workspace!.id);
break;

// Pending means the workspace does not yet consume resources in the cluster, but rather is looking for
Expand Down Expand Up @@ -100,7 +99,7 @@ export default function PrebuildLogs(props: { workspaceId?: string }) {

// Stopped means the workspace ended regularly because it was shut down.
case "stopped":
service.server.watchWorkspaceImageBuildLogs(workspace!.id);
getGitpodService().server.watchWorkspaceImageBuildLogs(workspace!.id);
break;
}
if (workspaceInstance?.status.conditions.failed) {
Expand All @@ -109,7 +108,6 @@ export default function PrebuildLogs(props: { workspaceId?: string }) {
}, [ workspaceInstance?.status.phase ]);

return <>
<div className="capitalize">{workspaceInstance?.status.phase}</div>
<Suspense fallback={<div />}>
<WorkspaceLogs classes="h-64 w-full" logsEmitter={logsEmitter} errorMessage={error?.message} />
</Suspense>
Expand All @@ -121,7 +119,7 @@ export default function PrebuildLogs(props: { workspaceId?: string }) {
</>;
}

export function watchHeadlessLogs(server: GitpodServer, instanceId: string, onLog: (chunk: string) => void, checkIsDone: () => Promise<boolean>): DisposableCollection {
export function watchHeadlessLogs(instanceId: string, onLog: (chunk: string) => void, checkIsDone: () => Promise<boolean>): DisposableCollection {
const disposables = new DisposableCollection();

const startWatchingLogs = async () => {
Expand All @@ -140,7 +138,7 @@ export function watchHeadlessLogs(server: GitpodServer, instanceId: string, onLo
let response: Response | undefined = undefined;
let reader: ReadableStreamDefaultReader<Uint8Array> | undefined = undefined;
try {
const logSources = await server.getHeadlessLog(instanceId);
const logSources = await getGitpodService().server.getHeadlessLog(instanceId);
// TODO(gpl) Only listening on first stream for now
const streamIds = Object.keys(logSources.streams);
if (streamIds.length < 1) {
Expand Down
3 changes: 3 additions & 0 deletions components/dashboard/src/icons/CaretUpDown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions components/dashboard/src/projects/ConfigureProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React, { Suspense, useContext, useEffect, useState } from "react";
import { useLocation, useRouteMatch } from "react-router";
import { CreateWorkspaceMode, ProjectInfo, WorkspaceCreationResult } from "@gitpod/gitpod-protocol";
import { CreateWorkspaceMode, Project, WorkspaceCreationResult } from "@gitpod/gitpod-protocol";
import PrebuildLogs from "../components/PrebuildLogs";
import TabMenuItem from "../components/TabMenuItem";
import { getGitpodService } from "../service/service";
Expand Down Expand Up @@ -53,7 +53,7 @@ export default function () {
const location = useLocation();
const team = getCurrentTeam(location, teams);
const routeMatch = useRouteMatch<{ teamSlug: string, projectSlug: string }>("/:teamSlug/:projectSlug/configure");
const [ project, setProject ] = useState<ProjectInfo | undefined>();
const [ project, setProject ] = useState<Project | undefined>();
const [ gitpodYml, setGitpodYml ] = useState<string>('');
const [ dockerfile, setDockerfile ] = useState<string>('');
const [ editorError, setEditorError ] = useState<React.ReactNode | null>(null);
Expand Down
12 changes: 8 additions & 4 deletions components/dashboard/src/projects/NewProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,15 @@ export default function NewProject() {
<div className="text-base text-gray-900 dark:text-gray-50 font-medium rounded-xl whitespace-nowrap">{toSimpleName(r.name)}</div>
<p>Updated {moment(r.updatedAt).fromNow()}</p>
</div>
<div className="flex justify-end">
<div className="h-full my-auto flex self-center opacity-0 group-hover:opacity-100">
<button className="primary" onClick={() => setSelectedRepo(r.name)}>Select</button>
<div className="flex justify-end">
<div className="h-full my-auto flex self-center opacity-0 group-hover:opacity-100">
{!r.inUse ? (
<button className="primary" onClick={() => setSelectedRepo(r.name)}>Select</button>
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: Specs for repository selection are being updated and we no longer need the primary button on hover, see #4948. However, this is probably out of the scope these changes. For the secondary option below we can use a tooltip on hover to indicate a projects is already taken. 💡

) : (
<p className="my-auto">already taken</p>
)}
</div>
</div>
</div>
</div>
))}
</div>
Expand Down
78 changes: 78 additions & 0 deletions components/dashboard/src/projects/Prebuild.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Copyright (c) 2021 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

import moment from "moment";
import { PrebuildInfo } from "@gitpod/gitpod-protocol";
import { useContext, useEffect, useState } from "react";
import { useLocation, useRouteMatch } from "react-router";
import Header from "../components/Header";
import { getGitpodService } from "../service/service";
import { TeamsContext, getCurrentTeam } from "../teams/teams-context";
import { prebuildStatusIcon, prebuildStatusLabel } from "./Prebuilds";
import PrebuildLogs from "../components/PrebuildLogs";
import { shortCommitMessage } from "./render-utils";

export default function () {
const { teams } = useContext(TeamsContext);
const location = useLocation();
const match = useRouteMatch<{ team: string, project: string, prebuildId: string }>("/:team/:project/:prebuildId");
const projectName = match?.params?.project;
const prebuildId = match?.params?.prebuildId;
const team = getCurrentTeam(location, teams);

const [prebuild, setPrebuild] = useState<PrebuildInfo | undefined>();

useEffect(() => {
if (!team || !projectName || !prebuildId) {
return;
}
(async () => {
const prebuilds = await getGitpodService().server.findPrebuilds({
projectName,
teamId: team.id,
prebuildId
});
setPrebuild(prebuilds[0]);
})();
}, [team]);


const renderTitle = () => {
if (!prebuild) {
return "unknown prebuild";
}
return (<h1 className="tracking-tight">{prebuild.branch} <span className="text-gray-200">#{prebuild.branchPrebuildNumber}</span></h1>);
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: Minor color fix. 🖍️

Suggested change
return (<h1 className="tracking-tight">{prebuild.branch} <span className="text-gray-200">#{prebuild.branchPrebuildNumber}</span></h1>);
return (<h1 className="tracking-tight">{prebuild.branch} <span className="text-gray-400">#{prebuild.branchPrebuildNumber}</span></h1>);

};

const renderSubtitle = () => {
if (!prebuild) {
return "";
}
const statusIcon = prebuildStatusIcon(prebuild.status);
const status = prebuildStatusLabel(prebuild.status);
const startedByAvatar = prebuild.startedByAvatar && <img className="rounded-full w-4 h-4 inline-block align-text-bottom mr-2" src={prebuild.startedByAvatar || ''} alt={prebuild.startedBy} />;
return (<div className="flex">
<div className="text-base text-gray-900 dark:text-gray-50 font-medium uppercase">
<div className="inline-block align-text-bottom mr-2 w-4 h-4">{statusIcon}</div>
{status}
</div>
<p className="mx-2 my-auto">·</p>
<div className="my-auto">
<p>{startedByAvatar}Triggered {moment(prebuild.startedAt).fromNow()}</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

question: Is it expected to see the avatar missing from everywhere?

</div>
<p className="mx-2 my-auto">·</p>
<div className="my-auto">
<p className="text-gray-500 dark:text-gray-50">{shortCommitMessage(prebuild.changeTitle)}</p>
</div>
</div>)
};

return <>
<Header title={renderTitle()} subtitle={renderSubtitle()} />
<div className="w-full"><PrebuildLogs workspaceId={prebuild?.buildWorkspaceId}/></div>
</>

}
Loading