/* * 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 { Changeset, Person } from "@scm-manager/ui-types"; import { useTranslation } from "react-i18next"; import { extensionPoints, useBinder } from "@scm-manager/ui-extensions"; import { EXTENSION_POINT } from "../../avatar/Avatar"; import styled from "styled-components"; import CommaSeparatedList from "../../CommaSeparatedList"; import ContributorAvatar from "./ContributorAvatar"; type Props = { changeset: Changeset; }; type PersonProps = { person: Person; className?: string; displayTextOnly?: boolean; }; const useAvatar = (person: Person): string | undefined => { const binder = useBinder(); const factory = binder.getExtension(EXTENSION_POINT); if (factory) { return factory(person); } }; const AvatarList = styled.span` & > :not(:last-child) { margin-right: 0.25em; } `; type PersonAvatarProps = { person: Person; avatar: string; }; const ContributorWithAvatar: FC = ({ person, avatar }) => { const [t] = useTranslation("repos"); if (person.mail) { return ( ); } return ; }; export const SingleContributor: FC = ({ person, className, displayTextOnly }) => { const [t] = useTranslation("repos"); const avatar = useAvatar(person); if (!displayTextOnly && avatar) { return ; } if (person.mail) { return ( {person.name} ); } return {person.name}; }; type PersonsProps = { persons: ReadonlyArray; label: string; displayTextOnly?: boolean; }; const Contributors: FC = ({ persons, label, displayTextOnly }) => { const binder = useBinder(); const [t] = useTranslation("repos"); if (persons.length === 1) { return ( <> {t(label)} ); } const avatarFactory = binder.getExtension(EXTENSION_POINT); if (avatarFactory) { return ( <> {t(label)}{" "} {persons.map((p) => ( ))} ); } else { return ( <> {t(label)}{" "} "- " + person.name).join("\n")}> {t("changeset.contributors.more", { count: persons.length })} ); } }; const emptyListOfContributors: ReadonlyArray = []; const ChangesetAuthor: FC = ({ changeset }) => { const binder = useBinder(); const getCoAuthors = () => { return filterContributorsByType("Co-authored-by"); }; const getCommitters = () => { return filterContributorsByType("Committed-by"); }; const filterContributorsByType = (type: string) => { if (changeset.contributors) { return changeset.contributors.filter((p) => p.type === type).map((contributor) => contributor.person); } return emptyListOfContributors; }; const authorLine = []; if (changeset.author) { authorLine.push( ); } const commiters = getCommitters(); if (commiters.length > 0) { authorLine.push(); } const coAuthors = getCoAuthors(); if (coAuthors.length > 0) { authorLine.push(); } // extensions const extensions = binder.getExtensions("changesets.author.suffix", { changeset }); if (extensions) { authorLine.push(...extensions); } return ( {authorLine.map((line, index) => ( {line} ))} ); }; export default ChangesetAuthor;