diff --git a/scm-ui/ui-webapp/src/repos/branches/components/BranchListItem.tsx b/scm-ui/ui-webapp/src/repos/branches/components/BranchListItem.tsx index d8d6877956..0bfd84d927 100644 --- a/scm-ui/ui-webapp/src/repos/branches/components/BranchListItem.tsx +++ b/scm-ui/ui-webapp/src/repos/branches/components/BranchListItem.tsx @@ -22,18 +22,18 @@ * SOFTWARE. */ -import { Dialog, Menu } from "@scm-manager/ui-overlays"; -import { Icon } from "@scm-manager/ui-buttons"; -import { CardList, Card } from "@scm-manager/ui-layout"; +import { Card, CardList } from "@scm-manager/ui-layout"; import { Link } from "react-router-dom"; import { encodePart } from "../../sources/components/content/FileLink"; import { useKeyboardIteratorTarget } from "@scm-manager/ui-shortcuts"; import { Trans, useTranslation } from "react-i18next"; import { DateFromNow } from "@scm-manager/ui-components"; -import { ExtensionPoint, extensionPoints } from "@scm-manager/ui-extensions"; +import { ExtensionPoint, extensionPoints, useBinder } from "@scm-manager/ui-extensions"; import React, { FC } from "react"; import { Branch, BranchDetails, Repository } from "@scm-manager/ui-types"; import AheadBehindTag from "./AheadBehindTag"; +import { Dialog, Menu } from "@scm-manager/ui-overlays"; +import { Icon } from "@scm-manager/ui-buttons"; type Props = { branch: Branch; @@ -46,28 +46,45 @@ type Props = { const BranchListItem: FC = ({ branch, remove, isLoading, branchesDetails, baseUrl, repository }) => { const [t] = useTranslation("repos"); + const binder = useBinder(); const branchDetails = branchesDetails?.find(({ branchName }) => branchName === branch.name); + const canDelete = "delete" in branch._links; + const hasAction = + canDelete || + binder.hasExtension("branches.list.menu", { + repository, + branch, + }); + const hasDetails = + !branch.defaultBranch || + binder.hasExtension("branches.list.detail", { + branch, + branchDetails, + repository, + }); return ( - remove(branch)} isLoading={isLoading}> - {t("branch.delete.confirmAlert.submit")} - , - - {t("branch.delete.confirmAlert.cancel")} - , - ]} - > - trash - {t("branch.delete.button")} - + {canDelete ? ( + remove(branch)} isLoading={isLoading}> + {t("branch.delete.confirmAlert.submit")} + , + + {t("branch.delete.confirmAlert.cancel")} + , + ]} + > + trash + {t("branch.delete.button")} + + ) : null} name="branches.list.menu" props={{ @@ -100,29 +117,31 @@ const BranchListItem: FC = ({ branch, remove, isLoading, branchesDetails, }} /> - - - - {({ labelId }) => ( - <> - - {branch.defaultBranch ? null : t("branch.aheadBehind.label")} - - - - )} - - - name="branches.list.detail" - props={{ - repository, - branch, - branchDetails, - }} - renderAll - /> - - + {hasDetails ? ( + + + {!branch.defaultBranch ? ( + + {({ labelId }) => ( + <> + {t("branch.aheadBehind.label")} + + + )} + + ) : null} + + name="branches.list.detail" + props={{ + repository, + branch, + branchDetails, + }} + renderAll + /> + + + ) : null} ); };