-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
</>; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) }} /> | ||
</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> | ||
laushinka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</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> | ||
) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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. 🏀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok - agree.