Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,73 @@
|
||||
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>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
);
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const sourcePath = path.resolve(process.cwd(), "apps/web/app/components/entities/templates/PreviewEntitiesTemplate.tsx");
|
||||
|
||||
describe("preview entities template i18n", () => {
|
||||
it("uses semantic translation keys for preview table headers", () => {
|
||||
const source = fs.readFileSync(sourcePath, "utf8");
|
||||
|
||||
expect(source).toContain("models.entity.prefix");
|
||||
expect(source).toContain("models.property.plural");
|
||||
expect(source).toContain("models.relationship.parents");
|
||||
expect(source).toContain("models.relationship.children");
|
||||
expect(source).toContain("models.view.defaultBadge");
|
||||
expect(source).not.toContain("ui.autogenerated");
|
||||
expect(source).not.toContain("(default)");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user