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,39 @@
|
||||
import { Colors } from "~/application/enums/shared/Colors";
|
||||
import MonacoEditor from "~/components/editors/MonacoEditor";
|
||||
import SimpleBadge from "~/components/ui/badges/SimpleBadge";
|
||||
import InputText from "~/components/ui/input/InputText";
|
||||
import { useLocaleFormatters } from "~/locale/format";
|
||||
import { EventWithDetails } from "../db/events.db.server";
|
||||
import { redactDiagnosticJsonString } from "~/utils/redaction";
|
||||
import EventUtils from "../utils/EventUtils";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
interface Props {
|
||||
item: EventWithDetails;
|
||||
}
|
||||
export default function EventDetails({ item }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const formatters = useLocaleFormatters();
|
||||
const formattedData = () => {
|
||||
return redactDiagnosticJsonString(item.data);
|
||||
};
|
||||
return (
|
||||
<div className="space-y-3 text-sm">
|
||||
<div className="border-border flex justify-between border-b pb-3">
|
||||
<h3>
|
||||
<SimpleBadge className="text-lg" title={EventUtils.parseName(item.name, t)} color={Colors.VIOLET} />
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-3 gap-4">
|
||||
<InputText name="createdAt" title={t("shared.createdAt")} defaultValue={formatters.dateTime(item.createdAt)} readOnly={true} />
|
||||
<InputText name="account" title={t("models.tenant.object")} defaultValue={item.tenant?.name ?? t("shared.notSet")} readOnly={true} />
|
||||
<InputText name="user" title={t("models.user.object")} defaultValue={item.user?.email || t("shared.notSet")} readOnly={true} />
|
||||
</div>
|
||||
|
||||
<div className="h-96 overflow-auto p-2">
|
||||
<MonacoEditor value={formattedData()} onChange={() => {}} theme="vs-dark" language="json" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
import { Link, useParams } from "react-router";
|
||||
import { Fragment, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { PaginationDto } from "~/application/dtos/data/PaginationDto";
|
||||
import { Colors } from "~/application/enums/shared/Colors";
|
||||
import SimpleBadge from "~/components/ui/badges/SimpleBadge";
|
||||
import ExternalLinkEmptyIcon from "~/components/ui/icons/ExternalLinkEmptyIcon";
|
||||
import OpenModal from "~/components/ui/modals/OpenModal";
|
||||
import TableSimple from "~/components/ui/tables/TableSimple";
|
||||
import { EventWithAttempts } from "../db/events.db.server";
|
||||
import MonacoEditor from "~/components/editors/MonacoEditor";
|
||||
import { Badge } from "~/components/ui/badge";
|
||||
import { useLocaleFormatters } from "~/locale/format";
|
||||
import { appPath } from "~/utils/app/CanonicalUrlUtils";
|
||||
import { redactDiagnosticJsonString } from "~/utils/redaction";
|
||||
import EventUtils from "../utils/EventUtils";
|
||||
|
||||
interface Props {
|
||||
items: EventWithAttempts[];
|
||||
pagination: PaginationDto;
|
||||
}
|
||||
export default function EventsTable({ items, pagination }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const formatters = useLocaleFormatters();
|
||||
const params = useParams();
|
||||
const [selectedData, setSelectedData] = useState<EventWithAttempts | undefined>(undefined);
|
||||
const formattedData = (item: EventWithAttempts) => {
|
||||
return redactDiagnosticJsonString(item.data);
|
||||
};
|
||||
return (
|
||||
<>
|
||||
<TableSimple
|
||||
items={items}
|
||||
actions={[
|
||||
{
|
||||
title: t("shared.details"),
|
||||
onClickRoute: (_, i) => i.id,
|
||||
},
|
||||
]}
|
||||
pagination={pagination}
|
||||
headers={[
|
||||
{
|
||||
name: "event",
|
||||
title: t("models.event.object"),
|
||||
value: (i) => EventUtils.parseName(i.name, t),
|
||||
formattedValue: (i) => (
|
||||
<div>
|
||||
<Badge variant="secondary">{EventUtils.parseName(i.name, t)}</Badge>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "data",
|
||||
title: t("models.event.data"),
|
||||
value: (i) => (
|
||||
<button type="button" onClick={() => setSelectedData(i)} className="hover:text-theme-500 truncate underline">
|
||||
{EventUtils.parseDescription(i, t, formatters)}
|
||||
</button>
|
||||
),
|
||||
className: "w-full",
|
||||
},
|
||||
// {
|
||||
// name: "attempts",
|
||||
// title: t("models.event.attempts"),
|
||||
// value: (i) => i.attempts.length,
|
||||
// formattedValue: (i) => (
|
||||
// <div className="flex space-x-1">
|
||||
// {i.attempts.map((f, idx) => (
|
||||
// <Link to={i.id + "?attempt=" + f.id} key={idx}>
|
||||
// <StatusBadge startedAt={f.startedAt} finishedAt={f.finishedAt} endpoint={f.endpoint} status={f.status} />
|
||||
// </Link>
|
||||
// ))}
|
||||
// </div>
|
||||
// ),
|
||||
// },
|
||||
{
|
||||
name: "tenant",
|
||||
title: t("models.tenant.object"),
|
||||
value: (i) => (
|
||||
<div className="text-xs">
|
||||
{!i.tenant ? (
|
||||
<span className="text-muted-foreground italic">{t("shared.notSet")}</span>
|
||||
) : (
|
||||
<Fragment>
|
||||
<div className="font-medium">{i.tenant?.name}</div>
|
||||
<Link
|
||||
to={appPath({ tenantSlug: i.tenant.slug, mode: "host-aware" })}
|
||||
target="_blank"
|
||||
className="text-muted-foreground focus:bg-secondary/90 hover:border-border rounded-md border-b border-dashed text-xs hover:border-dashed"
|
||||
>
|
||||
<span>/{i.tenant.slug}</span>
|
||||
</Link>
|
||||
</Fragment>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
hidden: !!params.tenant,
|
||||
},
|
||||
{
|
||||
name: "createdAt",
|
||||
title: t("shared.createdAt"),
|
||||
value: (i) => (
|
||||
<div className="text-xs">
|
||||
<div>{i.user?.email ?? <span className="text-muted-foreground italic">{t("shared.notSet")}</span>}</div>
|
||||
<div className="text-muted-foreground text-xs">{formatters.relativeDate(i.createdAt)}</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
{selectedData && (
|
||||
<OpenModal className="max-w-md" onClose={() => setSelectedData(undefined)}>
|
||||
<div className="space-y-3 text-sm">
|
||||
<div className="border-border flex justify-between border-b pb-3">
|
||||
<h3>
|
||||
<SimpleBadge className="text-lg" title={EventUtils.parseName(selectedData.name, t)} color={Colors.VIOLET} />
|
||||
</h3>
|
||||
<div className="flex items-center space-x-2">
|
||||
<div className="text-muted-foreground text-sm">{formatters.dateTime(selectedData.createdAt)}</div>
|
||||
<Link to={selectedData.id} className="text-muted-foreground hover:text-foreground/80">
|
||||
<ExternalLinkEmptyIcon className="h-5 w-5" />
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<p className="text-xs font-bold">{t("models.event.data")}</p>
|
||||
<div className="h-96 overflow-auto p-2">
|
||||
<MonacoEditor value={formattedData(selectedData)} onChange={() => {}} theme="vs-dark" language="json" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</OpenModal>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
import { Colors } from "~/application/enums/shared/Colors";
|
||||
import SimpleBadge from "~/components/ui/badges/SimpleBadge";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
interface Props {
|
||||
startedAt: Date | null;
|
||||
finishedAt: Date | null;
|
||||
endpoint: string;
|
||||
status: number | null;
|
||||
}
|
||||
export default function StatusBadge({ startedAt, finishedAt, endpoint, status }: Props) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
function getState() {
|
||||
if (status === null && startedAt === null) {
|
||||
return t("events.webhookAttempts.status.notCaught");
|
||||
} else if (status === null && startedAt !== null && finishedAt === null) {
|
||||
return t("events.webhookAttempts.status.running");
|
||||
} else if (status !== null && finishedAt !== null) {
|
||||
if (status >= 200 && status < 300) {
|
||||
return `[${status}] ${t("events.webhookAttempts.status.success")}`;
|
||||
} else if (status >= 300 && status < 400) {
|
||||
return `[${status}] ${t("events.webhookAttempts.status.redirect")}`;
|
||||
} else if (status >= 400 && status < 500) {
|
||||
return `[${status}] ${t("events.webhookAttempts.status.clientError")}`;
|
||||
} else if (status >= 500) {
|
||||
return `[${status}] ${t("events.webhookAttempts.status.serverError")}`;
|
||||
} else {
|
||||
return `[${status}] ${t("events.webhookAttempts.status.unknown")}`;
|
||||
}
|
||||
} else {
|
||||
return t("events.webhookAttempts.status.unknown");
|
||||
}
|
||||
}
|
||||
function getColor() {
|
||||
if (status === null) {
|
||||
return Colors.YELLOW;
|
||||
} else if (status >= 200 && status < 300) {
|
||||
return Colors.GREEN;
|
||||
} else if (status >= 300 && status < 400) {
|
||||
return Colors.ORANGE;
|
||||
} else if (status >= 400 && status < 500) {
|
||||
return Colors.RED;
|
||||
} else {
|
||||
return Colors.UNDEFINED;
|
||||
}
|
||||
}
|
||||
return (
|
||||
<div title={endpoint}>
|
||||
<SimpleBadge title={getState()} color={getColor()} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { ApplicationEvents, getApplicationEventNameKey } from "~/modules/events/types/ApplicationEvent";
|
||||
|
||||
const repoRoot = process.cwd();
|
||||
const textCache = new Map<string, string>();
|
||||
const jsonCache = new Map<string, unknown>();
|
||||
|
||||
type LocaleTranslations = {
|
||||
admin: {
|
||||
events: {
|
||||
filters: {
|
||||
eventOption: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
events: {
|
||||
descriptions: {
|
||||
subscription: Record<string, string>;
|
||||
};
|
||||
names: Record<string, string>;
|
||||
};
|
||||
models: {
|
||||
log: {
|
||||
actions: Record<string, string>;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
function resolveRepoPath(file: string) {
|
||||
return path.resolve(repoRoot, file);
|
||||
}
|
||||
|
||||
function readRepoFile(file: string) {
|
||||
const resolved = resolveRepoPath(file);
|
||||
const cached = textCache.get(resolved);
|
||||
if (cached !== undefined) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
const source = fs.readFileSync(resolved, "utf8");
|
||||
textCache.set(resolved, source);
|
||||
return source;
|
||||
}
|
||||
|
||||
function readJsonFile<T>(file: string) {
|
||||
const resolved = resolveRepoPath(file);
|
||||
if (!jsonCache.has(resolved)) {
|
||||
jsonCache.set(resolved, JSON.parse(readRepoFile(file)) as unknown);
|
||||
}
|
||||
|
||||
return jsonCache.get(resolved) as T;
|
||||
}
|
||||
|
||||
function readTranslations(locale: "en" | "de") {
|
||||
return readJsonFile<LocaleTranslations>(`apps/web/public/locales/${locale}/translations.json`);
|
||||
}
|
||||
|
||||
function getNestedValue(source: unknown, key: string) {
|
||||
return key.split(".").reduce<unknown>((value, segment) => {
|
||||
if (!value || typeof value !== "object") {
|
||||
return undefined;
|
||||
}
|
||||
return (value as Record<string, unknown>)[segment];
|
||||
}, source);
|
||||
}
|
||||
|
||||
describe("events i18n", () => {
|
||||
it("keeps event detail chrome behind semantic keys", () => {
|
||||
const sources = [
|
||||
"apps/web/app/modules/events/components/EventDetails.tsx",
|
||||
"apps/web/app/modules/events/components/EventsTable.tsx",
|
||||
"apps/web/app/modules/events/components/StatusBadge.tsx",
|
||||
"apps/web/app/components/app/events/LogsTable.tsx",
|
||||
"apps/web/app/routes/admin/events.tsx",
|
||||
"apps/web/app/routes/app.$tenant/settings/logs/events.$id.tsx",
|
||||
"apps/web/app/routes/app.$tenant/settings/logs/events.tsx",
|
||||
]
|
||||
.map((file) => readRepoFile(file))
|
||||
.join("\n");
|
||||
|
||||
expect(sources).toContain("shared.createdAt");
|
||||
expect(sources).toContain("models.tenant.object");
|
||||
expect(sources).toContain("models.user.object");
|
||||
expect(sources).toContain("models.log.action");
|
||||
expect(sources).toContain("EventUtils.parseName");
|
||||
expect(sources).toContain("admin.events.filters.eventOption");
|
||||
expect(sources).toContain("settings.logs.events.filters.eventOption");
|
||||
expect(sources).toContain("getLogActionI18nKey");
|
||||
expect(sources).toContain("events.webhookAttempts.status.notCaught");
|
||||
expect(sources).toContain("useLocaleFormatters");
|
||||
expect(sources).toContain("createLocaleFormatters");
|
||||
expect(sources).toContain("useTranslation");
|
||||
expect(sources).toContain('t("shared.notSet")');
|
||||
expect(sources).not.toContain("t as i18nT");
|
||||
expect(sources).not.toContain("DateUtils.");
|
||||
expect(sources).not.toContain('from "~/utils/shared/DateUtils"');
|
||||
expect(sources).not.toContain("ui.autogenerated");
|
||||
expect(sources).not.toContain("Webhook Attempt #");
|
||||
expect(sources).not.toContain("Webhook not catched");
|
||||
expect(sources).not.toContain("title={item.name}");
|
||||
expect(sources).not.toContain("title: data.item.name");
|
||||
expect(sources).not.toContain("${item.value} - ${t(");
|
||||
expect(sources).not.toContain("{i.name}</Badge>");
|
||||
expect(sources).not.toContain('italic">?</span>');
|
||||
});
|
||||
|
||||
it("localizes event preference values before interpolation", () => {
|
||||
const source = readRepoFile("apps/web/app/modules/events/utils/EventUtils.ts");
|
||||
|
||||
expect(source).toContain("translateEventValue");
|
||||
expect(source).toContain("shared.locales.${oldLocale}");
|
||||
expect(source).toContain("shared.locales.${newLocale}");
|
||||
expect(source).toContain("shared.${oldTheme}");
|
||||
expect(source).toContain("shared.${newTheme}");
|
||||
expect(source).not.toContain("oldLocale,\n newLocale,");
|
||||
expect(source).not.toContain("oldTheme,\n newTheme,");
|
||||
});
|
||||
|
||||
it("keeps server-side event diagnostics behind semantic keys", () => {
|
||||
const source = readRepoFile("apps/web/app/modules/events/services/.server/EventsService.ts");
|
||||
|
||||
expect(source).toContain("events.webhooks.errors.callEndpointFailed");
|
||||
expect(source).toContain("events.actions.viewAccount");
|
||||
expect(source).not.toContain("ui.autogenerated");
|
||||
});
|
||||
|
||||
it("keeps localized audit log actions available in English and German", () => {
|
||||
const en = readTranslations("en");
|
||||
const de = readTranslations("de");
|
||||
const actionKeys = [
|
||||
"apiKeyCreated",
|
||||
"apiKeyUpdated",
|
||||
"apiKeyRotated",
|
||||
"apiKeyDeleted",
|
||||
"updateTenantDetails",
|
||||
"updatedAiOverageConfiguration",
|
||||
"workspaceRoleCreated",
|
||||
"workspaceRoleUpdated",
|
||||
"workspaceRoleDeleted",
|
||||
];
|
||||
|
||||
for (const key of actionKeys) {
|
||||
expect(en.models.log.actions[key]).toEqual(expect.any(String));
|
||||
expect(de.models.log.actions[key]).toEqual(expect.any(String));
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps admin event filter option locale keys in parity", () => {
|
||||
const en = readTranslations("en");
|
||||
const de = readTranslations("de");
|
||||
|
||||
expect(en.admin.events.filters.eventOption).toBe("{{eventValue}} - {{eventLabel}}");
|
||||
expect(de.admin.events.filters.eventOption).toBe("{{eventValue}} - {{eventLabel}}");
|
||||
});
|
||||
|
||||
it("keeps German subscription event names aligned with plan and subscription terminology", () => {
|
||||
const de = readTranslations("de");
|
||||
|
||||
expect(de.events.descriptions.subscription.subscribed).toBe("{{tenant}} hat den Tarif {{product}} abonniert");
|
||||
expect(de.events.descriptions.subscription.subscribedByUser).toBe("{{email}} hat für {{tenant}} den Tarif {{product}} abonniert");
|
||||
expect(de.events.descriptions.subscription.upgraded).toBe("Tarif-Upgrade: {{tenant}} ({{product}})");
|
||||
expect(de.events.descriptions.subscription.downgraded).toBe("Tarif-Downgrade: {{tenant}} ({{product}})");
|
||||
expect(de.events.descriptions.subscription.cancelled).toBe("Abonnement gekündigt: {{tenant}} ({{product}})");
|
||||
expect(de.events.names.subscription_subscribed).toBe("Tarif abonniert");
|
||||
expect(de.events.names.subscription_upgraded).toBe("Tarif-Upgrade");
|
||||
expect(de.events.names.subscription_downgraded).toBe("Tarif-Downgrade");
|
||||
});
|
||||
|
||||
it("keeps German row event names aligned with Datensatz terminology", () => {
|
||||
const de = readTranslations("de");
|
||||
const rowEventNames = Object.entries(de.events.names).filter(([key]) => key.startsWith("row_"));
|
||||
|
||||
expect(rowEventNames.length).toBeGreaterThan(0);
|
||||
for (const [, value] of rowEventNames) {
|
||||
expect(value).toEqual(expect.any(String));
|
||||
expect(value).not.toMatch(/Zeile|Zeilen/u);
|
||||
}
|
||||
expect(de.events.names.row_updated).toBe("Datensatz aktualisiert");
|
||||
expect(de.events.names.row_comments_reacted).toBe("Reaktion auf Datensatzkommentar");
|
||||
});
|
||||
|
||||
it("keeps every application event name backed by explicit en/de locale keys", () => {
|
||||
const locales = ["en", "de"] as const;
|
||||
|
||||
for (const event of ApplicationEvents) {
|
||||
expect(event, event.value).not.toHaveProperty("name");
|
||||
|
||||
for (const locale of locales) {
|
||||
const translations = readTranslations(locale);
|
||||
const key = getApplicationEventNameKey(event.value).replace("events.names.", "");
|
||||
|
||||
expect(translations.events.names, `${locale} ${getApplicationEventNameKey(event.value)}`).toHaveProperty(key);
|
||||
expect(translations.events.names[key], `${locale} ${getApplicationEventNameKey(event.value)}`).toEqual(expect.any(String));
|
||||
expect(translations.events.names[key].trim(), `${locale} ${getApplicationEventNameKey(event.value)}`).not.toBe("");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps every EventUtils description key backed by explicit en/de locale text", () => {
|
||||
const source = readRepoFile("apps/web/app/modules/events/utils/EventUtils.ts");
|
||||
const descriptionKeys = Array.from(source.matchAll(/translateEventDescription\(\s*t,\s*"([^"]+)"/g), ([, key]) => key)
|
||||
.filter((key) => key.startsWith("events."))
|
||||
.sort();
|
||||
|
||||
expect(descriptionKeys.length).toBeGreaterThan(0);
|
||||
|
||||
for (const locale of ["en", "de"] as const) {
|
||||
const translations = readTranslations(locale);
|
||||
|
||||
for (const key of descriptionKeys) {
|
||||
expect(getNestedValue(translations, key), `${locale} ${key}`).toEqual(expect.any(String));
|
||||
expect((getNestedValue(translations, key) as string).trim(), `${locale} ${key}`).not.toBe("");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user