This commit is contained in:
Eduard Heimbuch
2020-11-11 17:20:13 +01:00
parent f93c9f3e7c
commit 595d97b211
5 changed files with 12 additions and 13 deletions

View File

@@ -31,7 +31,7 @@ import { useTranslation } from "react-i18next";
type Props = {
baseUrl: string;
branch: Branch;
onDelete: (url: string) => void;
onDelete: (branch: Branch) => void;
};
const BranchRow: FC<Props> = ({ baseUrl, branch, onDelete }) => {
@@ -40,9 +40,8 @@ const BranchRow: FC<Props> = ({ baseUrl, branch, onDelete }) => {
let deleteButton;
if ((branch?._links?.delete as Link)?.href) {
const url = (branch._links.delete as Link).href;
deleteButton = (
<a className="level-item" onClick={() => onDelete(url)}>
<a className="level-item" onClick={() => onDelete(branch)}>
<span className="icon is-small">
<Icon name="trash" className="fas" title={t("branch.delete.button")} />
</span>

View File

@@ -24,7 +24,7 @@
import React, { FC, useState } from "react";
import { useTranslation } from "react-i18next";
import BranchRow from "./BranchRow";
import { Branch } from "@scm-manager/ui-types";
import { Branch, Link } from "@scm-manager/ui-types";
import { apiClient, ConfirmAlert, ErrorNotification } from "@scm-manager/ui-components";
type Props = {
@@ -37,21 +37,21 @@ const BranchTable: FC<Props> = ({ baseUrl, branches, fetchBranches }) => {
const [t] = useTranslation("repos");
const [showConfirmAlert, setShowConfirmAlert] = useState(false);
const [error, setError] = useState<Error | undefined>();
const [deleteBranchUrl, setDeleteBranchUrl] = useState("");
const [branchToBeDeleted, setBranchToBeDeleted] = useState<Branch | undefined>();
const onDelete = (url: string) => {
setDeleteBranchUrl(url);
const onDelete = (branch: Branch) => {
setBranchToBeDeleted(branch);
setShowConfirmAlert(true);
};
const abortDelete = () => {
setDeleteBranchUrl("");
setBranchToBeDeleted(undefined);
setShowConfirmAlert(false);
};
const deleteBranch = () => {
apiClient
.delete(deleteBranchUrl)
.delete((branchToBeDeleted?._links.delete as Link).href)
.then(() => fetchBranches())
.catch(setError);
};
@@ -69,7 +69,7 @@ const BranchTable: FC<Props> = ({ baseUrl, branches, fetchBranches }) => {
const confirmAlert = (
<ConfirmAlert
title={t("branch.delete.confirmAlert.title")}
message={t("branch.delete.confirmAlert.message")}
message={t("branch.delete.confirmAlert.message", { branch: branchToBeDeleted?.name })}
buttons={[
{
className: "is-outlined",

View File

@@ -52,7 +52,7 @@ const DeleteBranch: FC<Props> = ({ repository, branch }: Props) => {
const confirmAlert = (
<ConfirmAlert
title={t("branch.delete.confirmAlert.title")}
message={t("branch.delete.confirmAlert.message")}
message={t("branch.delete.confirmAlert.message", { branch: branch.name })}
buttons={[
{
className: "is-outlined",