74 lines
2.7 KiB
TypeScript
74 lines
2.7 KiB
TypeScript
import { useTranslation } from "react-i18next";
|
|
import TableSimple from "~/components/ui/tables/TableSimple";
|
|
import { EntitiesTemplateDto, TemplateEntityDto } from "~/modules/templates/EntityTemplateDto";
|
|
import { translateEntityTitle, translateEntityTitlePlural, translateEntityViewTitle, translatePropertyTitle } from "~/utils/i18n/translateLabel";
|
|
|
|
export default function PreviewEntitiesTemplate({ template }: { template: EntitiesTemplateDto }) {
|
|
const { t, i18n } = useTranslation();
|
|
function findParentRelationships(item: TemplateEntityDto) {
|
|
return template.relationships.filter((f) => f.parent === item.name) ?? [];
|
|
}
|
|
function findChildRelationships(item: TemplateEntityDto) {
|
|
return template.relationships.filter((f) => f.child === item.name) ?? [];
|
|
}
|
|
return (
|
|
<TableSimple
|
|
items={template.entities}
|
|
headers={[
|
|
{ name: "prefix", title: t("models.entity.prefix"), value: (i) => i.prefix },
|
|
{
|
|
name: "name",
|
|
title: t("models.entity.name"),
|
|
value: (i) => (
|
|
<div className="flex items-baseline space-x-1">
|
|
<div>{i.name}</div>
|
|
<div className="text-xs italic">({i.slug})</div>
|
|
</div>
|
|
),
|
|
},
|
|
{
|
|
name: "title",
|
|
title: t("models.entity.title"),
|
|
value: (i) => (
|
|
<div className="flex items-baseline space-x-1">
|
|
<div>{translateEntityTitle(t, i18n, i)}</div>
|
|
<div className="text-xs italic">({translateEntityTitlePlural(t, i18n, i)})</div>
|
|
</div>
|
|
),
|
|
},
|
|
{
|
|
name: "properties",
|
|
title: t("models.property.plural"),
|
|
value: (i) => i.properties.map((property) => `${translatePropertyTitle(t, i18n, i.name, property)}${property.isRequired ? "*" : ""} [${property.type}]`).join(", "),
|
|
className: "text-xs",
|
|
},
|
|
{
|
|
name: "parents",
|
|
title: t("models.relationship.parents"),
|
|
value: (item) =>
|
|
findChildRelationships(item)
|
|
.map((i) => i.parent)
|
|
.join(", "),
|
|
className: "text-xs",
|
|
},
|
|
{
|
|
name: "children",
|
|
title: t("models.relationship.children"),
|
|
value: (item) =>
|
|
findParentRelationships(item)
|
|
.map((i) => i.child)
|
|
.join(", "),
|
|
className: "text-xs",
|
|
},
|
|
{
|
|
name: "views",
|
|
title: t("models.view.plural"),
|
|
value: (item) => (
|
|
<div>{item.views?.map((view) => translateEntityViewTitle(t, i18n, item.name, view) + (view.isDefault ? ` (${t("models.view.defaultBadge")})` : "")).join(", ")}</div>
|
|
),
|
|
},
|
|
]}
|
|
/>
|
|
);
|
|
}
|