Skip to content

Allow project search on admin dashboard #7882

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 2 commits into from
Feb 1, 2022
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
2 changes: 2 additions & 0 deletions components/dashboard/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const FromReferrer = React.lazy(() => import(/* webpackPrefetch: true */ './From
const UserSearch = React.lazy(() => import(/* webpackPrefetch: true */ './admin/UserSearch'));
const WorkspacesSearch = React.lazy(() => import(/* webpackPrefetch: true */ './admin/WorkspacesSearch'));
const AdminSettings = React.lazy(() => import(/* webpackPrefetch: true */ './admin/Settings'));
const ProjectsSearch = React.lazy(() => import(/* webpackPrefetch: true */ './admin/ProjectsSearch'));
const OAuthClientApproval = React.lazy(() => import(/* webpackPrefetch: true */ './OauthClientApproval'));

function Loading() {
Expand Down Expand Up @@ -288,6 +289,7 @@ function App() {
<Route path="/admin/users" component={UserSearch} />
<Route path="/admin/workspaces" component={WorkspacesSearch} />
<Route path="/admin/settings" component={AdminSettings} />
<Route path="/admin/projects" component={ProjectsSearch} />

<Route path={["/", "/login"]} exact>
<Redirect to={workspacesPathMain} />
Expand Down
44 changes: 44 additions & 0 deletions components/dashboard/src/admin/ProjectDetail.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (c) 2022 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 { Link } from "react-router-dom";
import { Project } from "@gitpod/gitpod-protocol";
import Prebuilds from "../projects/Prebuilds"
import Property from "./Property";

export default function ProjectDetail(props: { project: Project, owner: string | undefined }) {
return <>
<div className="flex">
<div className="flex-1">
<div className="flex"><h3>{props.project.name}</h3><span className="my-auto"></span></div>
<p>{props.project.cloneUrl}</p>
</div>
</div>
<div className="flex flex-col w-full -ml-3">
<div className="flex w-full mt-6">
<Property name="Created">{moment(props.project.creationTime).format('MMM D, YYYY')}</Property>
<Property name="Repository"><a className="text-blue-400 dark:text-blue-600 hover:text-blue-600 dark:hover:text-blue-400 truncate" href={props.project.cloneUrl}>{props.project.name}</a></Property>
{props.project.userId ?
<Property name="Owner">
<>
<Link className="text-blue-400 dark:text-blue-600 hover:text-blue-600 dark:hover:text-blue-400 truncate" to={"/admin/users/" + props.project.userId}>{props.owner}</Link>
<span className="text-gray-400 dark:text-gray-500"> (User)</span>
</>
</Property>
:
<Property name="Owner">{`${props.owner} (Team)`}</Property>}
</div>
<div className="flex w-full mt-6">
<Property name="Incremental Prebuilds">{props.project.settings?.useIncrementalPrebuilds ? "Yes" : "No"}</Property>
<Property name="Marked Deleted">{props.project.markedDeleted ? "Yes" : "No"}</Property>
</div>
</div>
<div className="mt-6">
<Prebuilds project={props.project} isAdminDashboard={true} />
</div>
</>;
}
132 changes: 132 additions & 0 deletions components/dashboard/src/admin/ProjectsSearch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/**
* Copyright (c) 2022 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 { useLocation } from "react-router";
import { Link, Redirect } from "react-router-dom";
import { useContext, useState, useEffect } from "react";

import { adminMenu } from "./admin-menu";
import ProjectDetail from "./ProjectDetail";
import { UserContext } from "../user-context";
import { getGitpodService } from "../service/service";
import { PageWithSubMenu } from "../components/PageWithSubMenu";
import { AdminGetListResult, Project } from "@gitpod/gitpod-protocol";

export default function ProjectsSearchPage() {
return (
<PageWithSubMenu subMenu={adminMenu} title="Projects" subtitle="Search and manage all projects.">
<ProjectsSearch />
</PageWithSubMenu>
)
}

export function ProjectsSearch() {
const location = useLocation();
const { user } = useContext(UserContext);
const [searchTerm, setSearchTerm] = useState('');
const [searching, setSearching] = useState(false);
const [searchResult, setSearchResult] = useState<AdminGetListResult<Project>>({ total: 0, rows: [] });
const [currentProject, setCurrentProject] = useState<Project | undefined>(undefined);
const [currentProjectOwner, setCurrentProjectOwner] = useState<string | undefined>("");

useEffect(() => {
const projectId = location.pathname.split('/')[3];
if (projectId && searchResult) {
let currentProject = searchResult.rows.find(project => project.id === projectId);
if (currentProject) {
setCurrentProject(currentProject);
} else {
getGitpodService().server.adminGetProjectById(projectId)
.then(project => setCurrentProject(project))
.catch(e => console.error(e));
}
} else {
setCurrentProject(undefined);
}
}, [location]);

useEffect(() => {
(async () => {
if (currentProject) {
if (currentProject.userId) {
const owner = await getGitpodService().server.adminGetUser(currentProject.userId);
if (owner) { setCurrentProjectOwner(owner?.name) }
}
if (currentProject.teamId) {
const owner = await getGitpodService().server.adminGetTeamById(currentProject.teamId);
if (owner) { setCurrentProjectOwner(owner?.name) }
}
}
})();
}, [currentProject])

if (!user || !user?.rolesOrPermissions?.includes('admin')) {
return <Redirect to="/" />
}

if (currentProject) {
return <ProjectDetail project={currentProject} owner={currentProjectOwner} />;
}

const search = async () => {
setSearching(true);
try {
const result = await getGitpodService().server.adminGetProjectsBySearchTerm({
searchTerm,
limit: 50,
orderBy: 'creationTime',
offset: 0,
orderDir: "desc"
})
setSearchResult(result);
} finally {
setSearching(false);
}
}

return <>
<div className="pt-8 flex">
<div className="flex justify-between w-full">
<div className="flex">
<div className="py-4">
<svg className={searching ? 'animate-spin' : ''} width="16" height="16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fillRule="evenodd" clipRule="evenodd" d="M6 2a4 4 0 100 8 4 4 0 000-8zM0 6a6 6 0 1110.89 3.477l4.817 4.816a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 010 6z" fill="#A8A29E" />
</svg>
</div>
<input type="search" placeholder="Search Projects" onKeyDown={(k) => k.key === 'Enter' && search()} onChange={(v) => { setSearchTerm(v.target.value) }} />
Copy link
Contributor

Choose a reason for hiding this comment

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

issue(non-blocking): The issue about state handling that @jldec mentioned in #7882 (comment) is valid but also visible when searching users or workspaces. If this is an online-fix let's include it here but probably not worth blocking this PR as it seems to be out of the scope of the changes here. 🏀

Copy link
Contributor

Choose a reason for hiding this comment

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

ok - agree.

</div>
<button disabled={searching} onClick={search}>Search</button>
</div>
</div>
<div className="flex flex-col space-y-2">
<div className="px-6 py-3 flex justify-between text-sm text-gray-400 border-t border-b border-gray-200 dark:border-gray-800 mb-2">
<div className="w-4/12">Name</div>
<div className="w-6/12">Clone URL</div>
<div className="w-2/12">Created</div>
</div>
{searchResult.rows.map(project => <ProjectResultItem project={project} />)}
</div>
</>

function ProjectResultItem(p: { project: Project }) {
return (
<Link key={'pr-' + p.project.name} to={'/admin/projects/' + p.project.id} data-analytics='{"button_type":"sidebar_menu"}'>
<div className="rounded-xl whitespace-nowrap flex py-6 px-6 w-full justify-between hover:bg-gray-100 dark:hover:bg-gray-800 focus:bg-gitpod-kumquat-light group">
<div className="flex flex-col w-4/12 truncate">
<div className="font-medium text-gray-800 dark:text-gray-100 truncate">{p.project.name}</div>
</div>
<div className="flex flex-col w-6/12 truncate">
<div className="text-gray-500 dark:text-gray-100 truncate">{p.project.cloneUrl}</div>
</div>
<div className="flex w-2/12 self-center">
<div className="text-sm w-full text-gray-400 truncate">{moment(p.project.creationTime).fromNow()}</div>
</div>
</div>
</Link>
)
}
}
25 changes: 25 additions & 0 deletions components/dashboard/src/admin/Property.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2022 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 { ReactChild } from 'react';

function Property(p: { name: string, children: string | ReactChild, actions?: { label: string, onClick: () => void }[] }) {
return <div className="ml-3 flex flex-col w-4/12 truncate">
<div className="text-base text-gray-500 truncate">
{p.name}
</div>
<div className="text-lg text-gray-600 font-semibold truncate">
{p.children}
</div>
{(p.actions || []).map(a =>
<div className="cursor-pointer text-sm text-blue-400 dark:text-blue-600 hover:text-blue-600 dark:hover:text-blue-400 truncate" onClick={a.onClick}>
{a.label || ''}
</div>
)}
</div>;
}

export default Property;
19 changes: 2 additions & 17 deletions components/dashboard/src/admin/UserDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import { NamedWorkspaceFeatureFlag, Permissions, RoleOrPermission, Roles, User,
import { AccountStatement, Subscription } from "@gitpod/gitpod-protocol/lib/accounting-protocol";
import { Plans } from "@gitpod/gitpod-protocol/lib/plans";
import moment from "moment";
import { ReactChild, useEffect, useRef, useState } from "react";
import { useEffect, useRef, useState } from "react";
import CheckBox from "../components/CheckBox";
import Modal from "../components/Modal";
import { PageWithSubMenu } from "../components/PageWithSubMenu"
import { getGitpodService } from "../service/service";
import { adminMenu } from "./admin-menu"
import { WorkspaceSearch } from "./WorkspacesSearch";
import Property from "./Property";


export default function UserDetail(p: { user: User }) {
Expand Down Expand Up @@ -199,22 +200,6 @@ function Label(p: { text: string, color: string }) {
return <div className={`ml-3 text-sm text-${p.color}-600 truncate bg-${p.color}-100 px-1.5 py-0.5 rounded-md my-auto`}>{p.text}</div>;
}

export function Property(p: { name: string, children: string | ReactChild, actions?: { label: string, onClick: () => void }[] }) {
return <div className="ml-3 flex flex-col w-4/12 truncate">
<div className="text-base text-gray-500 truncate">
{p.name}
</div>
<div className="text-lg text-gray-600 font-semibold truncate">
{p.children}
</div>
{(p.actions || []).map(a =>
<div className="cursor-pointer text-sm text-blue-400 dark:text-blue-600 hover:text-blue-600 dark:hover:text-blue-400 truncate" onClick={a.onClick}>
{a.label || ''}
</div>
)}
</div>;
}

interface Entry {
title: string,
checked: boolean,
Expand Down
2 changes: 1 addition & 1 deletion components/dashboard/src/admin/WorkspaceDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Link } from "react-router-dom";
import { getGitpodService } from "../service/service";
import { getProject, WorkspaceStatusIndicator } from "../workspaces/WorkspaceEntry";
import { getAdminLinks } from "./gcp-info";
import { Property } from "./UserDetail";
import Property from "./Property";

export default function WorkspaceDetail(props: { workspace: WorkspaceAndInstance }) {
const [workspace, setWorkspace] = useState(props.workspace);
Expand Down
28 changes: 18 additions & 10 deletions components/dashboard/src/admin/admin-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@
* See License-AGPL.txt in the project root for license information.
*/

export const adminMenu = [{
title: 'Users',
link: ['/admin/users', '/admin']
}, {
title: 'Workspaces',
link: ['/admin/workspaces']
}, {
title: 'Settings',
link: ['/admin/settings']
},];
export const adminMenu = [
{
title: 'Users',
link: ['/admin/users', '/admin']
},
{
title: 'Workspaces',
link: ['/admin/workspaces']
},
{
title: 'Projects',
link: ['/admin/projects']
},
{
title: 'Settings',
link: ['/admin/settings']
}
];
Loading