2022-01-12 16:01:54 +00:00
|
|
|
import {
|
2022-08-19 18:05:09 +00:00
|
|
|
DescriptionListDescription,
|
2022-01-12 16:01:54 +00:00
|
|
|
DescriptionListGroup,
|
|
|
|
DescriptionListTerm,
|
|
|
|
} from "@patternfly/react-core";
|
2022-08-19 18:05:09 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2022-08-22 15:51:19 +00:00
|
|
|
import { Link } from "react-router-dom-v5-compat";
|
2022-08-19 18:05:09 +00:00
|
|
|
import { Path } from "react-router-dom-v5-compat";
|
2022-01-12 16:01:54 +00:00
|
|
|
|
|
|
|
type DetailDescriptionProps<T> = {
|
|
|
|
name: string;
|
|
|
|
array?: string[] | T[];
|
|
|
|
convert?: (obj: T) => string;
|
|
|
|
};
|
|
|
|
|
2022-03-21 06:45:49 +00:00
|
|
|
export function DetailDescription<T>(props: DetailDescriptionProps<T>) {
|
|
|
|
return <DetailDescriptionLink {...props} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
type DetailDescriptionLinkProps<T> = DetailDescriptionProps<T> & {
|
2022-08-19 18:05:09 +00:00
|
|
|
link?: (element: T) => Partial<Path>;
|
2022-03-21 06:45:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export function DetailDescriptionLink<T>({
|
2022-01-12 16:01:54 +00:00
|
|
|
name,
|
|
|
|
array,
|
|
|
|
convert,
|
2022-03-21 06:45:49 +00:00
|
|
|
link,
|
|
|
|
}: DetailDescriptionLinkProps<T>) {
|
2022-01-12 16:01:54 +00:00
|
|
|
const { t } = useTranslation("clients");
|
|
|
|
return (
|
|
|
|
<DescriptionListGroup>
|
|
|
|
<DescriptionListTerm>{t(name)}</DescriptionListTerm>
|
|
|
|
<DescriptionListDescription>
|
|
|
|
{array?.map((element) => {
|
|
|
|
const value =
|
|
|
|
typeof element === "string" ? element : convert!(element);
|
2022-03-21 06:45:49 +00:00
|
|
|
return link ? (
|
|
|
|
<Link key={value} to={link(element as T)} className="pf-u-pr-sm">
|
|
|
|
{value}
|
|
|
|
</Link>
|
|
|
|
) : (
|
2022-01-12 16:01:54 +00:00
|
|
|
<span key={value} className="pf-u-pr-sm">
|
|
|
|
{value}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
{array?.length === 0 && <i>{t("common:none")}</i>}
|
|
|
|
</DescriptionListDescription>
|
|
|
|
</DescriptionListGroup>
|
|
|
|
);
|
|
|
|
}
|