-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[dashboard] BlockedRepo UI #11446
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
[dashboard] BlockedRepo UI #11446
Changes from all commits
Commits
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,300 @@ | ||
/** | ||
* 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 { AdminGetListResult } from "@gitpod/gitpod-protocol"; | ||
import { useEffect, useRef, useState } from "react"; | ||
import { getGitpodService } from "../service/service"; | ||
import { PageWithAdminSubMenu } from "./PageWithAdminSubMenu"; | ||
import { BlockedRepository } from "@gitpod/gitpod-protocol/lib/blocked-repositories-protocol"; | ||
import ConfirmationModal from "../components/ConfirmationModal"; | ||
import Modal from "../components/Modal"; | ||
import CheckBox from "../components/CheckBox"; | ||
import { ItemFieldContextMenu } from "../components/ItemsList"; | ||
import { ContextMenuEntry } from "../components/ContextMenu"; | ||
|
||
export function BlockedRepositories() { | ||
return ( | ||
<PageWithAdminSubMenu title="Blocked Repositories" subtitle="Search and manage all blocked repositories."> | ||
<BlockedRepositoriesList /> | ||
</PageWithAdminSubMenu> | ||
); | ||
} | ||
|
||
type NewBlockedRepository = Pick<BlockedRepository, "urlRegexp" | "blockUser">; | ||
type ExistingBlockedRepository = Pick<BlockedRepository, "id" | "urlRegexp" | "blockUser">; | ||
|
||
interface Props {} | ||
|
||
export function BlockedRepositoriesList(props: Props) { | ||
const [searchResult, setSearchResult] = useState<AdminGetListResult<BlockedRepository>>({ rows: [], total: 0 }); | ||
const [queryTerm, setQueryTerm] = useState(""); | ||
const [searching, setSearching] = useState(false); | ||
|
||
const [isAddModalVisible, setAddModalVisible] = useState(false); | ||
const [isDeleteModalVisible, setDeleteModalVisible] = useState(false); | ||
|
||
const [currentBlockedRepository, setCurrentBlockedRepository] = useState<ExistingBlockedRepository>({ | ||
id: 0, | ||
urlRegexp: "", | ||
blockUser: false, | ||
}); | ||
|
||
const search = async () => { | ||
setSearching(true); | ||
try { | ||
const result = await getGitpodService().server.adminGetBlockedRepositories({ | ||
limit: 100, | ||
orderBy: "urlRegexp", | ||
offset: 0, | ||
orderDir: "asc", | ||
searchTerm: queryTerm, | ||
}); | ||
setSearchResult(result); | ||
} finally { | ||
setSearching(false); | ||
} | ||
}; | ||
useEffect(() => { | ||
search(); // Initial list | ||
}, []); | ||
|
||
const add = () => { | ||
setCurrentBlockedRepository({ | ||
id: 0, | ||
urlRegexp: "", | ||
blockUser: false, | ||
}); | ||
setAddModalVisible(true); | ||
}; | ||
|
||
const save = async (blockedRepository: NewBlockedRepository) => { | ||
await getGitpodService().server.adminCreateBlockedRepository( | ||
blockedRepository.urlRegexp, | ||
blockedRepository.blockUser, | ||
); | ||
setAddModalVisible(false); | ||
search(); | ||
}; | ||
|
||
const validate = (blockedRepository: NewBlockedRepository): string | undefined => { | ||
if (blockedRepository.urlRegexp === "") { | ||
return "Empty RegEx!"; | ||
} | ||
}; | ||
|
||
const deleteBlockedRepository = async (blockedRepository: ExistingBlockedRepository) => { | ||
await getGitpodService().server.adminDeleteBlockedRepository(blockedRepository.id); | ||
search(); | ||
}; | ||
|
||
const confirmDeleteBlockedRepository = (blockedRepository: ExistingBlockedRepository) => { | ||
setCurrentBlockedRepository(blockedRepository); | ||
setAddModalVisible(false); | ||
setDeleteModalVisible(true); | ||
}; | ||
|
||
return ( | ||
<> | ||
{isAddModalVisible && ( | ||
<AddBlockedRepositoryModal | ||
blockedRepository={currentBlockedRepository} | ||
validate={validate} | ||
save={save} | ||
onClose={() => setAddModalVisible(false)} | ||
/> | ||
)} | ||
{isDeleteModalVisible && ( | ||
<DeleteBlockedRepositoryModal | ||
blockedRepository={currentBlockedRepository} | ||
deleteBlockedRepository={() => deleteBlockedRepository(currentBlockedRepository)} | ||
onClose={() => setDeleteModalVisible(false)} | ||
/> | ||
)} | ||
<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 by URL Regex" | ||
gtsiolis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
onKeyDown={(ke) => ke.key === "Enter" && search()} | ||
onChange={(v) => { | ||
setQueryTerm(v.target.value.trim()); | ||
}} | ||
/> | ||
geropl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</div> | ||
<div className="flex space-x-2"> | ||
<button onClick={add}>New Blocked Repository</button> | ||
</div> | ||
</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-9/12">Repository URL Regex</div> | ||
<div className="w-1/12">Block user</div> | ||
<div className="w-2/12">Delete</div> | ||
geropl marked this conversation as resolved.
Show resolved
Hide resolved
geropl marked this conversation as resolved.
Show resolved
Hide resolved
geropl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</div> | ||
{searchResult.rows.map((br) => ( | ||
<BlockedRepositoryEntry br={br} confirmedDelete={confirmDeleteBlockedRepository} /> | ||
))} | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
function BlockedRepositoryEntry(props: { br: BlockedRepository; confirmedDelete: (br: BlockedRepository) => void }) { | ||
const menuEntries: ContextMenuEntry[] = [ | ||
{ | ||
title: "Delete", | ||
onClick: () => props.confirmedDelete(props.br), | ||
}, | ||
]; | ||
return ( | ||
<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-9/12 truncate"> | ||
<span className="mr-3 text-lg text-gray-600 truncate">{props.br.urlRegexp}</span> | ||
</div> | ||
<div className="flex flex-col self-center w-1/12"> | ||
<CheckBox title={""} desc={""} checked={props.br.blockUser} disabled={true} /> | ||
</div> | ||
geropl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<div className="flex flex-col w-2/12"> | ||
<ItemFieldContextMenu menuEntries={menuEntries} /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
interface AddBlockedRepositoryModalProps { | ||
blockedRepository: NewBlockedRepository; | ||
validate: (blockedRepository: NewBlockedRepository) => string | undefined; | ||
save: (br: NewBlockedRepository) => void; | ||
onClose: () => void; | ||
} | ||
|
||
function AddBlockedRepositoryModal(p: AddBlockedRepositoryModalProps) { | ||
const [br, setBr] = useState({ ...p.blockedRepository }); | ||
const [error, setError] = useState(""); | ||
const ref = useRef(br); | ||
andrew-farries marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const update = (previous: Partial<NewBlockedRepository>) => { | ||
const newEnv = { ...ref.current, ...previous }; | ||
setBr(newEnv); | ||
ref.current = newEnv; | ||
}; | ||
|
||
useEffect(() => { | ||
setBr({ ...p.blockedRepository }); | ||
setError(""); | ||
}, [p.blockedRepository]); | ||
|
||
let save = (): boolean => { | ||
const v = ref.current; | ||
const newError = p.validate(v); | ||
if (!!newError) { | ||
setError(newError); | ||
return false; | ||
} | ||
|
||
p.save(v); | ||
p.onClose(); | ||
return true; | ||
}; | ||
|
||
return ( | ||
<Modal | ||
visible={true} | ||
title={"New Blocked Repository"} | ||
onClose={p.onClose} | ||
onEnter={save} | ||
buttons={[ | ||
<button className="secondary" onClick={p.onClose}> | ||
Cancel | ||
</button>, | ||
<button className="ml-2" onClick={save}> | ||
Add Blocked Repository | ||
</button>, | ||
]} | ||
> | ||
<Details br={br} update={update} error={error} /> | ||
</Modal> | ||
); | ||
} | ||
|
||
function DeleteBlockedRepositoryModal(props: { | ||
blockedRepository: ExistingBlockedRepository; | ||
deleteBlockedRepository: () => void; | ||
onClose: () => void; | ||
}) { | ||
return ( | ||
<ConfirmationModal | ||
title="Delete Blocked Repository" | ||
areYouSureText="Are you sure you want to delete this repository from the list?" | ||
geropl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
buttonText="Delete Blocked Repository" | ||
onClose={props.onClose} | ||
onConfirm={() => { | ||
props.deleteBlockedRepository(); | ||
props.onClose(); | ||
}} | ||
> | ||
<Details br={props.blockedRepository} /> | ||
</ConfirmationModal> | ||
); | ||
} | ||
|
||
function Details(props: { | ||
br: NewBlockedRepository; | ||
error?: string; | ||
update?: (pev: Partial<NewBlockedRepository>) => void; | ||
}) { | ||
return ( | ||
<div className="border-gray-200 dark:border-gray-800 -mx-6 px-6 py-4 flex flex-col"> | ||
{props.error ? ( | ||
<div className="bg-gitpod-kumquat-light rounded-md p-3 text-gitpod-red text-sm mb-2">{props.error}</div> | ||
) : null} | ||
<div> | ||
<h4>Repository URL RegEx</h4> | ||
<input | ||
autoFocus | ||
className="w-full" | ||
type="text" | ||
value={props.br.urlRegexp} | ||
disabled={!props.update} | ||
onChange={(v) => { | ||
if (!!props.update) { | ||
props.update({ urlRegexp: v.target.value }); | ||
} | ||
}} | ||
/> | ||
</div> | ||
<CheckBox | ||
geropl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
title={"Block User"} | ||
geropl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
desc={"Block any user that tries to open a workspace for a repository URL that matches this RegEx."} | ||
checked={props.br.blockUser} | ||
disabled={!props.update} | ||
onChange={(v) => { | ||
if (!!props.update) { | ||
props.update({ blockUser: v.target.checked }); | ||
} | ||
}} | ||
/> | ||
</div> | ||
); | ||
} |
15 changes: 0 additions & 15 deletions
15
components/dashboard/src/admin/BlockedRepositorySettings.tsx
This file was deleted.
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.
Uh oh!
There was an error while loading. Please reload this page.