Release v0.1.6
This commit is contained in:
27
webui/src/components/admin/adminUtils.ts
Normal file
27
webui/src/components/admin/adminUtils.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { formatDateTime as formatPlatformDateTime } from "../../utils/datetime";
|
||||
|
||||
export function adminErrorMessage(error: unknown): string {
|
||||
if (!(error instanceof Error)) return "The administrative operation failed.";
|
||||
const message = error.message;
|
||||
const jsonStart = message.indexOf("{");
|
||||
if (jsonStart >= 0) {
|
||||
try {
|
||||
const parsed = JSON.parse(message.slice(jsonStart)) as { detail?: unknown };
|
||||
if (typeof parsed.detail === "string") return parsed.detail;
|
||||
if (Array.isArray(parsed.detail)) {
|
||||
return parsed.detail.map((item) => typeof item === "object" && item && "msg" in item ? String((item as { msg: unknown }).msg) : String(item)).join("; ");
|
||||
}
|
||||
} catch {
|
||||
// Fall through to the original message.
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
export function formatAdminDateTime(value?: string | null): string {
|
||||
return formatPlatformDateTime(value, { fallback: "Never" });
|
||||
}
|
||||
|
||||
export function joinLabels(values: Array<{ name: string }>): string {
|
||||
return values.length ? values.map((value) => value.name).join(", ") : "—";
|
||||
}
|
||||
Reference in New Issue
Block a user