added component for comma separated lists

This commit is contained in:
Sebastian Sdorra
2020-06-10 08:11:48 +02:00
parent a2453885b9
commit 23b0ea27df
7 changed files with 73 additions and 27 deletions

View File

@@ -0,0 +1,51 @@
/*
* 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.
*/
import React, { FC } from "react";
import { useTranslation } from "react-i18next";
const CommaSeparatedList: FC = ({ children }) => {
const [t] = useTranslation("commons");
const childArray = React.Children.toArray(children);
return (
<>
{childArray.map((p, i) => {
if (i === 0) {
return <React.Fragment key={i}>{p}</React.Fragment>;
} else if (i + 1 === childArray.length) {
return (
<React.Fragment key={i}>
{" "}
{t("commaSeparatedList.lastDivider")} {p}{" "}
</React.Fragment>
);
} else {
return <React.Fragment key={i}>, {p}</React.Fragment>;
}
})}
</>
);
};
export default CommaSeparatedList;

View File

@@ -40,6 +40,7 @@ import {
DiffEventHandler,
DiffEventContext
} from "./repos";
import CommaSeparatedList from "./CommaSeparatedList";
export { validation, urls, repositories };
@@ -76,6 +77,7 @@ export { default as OverviewPageActions } from "./OverviewPageActions";
export { default as CardColumnGroup } from "./CardColumnGroup";
export { default as CardColumn } from "./CardColumn";
export { default as CardColumnSmall } from "./CardColumnSmall";
export { default as CommaSeparatedList } from "./CommaSeparatedList";
export { default as comparators } from "./comparators";

View File

@@ -28,6 +28,7 @@ import { useBinder } from "@scm-manager/ui-extensions";
import { EXTENSION_POINT, Person } from "../../avatar/Avatar";
import Image from "../../Image";
import styled from "styled-components";
import CommaSeparatedList from "../../CommaSeparatedList";
type Props = {
changeset: Changeset;
@@ -119,7 +120,7 @@ const Persons: FC<PersonsProps> = ({ persons, label, displayTextOnly }) => {
{t(label)}{" "}
<AvatarList>
{persons.map(p => (
<PersonAvatar person={p} avatar={avatarFactory(p)} />
<PersonAvatar key={p.name} person={p} avatar={avatarFactory(p)} />
))}
</AvatarList>
</>
@@ -128,7 +129,7 @@ const Persons: FC<PersonsProps> = ({ persons, label, displayTextOnly }) => {
return (
<>
{t(label)}{" "}
<a title={label + ":\n" + persons.map(person => "- " + person.name).join("\n")}>
<a title={persons.map(person => "- " + person.name).join("\n")}>
{t("changesets.authors.more", { count: persons.length })}
</a>
</>
@@ -175,24 +176,7 @@ const ChangesetAuthor: FC<Props> = ({ changeset }) => {
coAuthors.push(...extensions);
}
return (
<>
{authorLine.map((p, i) => {
if (i === 0) {
return <>{p}</>;
} else if (i + 1 === authorLine.length) {
return (
<>
{" "}
{t("changesets.authors.and")} {p}{" "}
</>
);
} else {
return <>, {p}</>;
}
})}
</>
);
return <CommaSeparatedList>{authorLine}</CommaSeparatedList>
};
export default ChangesetAuthor;

View File

@@ -104,5 +104,8 @@
"community": "Community",
"enterprise": "Enterprise"
}
},
"commaSeparatedList": {
"lastDivider": "und"
}
}

View File

@@ -105,5 +105,8 @@
"community": "Community",
"enterprise": "Enterprise"
}
},
"commaSeparatedList": {
"lastDivider": "and"
}
}

View File

@@ -89,5 +89,8 @@
"passwordConfirmFailed": "Las contraseñas deben ser identicas",
"submit": "Guardar",
"changedSuccessfully": "Contraseña cambiada correctamente"
},
"commaSeparatedList": {
"lastDivider": "y"
}
}

View File

@@ -26,7 +26,7 @@ import { Changeset } from "@scm-manager/ui-types";
import styled from "styled-components";
import { useTranslation } from "react-i18next";
import { useBinder } from "@scm-manager/ui-extensions";
import { Image } from "@scm-manager/ui-components";
import { Image, CommaSeparatedList } from "@scm-manager/ui-components";
type Props = {
changeset: Changeset;
@@ -104,14 +104,14 @@ const ContributorTable: FC<Props> = ({ changeset }) => {
</td>
</tr>
{getTrailersByType().map(trailer => (
<tr>
<tr key={trailer.type}>
<SizedTd>{t("changeset.trailer.type." + trailer.type) + ":"}</SizedTd>
<td className="shorten-text is-marginless">
{trailer.persons
.map(person => (
<Contributor person={person} />
))
.reduce((prev, curr) => [prev, ", ", curr])}
<CommaSeparatedList>
{trailer.persons.map(person => (
<Contributor key={person.name} person={person} />
))}
</CommaSeparatedList>
</td>
</tr>
))}