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";
|
2023-01-18 12:09:49 +00:00
|
|
|
import { Link, Path } from "react-router-dom";
|
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>) {
|
2023-09-08 13:17:17 +00:00
|
|
|
const { t } = useTranslation();
|
2022-01-12 16:01:54 +00:00
|
|
|
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>
|
|
|
|
);
|
|
|
|
})}
|
2023-09-14 09:01:15 +00:00
|
|
|
{array?.length === 0 && <i>{t("none")}</i>}
|
2022-01-12 16:01:54 +00:00
|
|
|
</DescriptionListDescription>
|
|
|
|
</DescriptionListGroup>
|
|
|
|
);
|
|
|
|
}
|