Add an extension point for contributor rows in contributor table

Co-authored-by: Rene Pfeuffer<rene.pfeuffer@cloudogu.com>
This commit is contained in:
Anna Vetcininova
2024-11-07 09:19:24 +01:00
parent f05aabc943
commit df0582dfd8
6 changed files with 111 additions and 55 deletions

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 2020 - present Cloudogu GmbH
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
import React, { FC } from "react";
import { Person } from "@scm-manager/ui-types";
import { useTranslation } from "react-i18next";
import { extensionPoints, useBinder } from "@scm-manager/ui-extensions";
import ContributorAvatar from "./ContributorAvatar";
const Contributor: FC<{ person: Person }> = ({ person }) => {
const [t] = useTranslation("repos");
const binder = useBinder();
const avatarFactory = binder.getExtension<extensionPoints.AvatarFactory>("avatar.factory");
let prefix = null;
if (avatarFactory) {
const avatar = avatarFactory(person);
if (avatar) {
prefix = (
<>
<ContributorAvatar src={avatar} alt={person.name} />{" "}
</>
);
}
}
if (person.mail) {
return (
<a href={"mailto:" + person.mail} title={t("changeset.contributors.mailto") + " " + person.mail}>
{prefix}
{person.name}
</a>
);
}
return <>{person.name}</>;
};
export default Contributor;

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2020 - present Cloudogu GmbH
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
import React, { FC } from "react";
import styled from "styled-components";
const SizedTd = styled.td`
width: 10rem;
`;
const ContributorRow: FC<{ label: string }> = ({ label, children }) => {
return (
<tr key={label}>
<SizedTd>{label}:</SizedTd>
<td className="is-ellipsis-overflow m-0">{children}</td>
</tr>
);
};
export default ContributorRow;

View File

@@ -31,3 +31,5 @@ export { default as ChangesetTagsCollapsed } from "./ChangesetTagsCollapsed";
export { default as ContributorAvatar } from "./ContributorAvatar";
export { default as SignatureIcon } from "./SignatureIcon";
export { default as SingleChangeset } from "./SingleChangeset";
export { default as Contributor } from "./Contributor";
export { default as ContributorRow } from "./ContributorRow";