2020-03-23 15:35:58 +01:00
|
|
|
/*
|
|
|
|
|
* MIT License
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
2020-06-09 11:41:03 +02:00
|
|
|
import React, { FC } from "react";
|
2019-10-20 16:59:02 +02:00
|
|
|
import { Changeset } from "@scm-manager/ui-types";
|
2020-06-09 14:11:15 +02:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
import { useBinder } from "@scm-manager/ui-extensions";
|
|
|
|
|
import { EXTENSION_POINT, Person } from "../../avatar/Avatar";
|
|
|
|
|
import styled from "styled-components";
|
2020-06-10 08:11:48 +02:00
|
|
|
import CommaSeparatedList from "../../CommaSeparatedList";
|
2020-06-10 09:35:34 +02:00
|
|
|
import ContributorAvatar from "./ContributorAvatar";
|
2018-09-19 16:47:21 +02:00
|
|
|
|
2020-06-09 14:11:15 +02:00
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
changeset: Changeset;
|
2018-09-19 16:47:21 +02:00
|
|
|
};
|
|
|
|
|
|
2020-06-09 14:11:15 +02:00
|
|
|
type PersonProps = {
|
|
|
|
|
person: Person;
|
|
|
|
|
displayTextOnly?: boolean;
|
2020-06-09 11:41:03 +02:00
|
|
|
};
|
2018-10-08 17:34:11 +02:00
|
|
|
|
2020-06-09 14:11:15 +02:00
|
|
|
const useAvatar = (person: Person): string | undefined => {
|
|
|
|
|
const binder = useBinder();
|
|
|
|
|
const factory: (person: Person) => string | undefined = binder.getExtension(EXTENSION_POINT);
|
|
|
|
|
if (factory) {
|
|
|
|
|
return factory(person);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-09 16:38:20 +02:00
|
|
|
const AvatarList = styled.span`
|
|
|
|
|
& > :not(:last-child) {
|
|
|
|
|
margin-right: 0.25em;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2020-06-09 14:11:15 +02:00
|
|
|
type PersonAvatarProps = {
|
|
|
|
|
person: Person;
|
|
|
|
|
avatar: string;
|
2020-06-09 11:41:03 +02:00
|
|
|
};
|
2019-02-07 10:27:11 +01:00
|
|
|
|
2020-06-09 14:11:15 +02:00
|
|
|
const PersonAvatar: FC<PersonAvatarProps> = ({ person, avatar }) => {
|
2020-06-09 11:41:03 +02:00
|
|
|
const [t] = useTranslation("repos");
|
2020-06-10 09:35:34 +02:00
|
|
|
const img = <ContributorAvatar src={avatar} alt={person.name} title={person.name} />;
|
2020-06-09 14:11:15 +02:00
|
|
|
if (person.mail) {
|
|
|
|
|
return (
|
|
|
|
|
<a href={"mailto:" + person.mail} title={t("changeset.author.mailto") + " " + person.mail}>
|
|
|
|
|
{img}
|
|
|
|
|
</a>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return img;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const SinglePerson: FC<PersonProps> = ({ person, displayTextOnly }) => {
|
|
|
|
|
const [t] = useTranslation("repos");
|
|
|
|
|
const avatar = useAvatar(person);
|
|
|
|
|
if (!displayTextOnly && avatar) {
|
|
|
|
|
return <PersonAvatar person={person} avatar={avatar} />;
|
|
|
|
|
}
|
2020-06-09 11:41:03 +02:00
|
|
|
if (person.mail) {
|
2018-09-19 16:47:21 +02:00
|
|
|
return (
|
2020-06-09 11:41:03 +02:00
|
|
|
<a href={"mailto:" + person.mail} title={t("changeset.author.mailto") + " " + person.mail}>
|
|
|
|
|
{person.name}
|
2019-02-07 10:27:11 +01:00
|
|
|
</a>
|
2018-10-08 17:34:11 +02:00
|
|
|
);
|
|
|
|
|
}
|
2020-06-09 11:41:03 +02:00
|
|
|
return <>{person.name}</>;
|
|
|
|
|
};
|
2018-10-08 17:34:11 +02:00
|
|
|
|
2020-06-09 11:41:03 +02:00
|
|
|
type PersonsProps = {
|
2020-06-09 14:11:15 +02:00
|
|
|
persons: Person[];
|
2020-06-09 11:41:03 +02:00
|
|
|
label: string;
|
2020-06-09 14:11:15 +02:00
|
|
|
displayTextOnly?: boolean;
|
2020-06-09 11:41:03 +02:00
|
|
|
};
|
|
|
|
|
|
2020-06-09 14:11:15 +02:00
|
|
|
const Persons: FC<PersonsProps> = ({ persons, label, displayTextOnly }) => {
|
|
|
|
|
const binder = useBinder();
|
|
|
|
|
|
2020-06-09 11:41:03 +02:00
|
|
|
const [t] = useTranslation("repos");
|
|
|
|
|
if (persons.length === 1) {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2020-06-09 14:11:15 +02:00
|
|
|
{t(label)} <SinglePerson person={persons[0]} displayTextOnly={displayTextOnly} />
|
2020-06-09 11:41:03 +02:00
|
|
|
</>
|
|
|
|
|
);
|
2020-05-28 11:16:03 +02:00
|
|
|
}
|
|
|
|
|
|
2020-06-09 14:11:15 +02:00
|
|
|
const avatarFactory = binder.getExtension(EXTENSION_POINT);
|
|
|
|
|
if (avatarFactory) {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{t(label)}{" "}
|
2020-06-09 16:38:20 +02:00
|
|
|
<AvatarList>
|
|
|
|
|
{persons.map(p => (
|
2020-06-10 08:11:48 +02:00
|
|
|
<PersonAvatar key={p.name} person={p} avatar={avatarFactory(p)} />
|
2020-06-09 16:38:20 +02:00
|
|
|
))}
|
|
|
|
|
</AvatarList>
|
2020-06-09 14:11:15 +02:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{t(label)}{" "}
|
2020-06-10 08:11:48 +02:00
|
|
|
<a title={persons.map(person => "- " + person.name).join("\n")}>
|
2020-06-09 14:11:15 +02:00
|
|
|
{t("changesets.authors.more", { count: persons.length })}
|
|
|
|
|
</a>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-06-09 11:41:03 +02:00
|
|
|
|
2020-06-09 14:11:15 +02:00
|
|
|
const ChangesetAuthor: FC<Props> = ({ changeset }) => {
|
|
|
|
|
const binder = useBinder();
|
2020-06-09 11:41:03 +02:00
|
|
|
|
2020-06-09 14:11:15 +02:00
|
|
|
const getCoAuthors = () => {
|
|
|
|
|
return filterTrailersByType("Co-authored-by");
|
|
|
|
|
};
|
2020-06-09 11:41:03 +02:00
|
|
|
|
2020-06-09 16:13:05 +02:00
|
|
|
const getCommitters = () => {
|
2020-06-09 14:11:15 +02:00
|
|
|
return filterTrailersByType("Committed-by");
|
|
|
|
|
};
|
2020-05-28 11:16:03 +02:00
|
|
|
|
2020-06-09 14:11:15 +02:00
|
|
|
const filterTrailersByType = (trailerType: string) => {
|
|
|
|
|
return changeset.trailers.filter(p => p.trailerType === trailerType).map(trailer => trailer.person);
|
|
|
|
|
};
|
2020-05-28 11:45:15 +02:00
|
|
|
|
2020-06-09 14:11:15 +02:00
|
|
|
const authorLine = [];
|
2020-06-09 14:47:47 +02:00
|
|
|
if (changeset.author) {
|
|
|
|
|
authorLine.push(
|
2020-06-09 16:38:20 +02:00
|
|
|
<Persons persons={[changeset.author]} label={"changesets.authors.authoredBy"} displayTextOnly={true} />
|
2020-06-09 14:47:47 +02:00
|
|
|
);
|
|
|
|
|
}
|
2020-05-28 11:16:03 +02:00
|
|
|
|
2020-06-09 16:13:05 +02:00
|
|
|
const commiters = getCommitters();
|
2020-06-09 14:11:15 +02:00
|
|
|
if (commiters.length > 0) {
|
|
|
|
|
authorLine.push(<Persons persons={commiters} label={"changesets.authors.committedBy"} />);
|
2020-06-09 14:47:47 +02:00
|
|
|
}
|
2020-06-09 16:13:05 +02:00
|
|
|
|
2020-06-09 14:11:15 +02:00
|
|
|
const coAuthors = getCoAuthors();
|
|
|
|
|
if (coAuthors.length > 0) {
|
|
|
|
|
authorLine.push(<Persons persons={coAuthors} label={"changesets.authors.coAuthoredBy"} />);
|
2020-06-09 14:47:47 +02:00
|
|
|
}
|
2020-06-09 16:13:05 +02:00
|
|
|
|
2020-06-09 14:11:15 +02:00
|
|
|
// extensions
|
|
|
|
|
const extensions = binder.getExtensions("changesets.author.suffix", { changeset });
|
|
|
|
|
if (extensions) {
|
|
|
|
|
coAuthors.push(...extensions);
|
2020-06-09 11:41:03 +02:00
|
|
|
}
|
2018-12-10 08:45:59 +01:00
|
|
|
|
2020-06-10 08:11:48 +02:00
|
|
|
return <CommaSeparatedList>{authorLine}</CommaSeparatedList>
|
2020-06-09 14:11:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ChangesetAuthor;
|