Skip to content

Commit

Permalink
src: Add confirmation dialog for deleting repos
Browse files Browse the repository at this point in the history
  • Loading branch information
SludgeGirl committed Feb 14, 2025
1 parent 12ddee4 commit d87c6a6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/components/confirmation_dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from "react";
import { Button, Modal } from "@patternfly/react-core";
import { useDialogs } from "dialogs";

import cockpit from "cockpit";

const _ = cockpit.gettext;

export const ConfirmationDialog = ({
title,
callback,
content,
}: {
title: string;
callback: () => void;
content: React.ReactNode | undefined;
}) => {
const Dialogs = useDialogs();

return (
<Modal
title={title}
variant="small"
onClose={Dialogs.close}
isOpen
footer={
<>
<Button
variant="danger"
onClick={callback}
aria-label={title}
>
{_("Delete")}
</Button>
<Button
variant="link"
className="btn-cancel"
onClick={Dialogs.close}
>
{_("Cancel")}
</Button>
</>
}
>
{content}
</Modal>
);
};
3 changes: 3 additions & 0 deletions src/components/repo_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useDialogs } from "dialogs";
import { BanIcon, CheckIcon } from "@patternfly/react-icons";
import { RepoDialog } from "./repo_dialog";
import { RepoChangesContext } from "../app";
import { ConfirmationDialog } from "./confirmation_dialog";

const _ = cockpit.gettext;

Expand Down Expand Up @@ -81,10 +82,12 @@ const RepoActions = ({ backend, repo }: { backend: Backend; repo: Repo }) => {
<DropdownItem
key="delete-repo"
onClick={() => {
Dialogs.show(<ConfirmationDialog title={cockpit.format(_("Delete $0?"), repo.name)} callback={() => {
backend.deleteRepo(repo).then(() => {
if (setReposChanged && reposChanged !== null)
setReposChanged(reposChanged + 1);
});
}}/>)
}}
>
{_("Delete repo")}
Expand Down

0 comments on commit d87c6a6

Please sign in to comment.