Skip to content

Commit

Permalink
Merge pull request #854 from OpenSourceBrain/feature/435
Browse files Browse the repository at this point in the history
feature/435 - add confirmation dialog for Repository delete
  • Loading branch information
filippomc authored Dec 21, 2023
2 parents 6336b0c + 49e4518 commit fef25c6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
16 changes: 9 additions & 7 deletions applications/osb-portal/src/components/dialogs/DeleteDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ import { Button } from "@mui/material";
const DeleteDialog = ({
open,
setOpen,
workspace,
handleDeleteWorkspace,
title,
description,
handleDeleteCallback,
navigateToPath
}) => {
const navigate = useNavigate();

const handleDelete = () => {
handleDeleteWorkspace();
if (window.location.pathname !== "/") {
navigate("/");
handleDeleteCallback();
if (navigateToPath && window.location.pathname !== "/") {
navigate(navigateToPath)
}
}

Expand All @@ -29,8 +31,8 @@ const DeleteDialog = ({
open={open}
onClose={() => setOpen(false)}
>
<DialogTitle>{'Delete Workspace "' + workspace.name + '"'}</DialogTitle>
<DialogContent>{'You are about to delete Workspace "' + workspace.name + '". This action cannot be undone. Are you sure?'}</DialogContent>
<DialogTitle>{title}</DialogTitle>
<DialogContent>{description}</DialogContent>
<DialogActions>
<Button
color="primary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { styled } from "@mui/styles";
import { chipBg } from "../../theme";
import IconButton from "@mui/material/IconButton";
import RepositoryService from "../../service/RepositoryService";
import DeleteDialog from "../dialogs/DeleteDialog";


interface RepositoryActionsMenuProps {
repository: OSBRepository;
Expand All @@ -37,6 +39,7 @@ const ThreeDotButton = styled(Button)(({ theme }) => ({
export default (props: RepositoryActionsMenuProps) => {
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const [repositoryEditorOpen, setRepositoryEditorOpen] = React.useState(false);
const [showDeleteRepositoryDialog, setShowDeleteRepositoryDialog] = React.useState(false);

const canEdit = canEditRepository(props.user, props.repository);
const navigate = useNavigate();
Expand Down Expand Up @@ -96,7 +99,10 @@ export default (props: RepositoryActionsMenuProps) => {
{canEdit && (
<MenuItem
className="open-repository"
onClick={handleDeleteRepository}
onClick={() => {
setShowDeleteRepositoryDialog(true);
setAnchorEl(null);
}}
>
Delete
</MenuItem>
Expand All @@ -113,6 +119,19 @@ export default (props: RepositoryActionsMenuProps) => {
repository={props.repository}
/>
)}

{
showDeleteRepositoryDialog && (
<DeleteDialog
open={showDeleteRepositoryDialog}
setOpen={setShowDeleteRepositoryDialog}
handleDeleteCallback={handleDeleteRepository}
navigateToPath={'/repositories'}
title={'Delete Repository "' + props.repository.name + '"'}
description={'You are about to delete Repository "' + props.repository.name + '". This action cannot be undone. Are you sure?'}
/>
)
}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,10 @@ export default (props: WorkspaceActionsMenuProps) => {
<DeleteDialog
open={showDeleteWorkspaceDialog}
setOpen={setShowDeleteWorkspaceDialog}
handleDeleteWorkspace={handleDeleteWorkspace}
workspace={props.workspace}
handleDeleteCallback={handleDeleteWorkspace}
navigateToPath="/"
title={'Delete Workspace "' + props.workspace.name + '"'}
description={'You are about to delete Workspace "' + props.workspace.name + '". This action cannot be undone. Are you sure?'}
/>
)
}
Expand Down

0 comments on commit fef25c6

Please sign in to comment.