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

feature/435 - add confirmation dialog for Repository delete #854

Merged
merged 1 commit into from
Dec 21, 2023
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
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
Loading