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,722 @@
|
||||
import { Property } from "@toolctrl/db/prisma-browser";
|
||||
import clsx from "clsx";
|
||||
import { useRef, useState, useEffect, Fragment } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import Constants from "~/application/Constants";
|
||||
import { PropertyType } from "~/application/enums/entities/PropertyType";
|
||||
import { ViewFilterCondition } from "~/application/enums/entities/ViewFilterCondition";
|
||||
import InfoBanner from "~/components/ui/banners/InfoBanner";
|
||||
import FormGroup from "~/components/ui/forms/FormGroup";
|
||||
import InputGroup from "~/components/ui/forms/InputGroup";
|
||||
import InputCheckboxInline from "~/components/ui/input/InputCheckboxInline";
|
||||
import InputNumber from "~/components/ui/input/InputNumber";
|
||||
import InputRadioGroupCards from "~/components/ui/input/InputRadioGroupCards";
|
||||
import InputSelect from "~/components/ui/input/InputSelect";
|
||||
import InputSelector from "~/components/ui/input/InputSelector";
|
||||
import InputText, { RefInputText } from "~/components/ui/input/InputText";
|
||||
import OrderIndexButtons from "~/components/ui/sort/OrderIndexButtons";
|
||||
import CollapsibleRow from "~/components/ui/tables/CollapsibleRow";
|
||||
import { EntityViewLayoutTypes } from "~/modules/rows/dtos/EntityViewLayoutType";
|
||||
import { EntityWithDetails } from "~/utils/db/entities/entities.db.server";
|
||||
import { EntityViewWithDetails } from "~/utils/db/entities/entityViews.db.server";
|
||||
import OrderHelper from "~/utils/helpers/OrderHelper";
|
||||
import RowColumnsHelper from "~/utils/helpers/RowColumnsHelper";
|
||||
import { updateItemByIdx } from "~/utils/shared/ObjectUtils";
|
||||
import StringUtils from "~/utils/shared/StringUtils";
|
||||
import EntityViewLayoutBadge from "./EntityViewLayoutBadge";
|
||||
import { RowWithDetails } from "~/utils/db/entities/rows.db.server";
|
||||
import RowHelper from "~/utils/helpers/RowHelper";
|
||||
import RowsList from "../rows/RowsList";
|
||||
import { defaultDisplayProperties } from "~/utils/helpers/PropertyHelper";
|
||||
import { translateEntityTitlePlural, translatePropertyTitle, translateSelectOptionLabel } from "~/utils/i18n/translateLabel";
|
||||
|
||||
interface Props {
|
||||
entity: EntityWithDetails | undefined;
|
||||
item?: EntityViewWithDetails | null;
|
||||
canDelete?: boolean;
|
||||
onClose?: () => void;
|
||||
actionNames?: {
|
||||
create: string;
|
||||
update: string;
|
||||
delete: string;
|
||||
};
|
||||
tenantId: string | null;
|
||||
userId: string | null;
|
||||
isSystem: boolean;
|
||||
showViewType: boolean;
|
||||
}
|
||||
|
||||
export default function EntityViewForm({
|
||||
entity,
|
||||
item,
|
||||
canDelete,
|
||||
onClose,
|
||||
actionNames,
|
||||
isSystem,
|
||||
tenantId,
|
||||
userId,
|
||||
showViewType,
|
||||
}: Props & { entity: EntityWithDetails }) {
|
||||
const { t, i18n } = useTranslation();
|
||||
|
||||
const inputName = useRef<RefInputText>(null);
|
||||
|
||||
const [possibleProperties, setPossibleProperties] = useState<{ propertyId: string | null; name: string | null; order: number; title?: string }[]>(
|
||||
item?.properties ?? []
|
||||
);
|
||||
|
||||
const [fakeItems, setFakeItems] = useState<RowWithDetails[]>([]);
|
||||
|
||||
const [layout, setLayout] = useState<"table" | "board" | "grid" | "card">("table");
|
||||
const [name, setName] = useState("");
|
||||
const [title, setTitle] = useState("");
|
||||
const [order, setOrder] = useState<number | undefined>(item?.order ?? OrderHelper.getNextOrder(entity.views));
|
||||
const [pageSize, setPageSize] = useState<number | undefined>(item?.pageSize ?? Constants.DEFAULT_PAGE_SIZE);
|
||||
const [isDefault, setIsDefault] = useState(item?.isDefault ?? OrderHelper.getNextOrder(entity.views) === 1);
|
||||
|
||||
const [properties, setProperties] = useState<{ propertyId: string | null; name: string | null; order: number; title?: string }[]>([]);
|
||||
const [filters, setFilters] = useState<{ name: string; condition: string; value: string; match: string }[]>(item?.filters ?? []);
|
||||
// const [sort, setSort] = useState<{ name: string; asc: boolean; order: number }[]>(item?.sort ?? []);
|
||||
|
||||
// Board
|
||||
const [groupBy, setGroupBy] = useState<string | number | undefined>(item?.groupByPropertyId ? "byProperty" : undefined);
|
||||
const [groupByPropertyId, setGroupByPropertyId] = useState<string | number | undefined>(item?.groupByPropertyId ?? undefined);
|
||||
const [groupByOptions, setGroupByOptions] = useState<{ name: string; value: string }[]>([]);
|
||||
const [selectProperties, setSelectProperties] = useState<Property[]>([]);
|
||||
|
||||
// Grid
|
||||
const [gridColumns, setGridColumns] = useState<number | undefined>(item?.gridColumns || 0);
|
||||
const [gridColumnsSm, setGridColumnsSm] = useState<number | undefined>(item?.gridColumnsSm || 0);
|
||||
const [gridColumnsMd, setGridColumnsMd] = useState<number | undefined>(item?.gridColumnsMd || 0);
|
||||
const [gridColumnsLg, setGridColumnsLg] = useState<number | undefined>(item?.gridColumnsLg || 0);
|
||||
const [gridColumnsXl, setGridColumnsXl] = useState<number | undefined>(item?.gridColumnsXl || 0);
|
||||
const [gridColumns2xl, setGridColumns2xl] = useState<number | undefined>(item?.gridColumns2xl || 0);
|
||||
const [gridGap, setGridGap] = useState(item?.gridGap ?? "sm");
|
||||
|
||||
const [filterByProperties, setFilterByProperties] = useState<{ name: string; value: string }[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!item && isSystem) {
|
||||
setName("system-" + entity.slug);
|
||||
setTitle(t("models.view.systemTitle", { entity: translateEntityTitlePlural(t, i18n, entity) }));
|
||||
setLayout("card");
|
||||
} else if (item) {
|
||||
setName(item.name);
|
||||
setTitle(item.title);
|
||||
setLayout(item.layout as "table" | "board" | "grid" | "card");
|
||||
}
|
||||
}, [entity, isSystem, item, t]);
|
||||
|
||||
useEffect(() => {
|
||||
const items: RowWithDetails[] = Array.from({ length: 10 }).map((_, idx) => {
|
||||
let nonDefaultProperties = properties.filter((p) => !defaultDisplayProperties.find((dp) => dp.name === p.name));
|
||||
const item: RowWithDetails = {
|
||||
values: nonDefaultProperties.map(({ name }) => {
|
||||
const property = entity.properties.find((p) => p.name === name);
|
||||
if (!property) return null;
|
||||
return RowHelper.getFakePropertyValue({ property, t, idx: idx + 1 });
|
||||
}),
|
||||
folio: idx + 1,
|
||||
createdAt: new Date(),
|
||||
createdByUser: {
|
||||
email: "preview@example.invalid",
|
||||
firstName: "Preview",
|
||||
lastName: "User",
|
||||
},
|
||||
} as RowWithDetails;
|
||||
return item;
|
||||
});
|
||||
setFakeItems(items);
|
||||
}, [entity.properties, properties, t]);
|
||||
|
||||
useEffect(() => {
|
||||
const possibleProperties = RowColumnsHelper.getDefaultEntityColumns(entity).map((i, idx) => {
|
||||
const property = entity.properties.find((p) => p.name === i.name);
|
||||
return {
|
||||
propertyId: property?.id ?? null,
|
||||
name: i.name,
|
||||
title: i.title,
|
||||
order: idx + 1,
|
||||
};
|
||||
});
|
||||
setPossibleProperties(possibleProperties);
|
||||
}, [entity]);
|
||||
|
||||
// Initial selected properties
|
||||
useEffect(() => {
|
||||
if (item) {
|
||||
setProperties(item.properties);
|
||||
} else {
|
||||
setProperties(
|
||||
RowColumnsHelper.getDefaultEntityColumns(entity)
|
||||
.filter((f) => f.visible)
|
||||
.map((i, idx) => {
|
||||
return {
|
||||
propertyId: null,
|
||||
name: i.name,
|
||||
title: i.title,
|
||||
order: idx + 1,
|
||||
};
|
||||
})
|
||||
);
|
||||
}
|
||||
}, [entity, item]);
|
||||
|
||||
useEffect(() => {
|
||||
setTimeout(() => {
|
||||
inputName.current?.input.current?.focus();
|
||||
}, 100);
|
||||
|
||||
const selectProperties = entity.properties.filter((f) => [PropertyType.SELECT, PropertyType.MULTI_SELECT].includes(f.type));
|
||||
setGroupByOptions([
|
||||
{
|
||||
name: t("models.view.property"),
|
||||
value: "byProperty",
|
||||
},
|
||||
]);
|
||||
setSelectProperties(selectProperties);
|
||||
|
||||
let filterByProperties = entity.properties
|
||||
.filter((f) => f.type === PropertyType.TEXT || f.type === PropertyType.SELECT || f.type === PropertyType.BOOLEAN)
|
||||
.map((property) => {
|
||||
return {
|
||||
name: translatePropertyTitle(t, i18n, entity.name, property),
|
||||
value: property.name,
|
||||
};
|
||||
});
|
||||
if (entity.hasTags) {
|
||||
filterByProperties = [...filterByProperties, { name: t("models.row.tags"), value: "tags" }];
|
||||
}
|
||||
setFilterByProperties(filterByProperties);
|
||||
}, [entity, t]);
|
||||
|
||||
function getPropertyByName(name: string) {
|
||||
return entity.properties.find((f) => f.name === name);
|
||||
}
|
||||
|
||||
function getPropertyConditionsByName(name: string) {
|
||||
if (name === "tags") {
|
||||
return [
|
||||
{ value: ViewFilterCondition.equals, name: t("entities.conditions.equals") },
|
||||
{ value: ViewFilterCondition.contains, name: t("entities.conditions.contains") },
|
||||
{ value: ViewFilterCondition.notIn, name: t("entities.conditions.notIn") },
|
||||
];
|
||||
} else {
|
||||
const property = getPropertyByName(name);
|
||||
if (property?.type === PropertyType.BOOLEAN) {
|
||||
return [
|
||||
{ value: ViewFilterCondition.equals, name: t("entities.conditions.equals") },
|
||||
// { value: ViewFilterCondition.notIn, name: t("entities.conditions.notIn") },
|
||||
];
|
||||
} else if (property?.type === PropertyType.TEXT || property?.type === PropertyType.SELECT) {
|
||||
return [
|
||||
{ value: ViewFilterCondition.equals, name: t("entities.conditions.equals") },
|
||||
{ value: ViewFilterCondition.contains, name: t("entities.conditions.contains") },
|
||||
{ value: ViewFilterCondition.lt, name: t("entities.conditions.lt") },
|
||||
{ value: ViewFilterCondition.lte, name: t("entities.conditions.lte") },
|
||||
{ value: ViewFilterCondition.gt, name: t("entities.conditions.gt") },
|
||||
{ value: ViewFilterCondition.gte, name: t("entities.conditions.gte") },
|
||||
{ value: ViewFilterCondition.startsWith, name: t("entities.conditions.startsWith") },
|
||||
{ value: ViewFilterCondition.endsWith, name: t("entities.conditions.endsWith") },
|
||||
{ value: ViewFilterCondition.in, name: t("entities.conditions.in") },
|
||||
{ value: ViewFilterCondition.notIn, name: t("entities.conditions.notIn") },
|
||||
];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
function getPropertyTitle(name: string) {
|
||||
return RowColumnsHelper.getDefaultEntityColumns(entity).find((f) => f.name === name)?.title ?? "";
|
||||
}
|
||||
|
||||
function getTypeTitle() {
|
||||
if (isSystem) {
|
||||
return t("models.view.typeSummary", { type: t("models.view.types.system") });
|
||||
} else if (!tenantId && !userId) {
|
||||
return t("models.view.typeSummary", { type: t("models.view.types.default") });
|
||||
} else if (tenantId && !userId) {
|
||||
return t("models.view.typeSummary", { type: t("models.view.types.tenant") });
|
||||
} else if (tenantId && userId) {
|
||||
return t("models.view.typeSummary", { type: t("models.view.types.user") });
|
||||
}
|
||||
return t("models.view.typeSummary", { type: t("models.view.types.tenant") });
|
||||
}
|
||||
|
||||
function getTypeDescription() {
|
||||
if (isSystem) {
|
||||
return t("models.view.typeDescriptions.system");
|
||||
} else if (!tenantId && !userId) {
|
||||
return t("models.view.typeDescriptions.default");
|
||||
} else if (tenantId && !userId) {
|
||||
return t("models.view.typeDescriptions.tenant");
|
||||
} else if (tenantId && userId) {
|
||||
return t("models.view.typeDescriptions.user");
|
||||
}
|
||||
return t("models.view.typeDescriptions.tenant");
|
||||
}
|
||||
|
||||
return (
|
||||
<FormGroup id={item?.id} onCancel={onClose} editing={true} canDelete={canDelete} actionNames={actionNames} className="text-foreground">
|
||||
<input type="hidden" name="id" value={item?.id} hidden readOnly />
|
||||
<input type="hidden" name="entityId" value={entity.id} hidden readOnly />
|
||||
<input type="hidden" name="isSystem" value={isSystem ? "true" : "false"} hidden readOnly />
|
||||
<input type="hidden" name="tenantId" value={tenantId ?? undefined} hidden readOnly />
|
||||
<input type="hidden" name="userId" value={userId ?? undefined} hidden readOnly />
|
||||
|
||||
{showViewType && <InfoBanner title={getTypeTitle()} text={getTypeDescription()} />}
|
||||
|
||||
<InputGroup title={t("models.view.object")}>
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-12">
|
||||
<InputRadioGroupCards
|
||||
display="name"
|
||||
columns={EntityViewLayoutTypes.length}
|
||||
className="sm:col-span-12"
|
||||
name="layout"
|
||||
title={t("models.view.layout")}
|
||||
value={layout}
|
||||
onChange={(e) => setLayout((e?.toString() ?? "table") as "table" | "board" | "grid" | "card")}
|
||||
options={EntityViewLayoutTypes.map((f) => {
|
||||
return {
|
||||
name: t(f.labelKey),
|
||||
value: f.value,
|
||||
renderName: (
|
||||
<div className="flex items-center space-x-2">
|
||||
<EntityViewLayoutBadge layout={f.value} className="text-muted-foreground h-3 w-3" />
|
||||
<div>{t(f.labelKey)}</div>
|
||||
</div>
|
||||
),
|
||||
};
|
||||
})}
|
||||
/>
|
||||
|
||||
<InputText
|
||||
autoFocus
|
||||
className={clsx(isSystem ? "sm:col-span-6" : "sm:col-span-3")}
|
||||
name="name"
|
||||
title={t("models.entity.name")}
|
||||
value={name}
|
||||
setValue={(e) => setName(e.toString().toLowerCase())}
|
||||
autoComplete="off"
|
||||
required
|
||||
// lowercase
|
||||
onBlur={() => {
|
||||
if (!item) {
|
||||
let title = StringUtils.capitalize(name.toLowerCase());
|
||||
// replace - occurrences with spaces
|
||||
title = title.replace(/-/g, " ");
|
||||
setTitle(title);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<InputText
|
||||
className={clsx(isSystem ? "sm:col-span-6" : "sm:col-span-3")}
|
||||
name="title"
|
||||
title={t("models.entity.title")}
|
||||
value={title}
|
||||
setValue={setTitle}
|
||||
autoComplete="off"
|
||||
required
|
||||
withTranslation={true}
|
||||
/>
|
||||
{!isSystem && (
|
||||
<Fragment>
|
||||
<InputNumber className="sm:col-span-3" name="pageSize" title={t("models.view.pageSize")} value={pageSize} setValue={setPageSize} min={1} max={500} required />
|
||||
<InputNumber
|
||||
className="sm:col-span-3"
|
||||
name="order"
|
||||
title={t("models.entity.order")}
|
||||
value={order}
|
||||
setValue={setOrder}
|
||||
disabled={!item}
|
||||
min={1}
|
||||
max={99}
|
||||
required
|
||||
/>
|
||||
<InputCheckboxInline className="sm:col-span-12" name="isDefault" title={t("models.view.isDefault")} value={isDefault} setValue={setIsDefault} />
|
||||
</Fragment>
|
||||
)}
|
||||
</div>
|
||||
</InputGroup>
|
||||
|
||||
{layout === "board" && (
|
||||
<InputGroup title={t("models.view.board")}>
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-12">
|
||||
<>
|
||||
<InputSelect className="sm:col-span-6" name="groupBy" title={t("models.view.groupBy")} value={groupBy} setValue={setGroupBy} options={groupByOptions} />
|
||||
<InputSelect
|
||||
className="sm:col-span-6"
|
||||
name="groupByPropertyId"
|
||||
title={t("models.view.property")}
|
||||
value={groupByPropertyId}
|
||||
setValue={setGroupByPropertyId}
|
||||
options={selectProperties.map((item) => {
|
||||
return {
|
||||
name: t(item.title),
|
||||
value: item.id,
|
||||
};
|
||||
})}
|
||||
/>
|
||||
</>
|
||||
</div>
|
||||
</InputGroup>
|
||||
)}
|
||||
|
||||
{layout === "grid" && (
|
||||
<InputGroup title={t("models.view.grid")}>
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-7">
|
||||
<InputNumber name="gridColumns" title={t("models.view.columns")} value={gridColumns} setValue={setGridColumns} min={0} max={12} required />
|
||||
<InputNumber name="gridColumnsSm" title="sm" value={gridColumnsSm} setValue={setGridColumnsSm} min={0} max={12} required />
|
||||
<InputNumber name="gridColumnsMd" title="md" value={gridColumnsMd} setValue={setGridColumnsMd} min={0} max={12} required />
|
||||
<InputNumber name="gridColumnsLg" title="lg" value={gridColumnsLg} setValue={setGridColumnsLg} min={0} max={12} required />
|
||||
<InputNumber name="gridColumnsXl" title="xl" value={gridColumnsXl} setValue={setGridColumnsXl} min={0} max={12} required />
|
||||
<InputNumber name="gridColumns2xl" title="2xl" value={gridColumns2xl} setValue={setGridColumns2xl} min={0} max={12} required />
|
||||
|
||||
<InputSelect
|
||||
name="gridGap"
|
||||
title={t("models.view.gap")}
|
||||
value={gridGap}
|
||||
setValue={(e) => setGridGap(e?.toString() ?? "sm")}
|
||||
options={[
|
||||
{ name: "xs", value: "xs" },
|
||||
{ name: "sm", value: "sm" },
|
||||
{ name: "md", value: "md" },
|
||||
{ name: "lg", value: "lg" },
|
||||
{ name: "xl", value: "xl" },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</InputGroup>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<div className="divide-border divide-y">
|
||||
{properties.map((item, idx) => (
|
||||
<input key={idx} type="text" name="properties[]" readOnly hidden value={JSON.stringify(item)} />
|
||||
))}
|
||||
<div className="grid gap-2 sm:grid-cols-2">
|
||||
<div className="space-y-1">
|
||||
<div className="flex items-baseline space-x-1">
|
||||
<div className="text-sm font-medium">{t("shared.all")}</div>
|
||||
<div className="flex items-center space-x-1">
|
||||
<button
|
||||
type="button"
|
||||
className="text-muted-foreground text-xs"
|
||||
onClick={() => setProperties(possibleProperties)}
|
||||
disabled={properties.length === possibleProperties.length}
|
||||
>
|
||||
({t("shared.selectAll")})
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="border-border h-64 space-y-1 overflow-y-scroll rounded-md border-2 border-dashed p-2">
|
||||
{possibleProperties.map((item, idx) => (
|
||||
<div key={item.name}>
|
||||
<InputCheckboxInline
|
||||
name={"properties[" + idx + "].propertyId"}
|
||||
title={
|
||||
<div className="flex items-baseline space-x-1 truncate text-sm">
|
||||
<div className={clsx("truncate", item.name?.includes(".") ? "text-muted-foreground" : "text-foreground font-medium")}>
|
||||
{item.title ? t(item.title) : item.name}
|
||||
</div>
|
||||
<div
|
||||
className={clsx(
|
||||
"truncate text-xs font-normal",
|
||||
item.name?.includes(".") ? "text-muted-foreground italic" : "text-foreground font-bold"
|
||||
)}
|
||||
>
|
||||
({item?.name})
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
value={properties.find((f) => f.name === item.name) !== undefined}
|
||||
setValue={(e) => {
|
||||
if (e) {
|
||||
setProperties([
|
||||
...properties,
|
||||
{ propertyId: item.propertyId, name: item.name, title: item.title, order: OrderHelper.getNextOrder(properties) },
|
||||
]);
|
||||
} else {
|
||||
setProperties(properties.filter((f) => f.name !== item.name));
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<div className="flex items-baseline space-x-1">
|
||||
<div className="text-sm font-medium">{t("models.view.propertiesDisplayed")}</div>
|
||||
<button type="button" className="text-muted-foreground text-xs" onClick={() => setProperties([])} disabled={properties.length === 0}>
|
||||
({t("shared.clear")})
|
||||
</button>
|
||||
</div>
|
||||
<div className="border-border h-64 space-y-1 overflow-y-scroll rounded-md border-2 border-dashed p-2">
|
||||
{properties
|
||||
.sort((a, b) => a.order - b.order)
|
||||
.map((item, idx) => (
|
||||
<div key={idx} className="flex items-baseline space-x-1 text-sm">
|
||||
<div className="shrink-0">
|
||||
<OrderIndexButtons
|
||||
idx={idx}
|
||||
items={properties.map((item, itemIdx) => {
|
||||
return {
|
||||
order: item.order,
|
||||
idx: itemIdx,
|
||||
};
|
||||
})}
|
||||
onChange={(newOrders) => {
|
||||
setProperties(
|
||||
properties.map((item, itemIdx) => {
|
||||
const newOrder = newOrders.find((f) => f.idx === itemIdx);
|
||||
if (newOrder) {
|
||||
return {
|
||||
...item,
|
||||
order: newOrder.order,
|
||||
};
|
||||
} else {
|
||||
return item;
|
||||
}
|
||||
})
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className={clsx("truncate", item.name?.includes(".") ? "text-muted-foreground" : "text-foreground font-medium")}>
|
||||
{item.title ? t(item.title) : t(getPropertyTitle(item.name ?? ""))}{" "}
|
||||
<span className={clsx("text-xs font-normal", item.name?.includes(".") ? "text-muted-foreground italic" : "text-foreground font-bold")}>
|
||||
({item?.name})
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{!isSystem && (
|
||||
<Fragment>
|
||||
<InputGroup title={t("models.view.filters")}>
|
||||
{filters.map((item, idx) => (
|
||||
<input key={idx} type="text" name="filters[]" readOnly hidden value={JSON.stringify(item)} />
|
||||
))}
|
||||
<div className="mb-2 space-y-2">
|
||||
{filters.map((item, idx) => (
|
||||
<CollapsibleRow
|
||||
className="bg-secondary"
|
||||
initial={true}
|
||||
key={idx}
|
||||
title={`${item.name} (${item.condition}) ${item.value}`}
|
||||
value={
|
||||
<div className="flex items-center space-x-1 text-sm">
|
||||
<div className="font-medium">{item.name}</div>
|
||||
<div className="text-muted-foreground font-light">{item.condition}</div>
|
||||
<div className="">{item.value}</div>
|
||||
</div>
|
||||
}
|
||||
onRemove={() => setFilters(filters.filter((_, i) => i !== idx))}
|
||||
>
|
||||
<div className="grid grid-cols-12 gap-3">
|
||||
<div className="sm:col-span-2">
|
||||
<InputSelector
|
||||
withSearch={false}
|
||||
name={"filters[" + idx + "].match"}
|
||||
title={t("models.view.match")}
|
||||
value={item.match}
|
||||
setValue={(e) =>
|
||||
updateItemByIdx(filters, setFilters, idx, {
|
||||
match: e,
|
||||
})
|
||||
}
|
||||
options={[
|
||||
{ name: t("models.view.matchOperators.and"), value: "and" },
|
||||
{ name: t("models.view.matchOperators.or"), value: "or" },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
<div className="sm:col-span-4">
|
||||
<InputSelector
|
||||
withSearch={false}
|
||||
name={"filters[" + idx + "].propertyId"}
|
||||
title={t("models.view.property")}
|
||||
value={item.name}
|
||||
setValue={(e) =>
|
||||
updateItemByIdx(filters, setFilters, idx, {
|
||||
name: e,
|
||||
})
|
||||
}
|
||||
options={filterByProperties}
|
||||
/>
|
||||
</div>
|
||||
<div className="sm:col-span-3">
|
||||
<InputSelector
|
||||
withSearch={false}
|
||||
name={"filters[" + idx + "].condition"}
|
||||
title={t("shared.condition")}
|
||||
value={item.condition}
|
||||
setValue={(e) =>
|
||||
updateItemByIdx(filters, setFilters, idx, {
|
||||
condition: e,
|
||||
})
|
||||
}
|
||||
options={getPropertyConditionsByName(item.name)}
|
||||
/>
|
||||
</div>
|
||||
<Fragment>
|
||||
{getPropertyByName(item.name)?.type === PropertyType.BOOLEAN ? (
|
||||
<div className="sm:col-span-3">
|
||||
<InputSelector
|
||||
withSearch={false}
|
||||
name={"filters[" + idx + "].value"}
|
||||
title={t("shared.value")}
|
||||
value={item.value}
|
||||
setValue={(e) => updateItemByIdx(filters, setFilters, idx, { value: e })}
|
||||
options={[
|
||||
{ name: t("shared.true"), value: "true" },
|
||||
{ name: t("shared.false"), value: "false" },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
) : getPropertyByName(item.name)?.type === PropertyType.SELECT ? (
|
||||
<div className="sm:col-span-3">
|
||||
<InputSelector
|
||||
withSearch={false}
|
||||
name={"filters[" + idx + "].value"}
|
||||
title={t("shared.value")}
|
||||
value={item.value}
|
||||
setValue={(e) => updateItemByIdx(filters, setFilters, idx, { value: e })}
|
||||
options={
|
||||
getPropertyByName(item.name)?.options.map((i) => {
|
||||
return {
|
||||
name: translateSelectOptionLabel(t, i18n, entity.name, item.name, i),
|
||||
value: i.value,
|
||||
};
|
||||
}) ?? []
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className="sm:col-span-3">
|
||||
<InputText
|
||||
name={"filters[" + idx + "].value"}
|
||||
title={t("shared.value")}
|
||||
value={item.value}
|
||||
setValue={(e) => updateItemByIdx(filters, setFilters, idx, { value: e })}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Fragment>
|
||||
</div>
|
||||
</CollapsibleRow>
|
||||
))}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
const firstProperty = filterByProperties.length > 0 ? filterByProperties[0].value : "";
|
||||
setFilters([
|
||||
...filters,
|
||||
{
|
||||
name: firstProperty,
|
||||
condition: "equals",
|
||||
value: "",
|
||||
match: "and",
|
||||
},
|
||||
]);
|
||||
}}
|
||||
className="border-border hover:border-border relative block w-full rounded-lg border-2 border-dashed p-4 text-center focus:outline-hidden focus:ring-2 focus:ring-gray-500"
|
||||
>
|
||||
<span className="text-muted-foreground block text-xs font-normal">
|
||||
{filters.length === 0 ? t("models.view.noFilters") : t("models.view.addFilter")}
|
||||
</span>
|
||||
</button>
|
||||
</InputGroup>
|
||||
|
||||
{/* <InputGroup title="Sort">
|
||||
{sort.map((item, idx) => (
|
||||
<input key={idx} type="text" name="sort[]" readOnly hidden value={JSON.stringify(item)} />
|
||||
))}
|
||||
<div className="space-y-2 mb-2">
|
||||
{sort
|
||||
.sort((a, b) => a.order - b.order)
|
||||
.map((item, idx) => (
|
||||
<CollapsibleRow
|
||||
className="bg-secondary"
|
||||
key={idx}
|
||||
initial={true}
|
||||
title={`${item.name} (${item.asc ? "asc" : "desc"})`}
|
||||
value={
|
||||
<div className="flex space-x-1 items-center text-sm">
|
||||
<div className="font-medium">{item.name}</div>
|
||||
<div className="font-light text-muted-foreground">{item.asc ? "asc" : "desc"}</div>
|
||||
</div>
|
||||
}
|
||||
onRemove={() => setSort(sort.filter((_, i) => i !== idx))}
|
||||
>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<InputSelector
|
||||
withSearch={false}
|
||||
name={"sort[" + idx + "].name"}
|
||||
title="Property"
|
||||
value={item.name}
|
||||
setValue={(e) => updateItemByIdx(sort, setSort, idx, { name: e })}
|
||||
options={entity.properties.map((property) => {
|
||||
return {
|
||||
name: translatePropertyTitle(t, i18n, entity.name, property),
|
||||
value: property.name,
|
||||
};
|
||||
})}
|
||||
/>
|
||||
<InputSelect
|
||||
name={"sort[" + idx + "].order"}
|
||||
title="Order"
|
||||
value={item.asc ? "asc" : "desc"}
|
||||
setValue={(e) => updateItemByIdx(sort, setSort, idx, { asc: e?.toString() === "asc" })}
|
||||
options={[
|
||||
{
|
||||
name: "Ascending",
|
||||
value: "asc",
|
||||
},
|
||||
{
|
||||
name: "Descending",
|
||||
value: "desc",
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</CollapsibleRow>
|
||||
))}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
setSort([...sort, { name: entity.properties.find((f) => !f.isDefault)?.name ?? "", asc: true, order: OrderHelper.getNextOrder(sort) }])
|
||||
}
|
||||
className="relative block w-full border-2 border-border border-dashed rounded-lg p-4 text-center hover:border-border focus:outline-hidden focus:ring-2 focus:ring-gray-500"
|
||||
>
|
||||
<span className="block text-xs font-normal text-muted-foreground">{filters.length === 0 ? "No sort fields" : "Add sort"}</span>
|
||||
</button>
|
||||
</InputGroup> */}
|
||||
</Fragment>
|
||||
)}
|
||||
|
||||
<InputGroup title={t("shared.preview")}>
|
||||
<div className="space-y-2">
|
||||
<RowsList
|
||||
view={layout}
|
||||
entity={entity}
|
||||
items={fakeItems}
|
||||
columns={properties.map((p) => ({
|
||||
name: p.name ?? "",
|
||||
title: p.title ?? "",
|
||||
visible: true,
|
||||
}))}
|
||||
/>
|
||||
</div>
|
||||
</InputGroup>
|
||||
</FormGroup>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
interface Props {
|
||||
layout: string;
|
||||
className?: string;
|
||||
}
|
||||
export default function EntityViewLayoutBadge({ layout, className = "h-5 w-5 text-muted-foreground" }: Props) {
|
||||
return (
|
||||
<>
|
||||
{layout === "table" && (
|
||||
<svg xmlns="http://www.w3.org/2000/svg" className={className} viewBox="0 0 20 20" fill="currentColor">
|
||||
<path
|
||||
fillRule="evenodd"
|
||||
d="M5 4a3 3 0 00-3 3v6a3 3 0 003 3h10a3 3 0 003-3V7a3 3 0 00-3-3H5zm-1 9v-1h5v2H5a1 1 0 01-1-1zm7 1h4a1 1 0 001-1v-1h-5v2zm0-4h5V8h-5v2zM9 8H4v2h5V8z"
|
||||
clipRule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
{layout === "board" && (
|
||||
<svg xmlns="http://www.w3.org/2000/svg" className={className} viewBox="0 0 20 20" fill="currentColor">
|
||||
<path d="M2 4a1 1 0 011-1h2a1 1 0 011 1v12a1 1 0 01-1 1H3a1 1 0 01-1-1V4zM8 4a1 1 0 011-1h2a1 1 0 011 1v12a1 1 0 01-1 1H9a1 1 0 01-1-1V4zM15 3a1 1 0 00-1 1v12a1 1 0 001 1h2a1 1 0 001-1V4a1 1 0 00-1-1h-2z" />
|
||||
</svg>
|
||||
)}
|
||||
|
||||
{layout === "grid" && (
|
||||
<svg xmlns="http://www.w3.org/2000/svg" className={className} viewBox="0 0 20 20" fill="currentColor">
|
||||
<path d="M5 3a2 2 0 00-2 2v2a2 2 0 002 2h2a2 2 0 002-2V5a2 2 0 00-2-2H5zM5 11a2 2 0 00-2 2v2a2 2 0 002 2h2a2 2 0 002-2v-2a2 2 0 00-2-2H5zM11 5a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V5zM11 13a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z" />
|
||||
</svg>
|
||||
)}
|
||||
|
||||
{layout === "card" && (
|
||||
// <svg className={className} xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width="80" height="80" viewBox="0 0 80 80" fill="currentColor">
|
||||
// <path d="M 19 14 C 12.9375 14 8 18.9375 8 25 L 8 55 C 8 61.0625 12.9375 66 19 66 L 61 66 C 67.0625 66 72 61.0625 72 55 L 72 25 C 72 18.9375 67.0625 14 61 14 Z M 19 16 L 61 16 C 65.984375 16 70 20.015625 70 25 L 70 55 C 70 59.984375 65.984375 64 61 64 L 19 64 C 14.015625 64 10 59.984375 10 55 L 10 25 C 10 20.015625 14.015625 16 19 16 Z M 22 19 C 21.449219 19 21 19.449219 21 20 C 21 20.550781 21.449219 21 22 21 C 22.550781 21 23 20.550781 23 20 C 23 19.449219 22.550781 19 22 19 Z M 26 19 C 25.449219 19 25 19.449219 25 20 C 25 20.550781 25.449219 21 26 21 C 26.550781 21 27 20.550781 27 20 C 27 19.449219 26.550781 19 26 19 Z M 30 19 C 29.449219 19 29 19.449219 29 20 C 29 20.550781 29.449219 21 30 21 C 30.550781 21 31 20.550781 31 20 C 31 19.449219 30.550781 19 30 19 Z M 34 19 C 33.449219 19 33 19.449219 33 20 C 33 20.550781 33.449219 21 34 21 C 34.550781 21 35 20.550781 35 20 C 35 19.449219 34.550781 19 34 19 Z M 38 19 C 37.449219 19 37 19.449219 37 20 C 37 20.550781 37.449219 21 38 21 C 38.550781 21 39 20.550781 39 20 C 39 19.449219 38.550781 19 38 19 Z M 42 19 C 41.449219 19 41 19.449219 41 20 C 41 20.550781 41.449219 21 42 21 C 42.550781 21 43 20.550781 43 20 C 43 19.449219 42.550781 19 42 19 Z M 46 19 C 45.449219 19 45 19.449219 45 20 C 45 20.550781 45.449219 21 46 21 C 46.550781 21 47 20.550781 47 20 C 47 19.449219 46.550781 19 46 19 Z M 50 19 C 49.449219 19 49 19.449219 49 20 C 49 20.550781 49.449219 21 50 21 C 50.550781 21 51 20.550781 51 20 C 51 19.449219 50.550781 19 50 19 Z M 54 19 C 53.449219 19 53 19.449219 53 20 C 53 20.550781 53.449219 21 54 21 C 54.550781 21 55 20.550781 55 20 C 55 19.449219 54.550781 19 54 19 Z M 58 19 C 57.449219 19 57 19.449219 57 20 C 57 20.550781 57.449219 21 58 21 C 58.550781 21 59 20.550781 59 20 C 59 19.449219 58.550781 19 58 19 Z M 18 20 C 17.449219 20 17 20.449219 17 21 C 17 21.550781 17.449219 22 18 22 C 18.550781 22 19 21.550781 19 21 C 19 20.449219 18.550781 20 18 20 Z M 62 20 C 61.449219 20 61 20.449219 61 21 C 61 21.550781 61.449219 22 62 22 C 62.550781 22 63 21.550781 63 21 C 63 20.449219 62.550781 20 62 20 Z M 15 23 C 14.449219 23 14 23.449219 14 24 C 14 24.550781 14.449219 25 15 25 C 15.550781 25 16 24.550781 16 24 C 16 23.449219 15.550781 23 15 23 Z M 65 23 C 64.449219 23 64 23.449219 64 24 C 64 24.550781 64.449219 25 65 25 C 65.550781 25 66 24.550781 66 24 C 66 23.449219 65.550781 23 65 23 Z M 14 27 C 13.449219 27 13 27.449219 13 28 C 13 28.550781 13.449219 29 14 29 C 14.550781 29 15 28.550781 15 28 C 15 27.449219 14.550781 27 14 27 Z M 66 27 C 65.449219 27 65 27.449219 65 28 C 65 28.550781 65.449219 29 66 29 C 66.550781 29 67 28.550781 67 28 C 67 27.449219 66.550781 27 66 27 Z M 14 31 C 13.449219 31 13 31.449219 13 32 C 13 32.550781 13.449219 33 14 33 C 14.550781 33 15 32.550781 15 32 C 15 31.449219 14.550781 31 14 31 Z M 66 31 C 65.449219 31 65 31.449219 65 32 C 65 32.550781 65.449219 33 66 33 C 66.550781 33 67 32.550781 67 32 C 67 31.449219 66.550781 31 66 31 Z M 14 35 C 13.449219 35 13 35.449219 13 36 C 13 36.550781 13.449219 37 14 37 C 14.550781 37 15 36.550781 15 36 C 15 35.449219 14.550781 35 14 35 Z M 66 35 C 65.449219 35 65 35.449219 65 36 C 65 36.550781 65.449219 37 66 37 C 66.550781 37 67 36.550781 67 36 C 67 35.449219 66.550781 35 66 35 Z M 14 39 C 13.449219 39 13 39.449219 13 40 C 13 40.550781 13.449219 41 14 41 C 14.550781 41 15 40.550781 15 40 C 15 39.449219 14.550781 39 14 39 Z M 66 39 C 65.449219 39 65 39.449219 65 40 C 65 40.550781 65.449219 41 66 41 C 66.550781 41 67 40.550781 67 40 C 67 39.449219 66.550781 39 66 39 Z M 14 43 C 13.449219 43 13 43.449219 13 44 C 13 44.550781 13.449219 45 14 45 C 14.550781 45 15 44.550781 15 44 C 15 43.449219 14.550781 43 14 43 Z M 66 43 C 65.449219 43 65 43.449219 65 44 C 65 44.550781 65.449219 45 66 45 C 66.550781 45 67 44.550781 67 44 C 67 43.449219 66.550781 43 66 43 Z M 14 47 C 13.449219 47 13 47.449219 13 48 C 13 48.550781 13.449219 49 14 49 C 14.550781 49 15 48.550781 15 48 C 15 47.449219 14.550781 47 14 47 Z M 66 47 C 65.449219 47 65 47.449219 65 48 C 65 48.550781 65.449219 49 66 49 C 66.550781 49 67 48.550781 67 48 C 67 47.449219 66.550781 47 66 47 Z M 14 51 C 13.449219 51 13 51.449219 13 52 C 13 52.550781 13.449219 53 14 53 C 14.550781 53 15 52.550781 15 52 C 15 51.449219 14.550781 51 14 51 Z M 66 51 C 65.449219 51 65 51.449219 65 52 C 65 52.550781 65.449219 53 66 53 C 66.550781 53 67 52.550781 67 52 C 67 51.449219 66.550781 51 66 51 Z M 15 55 C 14.449219 55 14 55.449219 14 56 C 14 56.550781 14.449219 57 15 57 C 15.550781 57 16 56.550781 16 56 C 16 55.449219 15.550781 55 15 55 Z M 65 55 C 64.449219 55 64 55.449219 64 56 C 64 56.550781 64.449219 57 65 57 C 65.550781 57 66 56.550781 66 56 C 66 55.449219 65.550781 55 65 55 Z M 18 58 C 17.449219 58 17 58.449219 17 59 C 17 59.550781 17.449219 60 18 60 C 18.550781 60 19 59.550781 19 59 C 19 58.449219 18.550781 58 18 58 Z M 62 58 C 61.449219 58 61 58.449219 61 59 C 61 59.550781 61.449219 60 62 60 C 62.550781 60 63 59.550781 63 59 C 63 58.44921
Line truncated
|
||||
// </svg>
|
||||
<svg className={className} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 100">
|
||||
<rect x="20" y="20" rx="10" ry="10" width="80" height="80" fill="currentColor" />
|
||||
<rect x="110" y="20" rx="10" ry="10" width="80" height="80" fill="currentColor" />
|
||||
</svg>
|
||||
|
||||
// <span className="text-xs font-medium italic">Row</span>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
import { Link } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import TenantBadge from "~/components/core/tenants/TenantBadge";
|
||||
import UserBadge from "~/components/core/users/UserBadge";
|
||||
import DateCell from "~/components/ui/dates/DateCell";
|
||||
import CheckIcon from "~/components/ui/icons/CheckIcon";
|
||||
import XIcon from "~/components/ui/icons/XIcon";
|
||||
import ShowPayloadModalButton from "~/components/ui/json/ShowPayloadModalButton";
|
||||
import TableSimple from "~/components/ui/tables/TableSimple";
|
||||
import { EntityViewWithTenantAndUser } from "~/utils/db/entities/entityViews.db.server";
|
||||
import { defaultDisplayProperties } from "~/utils/helpers/PropertyHelper";
|
||||
import EntityViewLayoutBadge from "./EntityViewLayoutBadge";
|
||||
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { useLocaleFormatters } from "~/locale/format";
|
||||
import { translateEntityTitlePlural, translateEntityViewTitle } from "~/utils/i18n/translateLabel";
|
||||
|
||||
export default function EntityViewsTable({
|
||||
items,
|
||||
onClickRoute,
|
||||
}: {
|
||||
items: EntityViewWithTenantAndUser[];
|
||||
onClickRoute: (item: EntityViewWithTenantAndUser) => string;
|
||||
}) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const formatters = useLocaleFormatters();
|
||||
return (
|
||||
<TableSimple
|
||||
items={items}
|
||||
actions={[
|
||||
{
|
||||
title: t("shared.edit"),
|
||||
onClickRoute: (_, i) => onClickRoute(i),
|
||||
},
|
||||
]}
|
||||
headers={[
|
||||
// {
|
||||
// name: "debug",
|
||||
// title: "Debug",
|
||||
// value: (i) => (
|
||||
// <div>
|
||||
// <ShowPayloadModalButton title="Debug" description="Debug" payload={JSON.stringify(i, null, 2)} />
|
||||
// </div>
|
||||
// ),
|
||||
// },
|
||||
{
|
||||
name: "entity",
|
||||
title: t("models.entity.object"),
|
||||
value: (i) => (
|
||||
<div className="flex flex-col">
|
||||
<div>{translateEntityTitlePlural(t, i18n, i.entity)}</div>
|
||||
{/* <div className="text-xs text-muted-foreground">{i.entity.name}</div> */}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "Layout",
|
||||
title: t("models.view.layout"),
|
||||
value: (i) => (
|
||||
<div>
|
||||
<EntityViewLayoutBadge layout={i.layout} className="text-muted-foreground mx-auto h-5 w-5" />
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "title",
|
||||
title: t("models.view.title"),
|
||||
className: "w-full",
|
||||
value: (i) => (
|
||||
<div className="flex flex-col">
|
||||
<Link to={adminPath(`entities/views/${i.id}`, { mode: "host-aware" })} className="hover:underline">
|
||||
{translateEntityViewTitle(t, i18n, i.entity.name, i)}
|
||||
</Link>
|
||||
{/* <div className="text-xs text-muted-foreground">{i.name}</div> */}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "appliesTo",
|
||||
title: t("models.view.appliesTo"),
|
||||
value: (i) => (
|
||||
<div className="flex items-center space-x-1">
|
||||
<div>
|
||||
{i.isSystem ? (
|
||||
<div className="font-medium italic">{t("models.view.appliesToStates.systemView")}</div>
|
||||
) : !i.tenant && !i.user ? (
|
||||
<div className="flex flex-col">
|
||||
<div className="font-medium italic">{t("models.view.appliesToStates.defaultAllAccounts")}</div>
|
||||
</div>
|
||||
) : i.tenant && i.user ? (
|
||||
<div className="flex items-center space-x-1">
|
||||
<div>
|
||||
<TenantBadge item={i.tenant} />
|
||||
</div>
|
||||
<div>→</div>
|
||||
<UserBadge item={i.user} />
|
||||
</div>
|
||||
) : i.tenant ? (
|
||||
<div>
|
||||
<TenantBadge item={i.tenant} />
|
||||
</div>
|
||||
) : i.user ? (
|
||||
<div>
|
||||
<UserBadge item={i.user} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="italic text-red-500">{t("models.view.appliesToStates.invalid")}</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "properties",
|
||||
title: t("models.view.properties"),
|
||||
value: (i) => {
|
||||
return (
|
||||
<div>
|
||||
{/* {i.properties
|
||||
.map((p) => {
|
||||
const defaultProperty = defaultDisplayProperties.find((f) => f.name === p.name);
|
||||
if (defaultProperty) {
|
||||
return t(defaultProperty.title);
|
||||
}
|
||||
return p.name;
|
||||
})
|
||||
.join(", ")} */}
|
||||
<ShowPayloadModalButton
|
||||
description={t("models.view.payload.propertiesCount", { count: i.properties.length })}
|
||||
title={t("models.view.properties")}
|
||||
payload={JSON.stringify(
|
||||
i.properties.map((p) => {
|
||||
const defaultProperty = defaultDisplayProperties.find((f) => f.name === p.name);
|
||||
if (defaultProperty) {
|
||||
return t(defaultProperty.title);
|
||||
}
|
||||
return p.name;
|
||||
}),
|
||||
null,
|
||||
2
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "filters",
|
||||
title: t("models.view.filters"),
|
||||
value: (i) => (
|
||||
<div>
|
||||
<ShowPayloadModalButton
|
||||
description={t("models.view.payload.filtersCount", { count: i.filters.length })}
|
||||
title={t("models.view.filters")}
|
||||
payload={JSON.stringify(
|
||||
i.filters.map((p) => {
|
||||
return `${p.name} ${p.condition} ${p.value}`;
|
||||
}),
|
||||
null,
|
||||
2
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "sort",
|
||||
title: t("models.view.sort"),
|
||||
value: (i) => (
|
||||
<div>
|
||||
<ShowPayloadModalButton
|
||||
description={t("models.view.payload.sortCount", { count: i.sort.length })}
|
||||
title={t("models.view.sort")}
|
||||
payload={JSON.stringify(
|
||||
i.sort.map((p) => {
|
||||
return `${p.name} ${p.asc ? "asc" : "desc"}`;
|
||||
}),
|
||||
null,
|
||||
2
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "pageSize",
|
||||
title: t("models.view.pageSize"),
|
||||
value: (i) => <div>{formatters.number(i.pageSize)}</div>,
|
||||
},
|
||||
{
|
||||
name: "isDefault",
|
||||
title: t("models.view.isDefault"),
|
||||
value: (i) => <div>{i.isDefault ? <CheckIcon className="h-5 w-5 text-green-500" /> : <XIcon className="text-muted-foreground h-5 w-5" />}</div>,
|
||||
},
|
||||
{
|
||||
name: "updatedAt",
|
||||
title: t("shared.updatedAt"),
|
||||
value: (i) => <DateCell date={i.updatedAt ?? null} />,
|
||||
},
|
||||
{
|
||||
name: "createdAt",
|
||||
title: t("shared.createdAt"),
|
||||
value: (i) => <DateCell date={i.createdAt ?? null} />,
|
||||
},
|
||||
{
|
||||
name: "createdBy",
|
||||
title: t("shared.createdBy"),
|
||||
value: (i) => (i.createdByUser ? <UserBadge item={i.createdByUser} /> : <div>-</div>),
|
||||
},
|
||||
]}
|
||||
noRecords={
|
||||
<div className="p-12 text-center">
|
||||
<h3 className="text-foreground mt-1 text-sm font-medium">{t("models.view.empty.title")}</h3>
|
||||
<p className="text-muted-foreground mt-1 text-sm">{t("models.view.empty.description")}</p>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const tablePath = path.resolve(process.cwd(), "apps/web/app/components/entities/views/EntityViewsTable.tsx");
|
||||
const formPath = path.resolve(process.cwd(), "apps/web/app/components/entities/views/EntityViewForm.tsx");
|
||||
const layoutTypePath = path.resolve(process.cwd(), "apps/web/app/modules/rows/dtos/EntityViewLayoutType.ts");
|
||||
|
||||
describe("entity view labels i18n", () => {
|
||||
it("uses semantic translation keys for view table and form labels", () => {
|
||||
const source = `${fs.readFileSync(tablePath, "utf8")}\n${fs.readFileSync(formPath, "utf8")}`;
|
||||
|
||||
expect(source).toContain("models.view.appliesToStates.systemView");
|
||||
expect(source).toContain("models.view.payload.propertiesCount");
|
||||
expect(source).toContain("models.view.empty.title");
|
||||
expect(source).toContain("models.view.propertiesDisplayed");
|
||||
expect(source).toContain("models.view.matchOperators.and");
|
||||
expect(source).toContain("models.view.systemTitle");
|
||||
expect(source).toContain("translateEntityTitlePlural(t, i18n, entity)");
|
||||
expect(source).toContain("translatePropertyTitle(t, i18n, entity.name, property)");
|
||||
expect(source).toContain("translateSelectOptionLabel(t, i18n, entity.name, item.name, i)");
|
||||
expect(source).toContain("shared.condition");
|
||||
expect(source).not.toContain("ui.autogenerated");
|
||||
expect(source).not.toContain('"System - "');
|
||||
expect(source).not.toContain('"AND"');
|
||||
expect(source).not.toContain('"True"');
|
||||
expect(source).not.toContain("t(entity.titlePlural)");
|
||||
expect(source).not.toContain("t(property.title)");
|
||||
expect(source).not.toContain('" - " + t(i.name)');
|
||||
});
|
||||
|
||||
it("renders entity view layout options through semantic label keys", () => {
|
||||
const formSource = fs.readFileSync(formPath, "utf8");
|
||||
const layoutTypeSource = fs.readFileSync(layoutTypePath, "utf8");
|
||||
|
||||
expect(layoutTypeSource).toContain('labelKey: "models.view.layouts.table"');
|
||||
expect(layoutTypeSource).toContain('labelKey: "models.view.layouts.grid"');
|
||||
expect(layoutTypeSource).toContain('labelKey: "models.view.layouts.card"');
|
||||
expect(layoutTypeSource).toContain('labelKey: "models.view.layouts.board"');
|
||||
expect(layoutTypeSource).not.toContain('name: "Table"');
|
||||
expect(layoutTypeSource).not.toContain('name: "Grid"');
|
||||
expect(layoutTypeSource).not.toContain('name: "Card"');
|
||||
expect(layoutTypeSource).not.toContain('name: "Board"');
|
||||
expect(formSource).toContain("name: t(f.labelKey)");
|
||||
expect(formSource).toContain("<div>{t(f.labelKey)}</div>");
|
||||
expect(formSource).not.toContain("name: f.name");
|
||||
expect(formSource).not.toContain("{f.name}");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user