mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 09:25:43 +01:00
added avatar support to contributor table
This commit is contained in:
@@ -22,9 +22,11 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
import React, { FC } from "react";
|
import React, { FC } from "react";
|
||||||
import { Changeset } from "@scm-manager/ui-types/src";
|
import { Changeset } from "@scm-manager/ui-types";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useBinder } from "@scm-manager/ui-extensions";
|
||||||
|
import { Image } from "@scm-manager/ui-components";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
changeset: Changeset;
|
changeset: Changeset;
|
||||||
@@ -34,6 +36,43 @@ const SizedTd = styled.td`
|
|||||||
width: 10rem;
|
width: 10rem;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
// TODO get from ui-types?
|
||||||
|
type Person = {
|
||||||
|
name: string;
|
||||||
|
mail?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ContributorAvatar = styled(Image)`
|
||||||
|
width: 1em;
|
||||||
|
height: 1em;
|
||||||
|
margin-right: 0.5em;
|
||||||
|
vertical-align: middle;
|
||||||
|
border-radius: 0.25em;
|
||||||
|
margin-bottom: 0.2em;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Contributor: FC<{ person: Person }> = ({ person }) => {
|
||||||
|
const [t] = useTranslation("repos");
|
||||||
|
const binder = useBinder();
|
||||||
|
const avatarFactory = binder.getExtension("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.author.mailto") + " " + person.mail}>
|
||||||
|
{prefix}
|
||||||
|
{person.name}
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return <>{person.name}</>;
|
||||||
|
};
|
||||||
|
|
||||||
const ContributorTable: FC<Props> = ({ changeset }) => {
|
const ContributorTable: FC<Props> = ({ changeset }) => {
|
||||||
const [t] = useTranslation("plugins");
|
const [t] = useTranslation("plugins");
|
||||||
|
|
||||||
@@ -61,9 +100,7 @@ const ContributorTable: FC<Props> = ({ changeset }) => {
|
|||||||
<tr>
|
<tr>
|
||||||
<SizedTd>{t("changeset.trailer.type.author") + ":"}</SizedTd>
|
<SizedTd>{t("changeset.trailer.type.author") + ":"}</SizedTd>
|
||||||
<td>
|
<td>
|
||||||
<a title={changeset?.author?.mail} href={"mailto:" + changeset?.author?.mail}>
|
<Contributor person={changeset.author} />
|
||||||
{changeset?.author?.name}
|
|
||||||
</a>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{getTrailersByType().map(trailer => (
|
{getTrailersByType().map(trailer => (
|
||||||
@@ -72,9 +109,7 @@ const ContributorTable: FC<Props> = ({ changeset }) => {
|
|||||||
<td className="shorten-text is-marginless">
|
<td className="shorten-text is-marginless">
|
||||||
{trailer.persons
|
{trailer.persons
|
||||||
.map(person => (
|
.map(person => (
|
||||||
<a title={person.mail} href={"mailto:" + person.mail}>
|
<Contributor person={person} />
|
||||||
{person.name}
|
|
||||||
</a>
|
|
||||||
))
|
))
|
||||||
.reduce((prev, curr) => [prev, ", ", curr])}
|
.reduce((prev, curr) => [prev, ", ", curr])}
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
Reference in New Issue
Block a user