Track HiveGrid Cloud planning reference

This commit is contained in:
david committed 2026-06-26 20:48:01 +02:00
1 parent b3d5ea6764
commit e341c5938a
5784 files changed
+1104929 -3

No files matched your search

@@ -0,0 +1,44 @@
import { TFunction, t as i18nT } from "i18next";
import { useTranslation } from "react-i18next";
import { Colors } from "~/application/enums/shared/Colors";
import SimpleBadge from "~/components/ui/badges/SimpleBadge";
import CheckIcon from "~/components/ui/icons/CheckIcon";
import XIcon from "~/components/ui/icons/XIcon";
import { BooleanFormatType } from "~/utils/shared/BooleanUtils";
export function getBooleanAsStringValue({ value, format, t }: { value?: boolean; format?: BooleanFormatType; t?: TFunction }) {
const translate = t ?? i18nT;
return !format || format === "yesNo"
? value
? translate("shared.yes")
: translate("shared.no")
: format === "trueFalse"
? value
? translate("shared.true")
: translate("shared.false")
: format === "enabledDisabled"
? value
? translate("shared.enabled")
: translate("shared.disabled")
: format === "onOff"
? value
? translate("shared.on")
: translate("shared.off")
: format === "activeInactive"
? value
? translate("shared.active")
: translate("shared.inactive")
: "";
}
export default function RowBooleanCell({ value, format }: { value?: boolean; format?: BooleanFormatType }) {
const { t } = useTranslation();
return (
<>
{!format ? (
<div>{value ? <CheckIcon className="h-4 w-4 text-teal-500" /> : <XIcon className="text-muted-foreground h-4 w-4" />}</div>
) : (
<SimpleBadge title={getBooleanAsStringValue({ value, format, t })} color={value ? Colors.GREEN : Colors.GRAY} />
)}
</>
);
}
@@ -0,0 +1,29 @@
import { useTranslation } from "react-i18next";
export default function RowCreatedByCell({
user,
apiKey,
}: {
user?: { firstName: string; lastName: string; email: string } | null;
apiKey?: { alias: string } | null;
}) {
const { t } = useTranslation();
return (
<div>
{user ? (
<div className="flex flex-col text-xs">
<div className="font-medium">
{user?.firstName} {user?.lastName}
</div>
<div>{user?.email}</div>
</div>
) : apiKey ? (
<div>
{t("models.apiKey.object")}: {apiKey.alias}
</div>
) : (
<div></div>
)}
</div>
);
}
@@ -0,0 +1,53 @@
import { createLocaleFormatters, type LocaleFormatters, useLocaleFormatters } from "~/locale/format";
export type DateFormatType = "YYYY-MM-DD" | "DD-MM-YYYY" | "MM-DD-YYYY" | "diff";
const fallbackFormatters = createLocaleFormatters("en");
function padDatePart(value: number) {
return value.toString().padStart(2, "0");
}
function formatExplicitDate(value: Date, pattern: Exclude<DateFormatType, "diff">) {
const year = value.getFullYear();
const month = padDatePart(value.getMonth() + 1);
const day = padDatePart(value.getDate());
if (pattern === "YYYY-MM-DD") {
return `${year}-${month}-${day}`;
}
if (pattern === "DD-MM-YYYY") {
return `${day}-${month}-${year}`;
}
return `${month}-${day}-${year}`;
}
export function getDateAsString({
value,
format,
formatters = fallbackFormatters,
}: {
value?: Date | null;
format?: DateFormatType;
formatters?: LocaleFormatters;
}) {
if (!value) {
return "";
}
switch (format) {
case "YYYY-MM-DD":
case "DD-MM-YYYY":
case "MM-DD-YYYY":
return formatExplicitDate(value, format);
case "diff":
return formatters.relativeDate(value);
default:
return formatters.date(value, { dateStyle: "medium" });
}
}
export default function RowDateCell({ value, format }: { value?: Date | null; format?: DateFormatType }) {
const formatters = useLocaleFormatters();
const text = getDateAsString({ value, format, formatters });
return <>{!value ? <div></div> : <div>{text}</div>}</>;
}
@@ -0,0 +1,41 @@
import { Link } from "react-router";
import { useLocaleFormatters } from "~/locale/format";
export default function RowFolioCell({ prefix, folio, href, onClick }: { prefix: string; folio: number; href?: string; onClick?: () => void }) {
const formatters = useLocaleFormatters();
const folioText = formatters.number(folio ?? 0, {
maximumFractionDigits: 0,
minimumIntegerDigits: 4,
useGrouping: false,
});
const text = `${prefix}-${folioText}`;
return (
<>
{href ? (
<Link
to={href}
onClick={(e) => {
e.stopPropagation();
}}
className="hover border-border text-muted-foreground hover:text-foreground bg-secondary rounded-md border border-b px-1 py-0.5 text-center text-sm hover:underline"
>
{text}
</Link>
) : onClick ? (
<button
type="button"
onClick={(e) => {
e.stopPropagation();
onClick();
}}
className="hover border-border text-muted-foreground hover:text-foreground bg-secondary rounded-md border border-b px-1 py-0.5 text-center text-sm hover:underline"
>
{text}
</button>
) : (
<div>{text}</div>
)}
</>
);
}
@@ -0,0 +1,52 @@
import clsx from "clsx";
import { Fragment } from "react";
import { MediaDto } from "~/application/dtos/entities/MediaDto";
import DownloadIcon from "~/components/ui/icons/DownloadIcon";
export default function RowMediaCell({ media, layout = "table" }: { media: MediaDto[] | undefined; layout?: string }) {
const onDownload = (media: MediaDto) => {
const downloadLink = document.createElement("a");
downloadLink.href = media.publicUrl ?? media.file;
downloadLink.download = media.name;
downloadLink.click();
};
function getFileName(name: string) {
let fileName = name;
if (name.includes("/")) {
fileName = name.split("/").pop() ?? name;
}
if (name.includes("\\")) {
fileName = name.split("\\").pop() ?? name;
}
return fileName;
}
return (
<Fragment>
<div className={clsx(layout === "table" ? "flex max-h-12 items-center space-x-2 overflow-x-visible truncate" : "grid max-h-60 gap-1 overflow-auto")}>
{media
?.filter((f) => f.type.includes("image"))
.map((item) => {
return <img key={item.name} className={clsx("object-cover", layout === "table" ? "h-10" : "")} src={item.publicUrl ?? item.file} alt={item.name} />;
})}
{media
?.filter((f) => !f.type.includes("image"))
.map((item, idx) => {
return (
<button
type="button"
key={idx}
onClick={() => onDownload(item)}
className={
"hover:border-border text-muted-foreground hover:text-foreground flex items-center space-x-1 border-b border-transparent text-xs hover:border-dashed"
}
>
<div className="font-normal">{getFileName(item.title)}</div>
<DownloadIcon className="h-3 w-3" />
</button>
);
})}
</div>
</Fragment>
);
}
@@ -0,0 +1,59 @@
import RatingBadge from "~/components/ui/badges/RatingBadge";
import { createLocaleFormatters, type LocaleFormatters, useLocaleFormatters } from "~/locale/format";
export type NumberFormatType = "integer" | "decimal" | "currency" | "percentage" | "rating";
const fallbackFormatters = createLocaleFormatters("en");
const defaultCurrency = "USD";
type NumberOptions = Parameters<LocaleFormatters["number"]>[1];
const fixedDecimalOptions: NumberOptions = { minimumFractionDigits: 2, maximumFractionDigits: 2 };
export function getNumberAsStringValue({
value,
format,
currencySymbol,
formatters = fallbackFormatters,
}: {
value?: number | null;
format?: NumberFormatType;
currencySymbol?: string;
formatters?: LocaleFormatters;
}) {
if (value === null || value === undefined) {
return "";
}
switch (format) {
case "integer":
return formatters.number(value, { maximumFractionDigits: 0 });
case "decimal":
return formatters.number(value, fixedDecimalOptions);
case "currency":
return currencySymbol ? `${currencySymbol}${formatters.number(value, fixedDecimalOptions)}` : formatters.currency(value, defaultCurrency, fixedDecimalOptions);
case "percentage":
return formatters.percent(value / 100, fixedDecimalOptions);
default:
return formatters.number(value);
}
}
export default function RowNumberCell({ value, format, currencySymbol }: { value?: number | null; format?: NumberFormatType; currencySymbol?: string }) {
const formatters = useLocaleFormatters();
const formattedValue = getNumberAsStringValue({ value, format, currencySymbol, formatters });
return (
<>
{value === null || value === undefined ? (
<div></div>
) : (
<div>
{format === "rating" ? (
<span>
<RatingBadge value={value} />
</span>
) : (
<span>{formattedValue}</span>
)}
</div>
)}
</>
);
}
@@ -0,0 +1,17 @@
import { RowValueRangeDto } from "~/application/dtos/entities/RowValueRangeDto";
import RowDateCell from "./RowDateCell";
import { DateFormatType } from "~/utils/shared/DateUtils";
interface Props {
value: RowValueRangeDto;
format?: DateFormatType;
}
export default function RowRangeDateCell({ value, format }: Props) {
return (
<div className="flex items-center space-x-1">
<RowDateCell value={value?.dateMin ?? undefined} format={format} />
<div className="text-muted-foreground">-</div>
<RowDateCell value={value?.dateMax ?? undefined} format={format} />
</div>
);
}
@@ -0,0 +1,18 @@
import { RowValueRangeDto } from "~/application/dtos/entities/RowValueRangeDto";
import { NumberFormatType } from "~/utils/shared/NumberUtils";
import RowNumberCell from "./RowNumberCell";
interface Props {
value: RowValueRangeDto;
format?: NumberFormatType;
currencySymbol?: string;
}
export default function RowRangeNumberCell({ value, format, currencySymbol }: Props) {
return (
<div className="flex items-center space-x-1">
<RowNumberCell value={Number(value?.numberMin) ?? undefined} format={format} currencySymbol={currencySymbol} />
<div className="text-muted-foreground">-</div>
<RowNumberCell value={Number(value?.numberMax) ?? undefined} format={format} currencySymbol={currencySymbol} />
</div>
);
}
@@ -0,0 +1,42 @@
import { Link } from "react-router";
import { Fragment } from "react";
import { TFunction } from "i18next";
import { RowDto } from "~/modules/rows/repositories/RowDto";
import { EntitiesApi } from "~/utils/api/.server/EntitiesApi";
import { EntityWithDetails } from "~/utils/db/entities/entities.db.server";
import EntityHelper from "~/utils/helpers/EntityHelper";
import RowHelper from "~/utils/helpers/RowHelper";
export default function RowRelationshipRow({
entity,
item,
onRelatedRowClick,
routes,
t,
}: {
entity: EntityWithDetails;
item: RowDto;
onRelatedRowClick?: () => void;
routes?: EntitiesApi.Routes;
t: TFunction;
}) {
return (
<Fragment>
{onRelatedRowClick !== undefined ? (
<button type="button" onClick={onRelatedRowClick} className="hover truncate text-left text-sm hover:underline">
{RowHelper.getTextDescription({ entity: entity, item, t })}
</button>
) : !routes || !EntityHelper.getRoutes({ routes, entity: entity, item })?.overview ? (
<div className="hover truncate text-left text-sm hover:underline">{RowHelper.getTextDescription({ entity: entity, item, t })}</div>
) : (
<Link
onClick={(e) => e.stopPropagation()}
to={EntityHelper.getRoutes({ routes, entity: entity, item })?.overview ?? ""}
className="hover truncate text-left text-sm hover:underline"
>
{RowHelper.getTextDescription({ entity: entity, item, t })}
</Link>
)}
</Fragment>
);
}
@@ -0,0 +1,70 @@
import { useTranslation } from "react-i18next";
import { RowDto } from "~/modules/rows/repositories/RowDto";
import { EntityWithDetails } from "~/utils/db/entities/entities.db.server";
import { RowWithDetails } from "~/utils/db/entities/rows.db.server";
import RowRelationshipRow from "./RowRelationshipRow";
import { EntitiesApi } from "~/utils/api/.server/EntitiesApi";
import { translateEntityTitle } from "~/utils/i18n/translateLabel";
export default function RowRelationshipRowsByEntity({
entity,
item,
allEntities,
onRelatedRowClick,
routes,
type,
}: {
entity: EntityWithDetails;
item: RowWithDetails;
allEntities: EntityWithDetails[];
onRelatedRowClick?: () => void;
routes?: EntitiesApi.Routes;
type: "parents" | "children";
}) {
const { t, i18n } = useTranslation();
const relatedEntities = type === "children" ? entity.childEntities.filter((f) => f.hiddenIfEmpty) : entity.parentEntities.filter((f) => f.hiddenIfEmpty);
let relatedRows: any[] = [];
if (type === "children") {
relatedRows = item.childRows?.filter((f) => relatedEntities.some((p) => p.id === f.relationshipId)) ?? [];
} else {
relatedRows = item.parentRows?.filter((f) => relatedEntities.some((p) => p.id === f.relationshipId)) ?? [];
}
const relatedRowsByEntity: { entity: EntityWithDetails; rows: RowDto[] }[] = [];
relatedRows?.forEach((row) => {
const entity = type === "children" ? allEntities.find((f) => f.id === row.child.entityId) : allEntities.find((f) => f.id === row.parent.entityId);
if (!entity) {
return null;
}
const existing = relatedRowsByEntity.find((f) => f.entity.id === entity.id);
if (existing) {
existing.rows.push(type === "children" ? row.child : row.parent);
} else {
relatedRowsByEntity.push({ entity, rows: [type === "children" ? row.child : row.parent] });
}
});
return (
<div>
{relatedRows.length === 0 ? (
<div className="text-muted-foreground px-1 pt-1 pb-0.5 text-center text-sm italic">{t("shared.none")}</div>
) : (
<ul className="flex max-h-20 max-w-lg flex-col space-y-1 overflow-auto">
{relatedRowsByEntity.map(({ entity, rows }) => {
return (
<div className="space-y-1" key={entity.id}>
<div className="text-muted-foreground text-xs font-medium">{translateEntityTitle(t, i18n, entity)}</div>
{rows.map((row) => {
return (
<li key={row.id}>
<RowRelationshipRow entity={entity} item={row} onRelatedRowClick={onRelatedRowClick} routes={routes} t={t} />
</li>
);
})}
</div>
);
})}
</ul>
)}
</div>
);
}
@@ -0,0 +1,48 @@
import { render, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { Colors } from "~/application/enums/shared/Colors";
import RowSelectedOptionCell from "./RowSelectedOptionCell";
const translations: Record<string, string> = {
"models.contact.status.options.customer": "Kunde",
};
vi.mock("react-i18next", () => ({
useTranslation: () => ({
t: (key: string) => translations[key] ?? key,
i18n: {
exists: (key: string) => key in translations,
},
}),
}));
describe("RowSelectedOptionCell", () => {
it("renders seed select option labels through model translation fallbacks", () => {
render(
<RowSelectedOptionCell
value="customer"
entityName="contact"
propertyName="status"
display="Name"
options={[{ value: "customer", name: "Customer", color: Colors.GREEN }]}
/>
);
expect(screen.getByText("Kunde")).toBeTruthy();
expect(screen.queryByText("Customer")).toBeNull();
});
it("keeps custom option labels literal when no model translation exists", () => {
render(
<RowSelectedOptionCell
value="vip"
entityName="contact"
propertyName="status"
display="Name"
options={[{ value: "vip", name: "VIP customer", color: Colors.YELLOW }]}
/>
);
expect(screen.getByText("VIP customer")).toBeTruthy();
});
});
@@ -0,0 +1,35 @@
import { Colors } from "~/application/enums/shared/Colors";
import RenderOption from "../../properties/select/RenderOption";
import { SelectOptionsDisplay } from "~/utils/shared/SelectOptionsUtils";
import { translateSelectOptionLabel } from "~/utils/i18n/translateLabel";
import { useTranslation } from "react-i18next";
type ItemDto = { value: string; name: string | null; color: Colors };
export default function RowSelectedOptionCell({
value,
options,
display = "Name",
entityName,
propertyName,
}: {
value: string;
options: ItemDto[];
display: SelectOptionsDisplay;
entityName?: string;
propertyName?: string;
}) {
const { t, i18n } = useTranslation();
const selected = options.find((f) => f.value === value);
if (options.length === 0 || !selected) {
return value;
}
const translatedSelected =
entityName && propertyName ? { ...selected, name: translateSelectOptionLabel(t, i18n, entityName, propertyName, selected) } : selected;
return (
<>
<div className="flex items-center space-x-2">
<RenderOption option={translatedSelected} display={display} hasColors={true} />
</div>
</>
);
}
@@ -0,0 +1,23 @@
import { clsx } from "clsx";
import { RowTagWithDetails } from "~/utils/db/entities/rowTags.db.server";
import { getBackgroundColor } from "~/utils/shared/ColorUtils";
export default function RowTagsCell({ items }: { items: RowTagWithDetails[] }) {
return (
<div>
{items?.map((rowTag) => {
return (
<div
key={rowTag.id}
className="border-border bg-secondary relative mx-0.5 inline-flex max-w-sm select-none items-center space-x-0.5 overflow-x-auto rounded-full border px-2 py-0.5"
>
<div className="absolute flex shrink-0 items-center justify-center">
<span className={clsx("h-1.5 w-1.5 rounded-full", getBackgroundColor(rowTag.tag.color))} aria-hidden="true" />
</div>
<div className="text-muted-foreground pl-2 text-xs font-medium">{rowTag.tag.value}</div>
</div>
);
})}
</div>
);
}