mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 22:15:45 +01:00
added component for comma separated lists
This commit is contained in:
51
scm-ui/ui-components/src/CommaSeparatedList.tsx
Normal file
51
scm-ui/ui-components/src/CommaSeparatedList.tsx
Normal 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;
|
||||||
@@ -40,6 +40,7 @@ import {
|
|||||||
DiffEventHandler,
|
DiffEventHandler,
|
||||||
DiffEventContext
|
DiffEventContext
|
||||||
} from "./repos";
|
} from "./repos";
|
||||||
|
import CommaSeparatedList from "./CommaSeparatedList";
|
||||||
|
|
||||||
export { validation, urls, repositories };
|
export { validation, urls, repositories };
|
||||||
|
|
||||||
@@ -76,6 +77,7 @@ export { default as OverviewPageActions } from "./OverviewPageActions";
|
|||||||
export { default as CardColumnGroup } from "./CardColumnGroup";
|
export { default as CardColumnGroup } from "./CardColumnGroup";
|
||||||
export { default as CardColumn } from "./CardColumn";
|
export { default as CardColumn } from "./CardColumn";
|
||||||
export { default as CardColumnSmall } from "./CardColumnSmall";
|
export { default as CardColumnSmall } from "./CardColumnSmall";
|
||||||
|
export { default as CommaSeparatedList } from "./CommaSeparatedList";
|
||||||
|
|
||||||
export { default as comparators } from "./comparators";
|
export { default as comparators } from "./comparators";
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import { useBinder } from "@scm-manager/ui-extensions";
|
|||||||
import { EXTENSION_POINT, Person } from "../../avatar/Avatar";
|
import { EXTENSION_POINT, Person } from "../../avatar/Avatar";
|
||||||
import Image from "../../Image";
|
import Image from "../../Image";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
|
import CommaSeparatedList from "../../CommaSeparatedList";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
changeset: Changeset;
|
changeset: Changeset;
|
||||||
@@ -119,7 +120,7 @@ const Persons: FC<PersonsProps> = ({ persons, label, displayTextOnly }) => {
|
|||||||
{t(label)}{" "}
|
{t(label)}{" "}
|
||||||
<AvatarList>
|
<AvatarList>
|
||||||
{persons.map(p => (
|
{persons.map(p => (
|
||||||
<PersonAvatar person={p} avatar={avatarFactory(p)} />
|
<PersonAvatar key={p.name} person={p} avatar={avatarFactory(p)} />
|
||||||
))}
|
))}
|
||||||
</AvatarList>
|
</AvatarList>
|
||||||
</>
|
</>
|
||||||
@@ -128,7 +129,7 @@ const Persons: FC<PersonsProps> = ({ persons, label, displayTextOnly }) => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{t(label)}{" "}
|
{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 })}
|
{t("changesets.authors.more", { count: persons.length })}
|
||||||
</a>
|
</a>
|
||||||
</>
|
</>
|
||||||
@@ -175,24 +176,7 @@ const ChangesetAuthor: FC<Props> = ({ changeset }) => {
|
|||||||
coAuthors.push(...extensions);
|
coAuthors.push(...extensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return <CommaSeparatedList>{authorLine}</CommaSeparatedList>
|
||||||
<>
|
|
||||||
{authorLine.map((p, i) => {
|
|
||||||
if (i === 0) {
|
|
||||||
return <>{p}</>;
|
|
||||||
} else if (i + 1 === authorLine.length) {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{" "}
|
|
||||||
{t("changesets.authors.and")} {p}{" "}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return <>, {p}</>;
|
|
||||||
}
|
|
||||||
})}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ChangesetAuthor;
|
export default ChangesetAuthor;
|
||||||
|
|||||||
@@ -104,5 +104,8 @@
|
|||||||
"community": "Community",
|
"community": "Community",
|
||||||
"enterprise": "Enterprise"
|
"enterprise": "Enterprise"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"commaSeparatedList": {
|
||||||
|
"lastDivider": "und"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,5 +105,8 @@
|
|||||||
"community": "Community",
|
"community": "Community",
|
||||||
"enterprise": "Enterprise"
|
"enterprise": "Enterprise"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"commaSeparatedList": {
|
||||||
|
"lastDivider": "and"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,5 +89,8 @@
|
|||||||
"passwordConfirmFailed": "Las contraseñas deben ser identicas",
|
"passwordConfirmFailed": "Las contraseñas deben ser identicas",
|
||||||
"submit": "Guardar",
|
"submit": "Guardar",
|
||||||
"changedSuccessfully": "Contraseña cambiada correctamente"
|
"changedSuccessfully": "Contraseña cambiada correctamente"
|
||||||
|
},
|
||||||
|
"commaSeparatedList": {
|
||||||
|
"lastDivider": "y"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ 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 { useBinder } from "@scm-manager/ui-extensions";
|
||||||
import { Image } from "@scm-manager/ui-components";
|
import { Image, CommaSeparatedList } from "@scm-manager/ui-components";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
changeset: Changeset;
|
changeset: Changeset;
|
||||||
@@ -104,14 +104,14 @@ const ContributorTable: FC<Props> = ({ changeset }) => {
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{getTrailersByType().map(trailer => (
|
{getTrailersByType().map(trailer => (
|
||||||
<tr>
|
<tr key={trailer.type}>
|
||||||
<SizedTd>{t("changeset.trailer.type." + trailer.type) + ":"}</SizedTd>
|
<SizedTd>{t("changeset.trailer.type." + trailer.type) + ":"}</SizedTd>
|
||||||
<td className="shorten-text is-marginless">
|
<td className="shorten-text is-marginless">
|
||||||
{trailer.persons
|
<CommaSeparatedList>
|
||||||
.map(person => (
|
{trailer.persons.map(person => (
|
||||||
<Contributor person={person} />
|
<Contributor key={person.name} person={person} />
|
||||||
))
|
))}
|
||||||
.reduce((prev, curr) => [prev, ", ", curr])}
|
</CommaSeparatedList>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
|
|||||||
Reference in New Issue
Block a user