@alepha/ui 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +12 -0
  2. package/components.json +20 -0
  3. package/package.json +85 -0
  4. package/src/components/action-error-toaster/action-error-toaster.tsx +70 -0
  5. package/src/components/admin/admin-audits.tsx +247 -0
  6. package/src/components/admin/admin-files.tsx +346 -0
  7. package/src/components/admin/admin-jobs-executions-panel.tsx +235 -0
  8. package/src/components/admin/admin-jobs-status-badge.tsx +33 -0
  9. package/src/components/admin/admin-jobs.tsx +294 -0
  10. package/src/components/admin/admin-keys.tsx +162 -0
  11. package/src/components/admin/admin-notifications.tsx +130 -0
  12. package/src/components/admin/admin-page.tsx +24 -0
  13. package/src/components/admin/admin-parameters.tsx +864 -0
  14. package/src/components/admin/admin-payments.tsx +93 -0
  15. package/src/components/admin/admin-sessions.tsx +174 -0
  16. package/src/components/admin/admin-user-detail-audits-tab.tsx +82 -0
  17. package/src/components/admin/admin-user-detail-identity-aside.tsx +218 -0
  18. package/src/components/admin/admin-user-detail-overview-tab.tsx +87 -0
  19. package/src/components/admin/admin-user-detail-password-dialog.tsx +85 -0
  20. package/src/components/admin/admin-user-detail-password-schema.ts +11 -0
  21. package/src/components/admin/admin-user-detail-profile-schema.ts +19 -0
  22. package/src/components/admin/admin-user-detail-provider-labels.ts +15 -0
  23. package/src/components/admin/admin-user-detail-security-tab.tsx +146 -0
  24. package/src/components/admin/admin-user-detail-sessions-tab.tsx +93 -0
  25. package/src/components/admin/admin-user-detail.tsx +606 -0
  26. package/src/components/admin/admin-users-roles-picker.tsx +126 -0
  27. package/src/components/admin/admin-users-status-filter.tsx +51 -0
  28. package/src/components/admin/admin-users.tsx +518 -0
  29. package/src/components/admin/diff-lines.spec.ts +58 -0
  30. package/src/components/admin/diff-lines.ts +58 -0
  31. package/src/components/admin/parameter-diff-dialog.tsx +119 -0
  32. package/src/components/admin/parameter-history-item.tsx +252 -0
  33. package/src/components/admin/parameter-json-dialog.tsx +93 -0
  34. package/src/components/admin/parameter-save-dialog.tsx +126 -0
  35. package/src/components/admin/use-confirmed-action.tsx +93 -0
  36. package/src/components/alepha-table/__tests__/use-table-selection.browser.spec.tsx +92 -0
  37. package/src/components/alepha-table/alepha-table.tsx +1158 -0
  38. package/src/components/alepha-table/use-table-selection.ts +95 -0
  39. package/src/components/app-shell/app-shell.tsx +568 -0
  40. package/src/components/auth/__tests__/auth-router.spec.ts +52 -0
  41. package/src/components/auth/auth-login.tsx +382 -0
  42. package/src/components/auth/auth-register.tsx +786 -0
  43. package/src/components/auth/auth-reset-password.tsx +349 -0
  44. package/src/components/auth/auth-router.tsx +126 -0
  45. package/src/components/auth/auth-verify-email.tsx +179 -0
  46. package/src/components/auto-form/auto-form.tsx +867 -0
  47. package/src/components/brand-icon/brand-icon.tsx +104 -0
  48. package/src/components/button-dark/button-dark.tsx +78 -0
  49. package/src/components/button-language/button-language.tsx +98 -0
  50. package/src/components/button-theme/button-theme.tsx +148 -0
  51. package/src/components/button-user/button-user.tsx +214 -0
  52. package/src/components/captcha/turnstile-widget.tsx +157 -0
  53. package/src/components/control/control.tsx +735 -0
  54. package/src/components/control-array/control-array.tsx +700 -0
  55. package/src/components/control-base/__tests__/form-field-a11y.browser.spec.tsx +93 -0
  56. package/src/components/control-base/field-i18n.ts +60 -0
  57. package/src/components/control-base/form-field.tsx +275 -0
  58. package/src/components/control-base/grid.tsx +59 -0
  59. package/src/components/control-base/icon-hint.tsx +64 -0
  60. package/src/components/control-date/control-date.tsx +190 -0
  61. package/src/components/control-number/control-number.tsx +136 -0
  62. package/src/components/control-object/control-object.tsx +200 -0
  63. package/src/components/control-select/control-select.tsx +774 -0
  64. package/src/components/control-upload/control-upload.tsx +475 -0
  65. package/src/components/file-image/file-image.tsx +52 -0
  66. package/src/components/language-toggle/language-toggle.tsx +66 -0
  67. package/src/components/markdown-view/markdown-view.css +114 -0
  68. package/src/components/markdown-view/markdown-view.tsx +92 -0
  69. package/src/components/nav-shell/nav-page.tsx +56 -0
  70. package/src/components/nav-shell/nav-shell.tsx +72 -0
  71. package/src/components/nav-shell/nav-tree-util.ts +62 -0
  72. package/src/components/nav-shell/spotlight.tsx +163 -0
  73. package/src/components/nav-shell/use-nav-breadcrumbs.ts +52 -0
  74. package/src/components/nav-shell/use-nav-entries.ts +101 -0
  75. package/src/components/nav-shell/use-nav-tree.ts +61 -0
  76. package/src/components/ui/accordion.tsx +77 -0
  77. package/src/components/ui/alert-dialog.tsx +186 -0
  78. package/src/components/ui/alert.tsx +75 -0
  79. package/src/components/ui/aspect-ratio.tsx +22 -0
  80. package/src/components/ui/avatar.tsx +106 -0
  81. package/src/components/ui/badge.tsx +51 -0
  82. package/src/components/ui/breadcrumb.tsx +121 -0
  83. package/src/components/ui/button-group.tsx +86 -0
  84. package/src/components/ui/button.tsx +83 -0
  85. package/src/components/ui/calendar.tsx +235 -0
  86. package/src/components/ui/card.tsx +102 -0
  87. package/src/components/ui/carousel.tsx +241 -0
  88. package/src/components/ui/chart.tsx +370 -0
  89. package/src/components/ui/checkbox.tsx +27 -0
  90. package/src/components/ui/collapsible.tsx +19 -0
  91. package/src/components/ui/combobox.tsx +298 -0
  92. package/src/components/ui/command.tsx +196 -0
  93. package/src/components/ui/context-menu.tsx +271 -0
  94. package/src/components/ui/dialog.tsx +153 -0
  95. package/src/components/ui/direction.tsx +4 -0
  96. package/src/components/ui/drawer.tsx +130 -0
  97. package/src/components/ui/dropdown-menu.tsx +269 -0
  98. package/src/components/ui/empty.tsx +100 -0
  99. package/src/components/ui/hover-card.tsx +50 -0
  100. package/src/components/ui/input-group.tsx +157 -0
  101. package/src/components/ui/input-otp.tsx +83 -0
  102. package/src/components/ui/input.tsx +19 -0
  103. package/src/components/ui/item.tsx +200 -0
  104. package/src/components/ui/kbd.tsx +26 -0
  105. package/src/components/ui/label.tsx +19 -0
  106. package/src/components/ui/menubar.tsx +283 -0
  107. package/src/components/ui/navigation-menu.tsx +170 -0
  108. package/src/components/ui/pagination.tsx +133 -0
  109. package/src/components/ui/popover.tsx +87 -0
  110. package/src/components/ui/progress.tsx +82 -0
  111. package/src/components/ui/radio-group.tsx +35 -0
  112. package/src/components/ui/resizable.tsx +49 -0
  113. package/src/components/ui/scroll-area.tsx +51 -0
  114. package/src/components/ui/segmented.tsx +232 -0
  115. package/src/components/ui/select.tsx +201 -0
  116. package/src/components/ui/separator.tsx +22 -0
  117. package/src/components/ui/sheet.tsx +133 -0
  118. package/src/components/ui/sidebar.tsx +723 -0
  119. package/src/components/ui/skeleton.tsx +13 -0
  120. package/src/components/ui/slider.tsx +51 -0
  121. package/src/components/ui/sonner.tsx +46 -0
  122. package/src/components/ui/spinner.tsx +15 -0
  123. package/src/components/ui/switch.tsx +29 -0
  124. package/src/components/ui/table.tsx +115 -0
  125. package/src/components/ui/tabs.tsx +79 -0
  126. package/src/components/ui/textarea.tsx +17 -0
  127. package/src/components/ui/toggle-group.tsx +86 -0
  128. package/src/components/ui/toggle.tsx +44 -0
  129. package/src/components/ui/tooltip.tsx +63 -0
  130. package/src/components/use-dialog/use-dialog.tsx +244 -0
  131. package/src/components/use-toast/use-toast.tsx +89 -0
  132. package/src/hooks/use-mobile.ts +21 -0
  133. package/src/lib/__tests__/i18n-fr.spec.ts +72 -0
  134. package/src/lib/i18n-fr.ts +500 -0
  135. package/src/lib/utils.ts +6 -0
  136. package/src/styles.css +129 -0
@@ -0,0 +1,58 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { diffLines } from "./diff-lines.ts";
3
+
4
+ describe("diffLines", () => {
5
+ it("marks every line as unchanged for identical input", () => {
6
+ const text = "a\nb\nc";
7
+ expect(diffLines(text, text)).toEqual([
8
+ { type: "same", text: "a" },
9
+ { type: "same", text: "b" },
10
+ { type: "same", text: "c" },
11
+ ]);
12
+ });
13
+
14
+ it("detects a changed line as a remove followed by an add", () => {
15
+ const result = diffLines("a\nb\nc", "a\nB\nc");
16
+ expect(result).toEqual([
17
+ { type: "same", text: "a" },
18
+ { type: "remove", text: "b" },
19
+ { type: "add", text: "B" },
20
+ { type: "same", text: "c" },
21
+ ]);
22
+ });
23
+
24
+ it("detects pure additions", () => {
25
+ const result = diffLines("a\nb", "a\nb\nc");
26
+ expect(result).toEqual([
27
+ { type: "same", text: "a" },
28
+ { type: "same", text: "b" },
29
+ { type: "add", text: "c" },
30
+ ]);
31
+ });
32
+
33
+ it("detects pure removals", () => {
34
+ const result = diffLines("a\nb\nc", "a\nc");
35
+ expect(result).toEqual([
36
+ { type: "same", text: "a" },
37
+ { type: "remove", text: "b" },
38
+ { type: "same", text: "c" },
39
+ ]);
40
+ });
41
+
42
+ it("handles an empty before (all added)", () => {
43
+ expect(diffLines("", "x")).toEqual([
44
+ { type: "remove", text: "" },
45
+ { type: "add", text: "x" },
46
+ ]);
47
+ });
48
+
49
+ it("preserves the LCS so unchanged lines are not duplicated", () => {
50
+ const before = JSON.stringify({ a: 1, b: 2 }, null, 2);
51
+ const after = JSON.stringify({ a: 1, b: 3 }, null, 2);
52
+ const result = diffLines(before, after);
53
+ const added = result.filter((l) => l.type === "add");
54
+ const removed = result.filter((l) => l.type === "remove");
55
+ expect(added).toEqual([{ type: "add", text: ' "b": 3' }]);
56
+ expect(removed).toEqual([{ type: "remove", text: ' "b": 2' }]);
57
+ });
58
+ });
@@ -0,0 +1,58 @@
1
+ export type DiffLineType = "add" | "remove" | "same";
2
+
3
+ export interface DiffLine {
4
+ type: DiffLineType;
5
+ text: string;
6
+ }
7
+
8
+ /**
9
+ * Compute a line-based diff between two strings using a longest-common-
10
+ * subsequence walk. Returns an ordered list of lines tagged as added,
11
+ * removed, or unchanged — enough to render a side-less unified diff for small
12
+ * JSON blobs without pulling in a diff dependency.
13
+ */
14
+ export const diffLines = (before: string, after: string): DiffLine[] => {
15
+ const a = before.split("\n");
16
+ const b = after.split("\n");
17
+ const m = a.length;
18
+ const n = b.length;
19
+
20
+ // lcs[i][j] = length of the LCS of a[i..] and b[j..].
21
+ const lcs: number[][] = Array.from({ length: m + 1 }, () =>
22
+ new Array<number>(n + 1).fill(0),
23
+ );
24
+ for (let i = m - 1; i >= 0; i--) {
25
+ for (let j = n - 1; j >= 0; j--) {
26
+ lcs[i][j] =
27
+ a[i] === b[j]
28
+ ? lcs[i + 1][j + 1] + 1
29
+ : Math.max(lcs[i + 1][j], lcs[i][j + 1]);
30
+ }
31
+ }
32
+
33
+ const out: DiffLine[] = [];
34
+ let i = 0;
35
+ let j = 0;
36
+ while (i < m && j < n) {
37
+ if (a[i] === b[j]) {
38
+ out.push({ type: "same", text: a[i] });
39
+ i++;
40
+ j++;
41
+ } else if (lcs[i + 1][j] >= lcs[i][j + 1]) {
42
+ out.push({ type: "remove", text: a[i] });
43
+ i++;
44
+ } else {
45
+ out.push({ type: "add", text: b[j] });
46
+ j++;
47
+ }
48
+ }
49
+ while (i < m) {
50
+ out.push({ type: "remove", text: a[i] });
51
+ i++;
52
+ }
53
+ while (j < n) {
54
+ out.push({ type: "add", text: b[j] });
55
+ j++;
56
+ }
57
+ return out;
58
+ };
@@ -0,0 +1,119 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { Button } from "@alepha/ui/components/ui/button";
6
+ import {
7
+ Dialog,
8
+ DialogClose,
9
+ DialogContent,
10
+ DialogDescription,
11
+ DialogFooter,
12
+ DialogHeader,
13
+ DialogTitle,
14
+ } from "@alepha/ui/components/ui/dialog";
15
+ import { cn } from "@alepha/ui/lib/utils";
16
+ import { useI18n } from "alepha/react/i18n";
17
+ import { type ReactNode, useMemo } from "react";
18
+ import { diffLines } from "./diff-lines.ts";
19
+
20
+ export interface ParameterDiffDialogProps {
21
+ open: boolean;
22
+ onOpenChange: (open: boolean) => void;
23
+ title: string;
24
+ /**
25
+ * Overrides the default "Changes compared to the previous version." line.
26
+ */
27
+ description?: ReactNode;
28
+ /**
29
+ * Content of the previous version (the "before" side of the diff).
30
+ */
31
+ previous: unknown;
32
+ /**
33
+ * Content of this version (the "after" side of the diff).
34
+ */
35
+ current: unknown;
36
+ /**
37
+ * When set, renders a footer with a Cancel button and a confirm button.
38
+ * Turns the read-only diff viewer into a confirmation dialog (e.g. factory
39
+ * reset, where the diff previews what the reset will change).
40
+ */
41
+ confirm?: {
42
+ label: string;
43
+ onConfirm: () => void | Promise<void>;
44
+ loading?: boolean;
45
+ destructive?: boolean;
46
+ };
47
+ }
48
+
49
+ /**
50
+ * Dialog rendering a line-based diff between a version and its predecessor.
51
+ * Added lines are green, removed lines red, unchanged lines muted.
52
+ */
53
+ export const ParameterDiffDialog = (props: ParameterDiffDialogProps) => {
54
+ const { tr } = useI18n();
55
+ const lines = useMemo(
56
+ () =>
57
+ diffLines(
58
+ JSON.stringify(props.previous ?? {}, null, 2),
59
+ JSON.stringify(props.current ?? {}, null, 2),
60
+ ),
61
+ [props.previous, props.current],
62
+ );
63
+
64
+ return (
65
+ <Dialog open={props.open} onOpenChange={props.onOpenChange}>
66
+ <DialogContent className="max-w-2xl">
67
+ <DialogHeader>
68
+ <DialogTitle className="truncate pr-6">{props.title}</DialogTitle>
69
+ <DialogDescription>
70
+ {props.description ??
71
+ tr("admin.parameters.diffDialogDescription", {
72
+ default: "Changes compared to the previous version.",
73
+ })}
74
+ </DialogDescription>
75
+ </DialogHeader>
76
+ <pre className="bg-muted max-h-[60vh] overflow-auto rounded-md p-3 font-mono text-xs leading-relaxed">
77
+ {lines.map((line, index) => (
78
+ <div
79
+ // biome-ignore lint/suspicious/noArrayIndexKey: diff lines are positional
80
+ key={index}
81
+ className={cn(
82
+ "flex gap-2 whitespace-pre-wrap",
83
+ line.type === "add" &&
84
+ "bg-emerald-500/10 text-emerald-700 dark:text-emerald-400",
85
+ line.type === "remove" &&
86
+ "bg-red-500/10 text-red-700 dark:text-red-400",
87
+ line.type === "same" && "text-muted-foreground",
88
+ )}
89
+ >
90
+ <span aria-hidden className="select-none opacity-60">
91
+ {line.type === "add" ? "+" : line.type === "remove" ? "-" : " "}
92
+ </span>
93
+ <span className="flex-1">{line.text}</span>
94
+ </div>
95
+ ))}
96
+ </pre>
97
+ {props.confirm && (
98
+ <DialogFooter>
99
+ <DialogClose
100
+ render={
101
+ <Button type="button" variant="outline">
102
+ {tr("admin.parameters.diffCancel", { default: "Cancel" })}
103
+ </Button>
104
+ }
105
+ />
106
+ <Button
107
+ type="button"
108
+ variant={props.confirm.destructive ? "destructive" : "default"}
109
+ loading={props.confirm.loading}
110
+ onClick={() => props.confirm?.onConfirm()}
111
+ >
112
+ {props.confirm.label}
113
+ </Button>
114
+ </DialogFooter>
115
+ )}
116
+ </DialogContent>
117
+ </Dialog>
118
+ );
119
+ };
@@ -0,0 +1,252 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { Badge } from "@alepha/ui/components/ui/badge";
6
+ import { Button } from "@alepha/ui/components/ui/button";
7
+ import {
8
+ DropdownMenu,
9
+ DropdownMenuContent,
10
+ DropdownMenuItem,
11
+ DropdownMenuSeparator,
12
+ DropdownMenuTrigger,
13
+ } from "@alepha/ui/components/ui/dropdown-menu";
14
+ import { cn } from "@alepha/ui/lib/utils";
15
+ import type { AdminParameterController } from "alepha/api/parameters";
16
+ import { useI18n } from "alepha/react/i18n";
17
+ import { useRouter } from "alepha/react/router";
18
+ import {
19
+ Archive,
20
+ ChevronRight,
21
+ CircleCheck,
22
+ Clock,
23
+ Eye,
24
+ GitCompare,
25
+ MoreVertical,
26
+ RotateCcw,
27
+ Tag,
28
+ } from "lucide-react";
29
+ import { useState } from "react";
30
+ import { ParameterDiffDialog } from "./parameter-diff-dialog.tsx";
31
+ import { ParameterJsonDialog } from "./parameter-json-dialog.tsx";
32
+
33
+ type HistoryVersion = Awaited<
34
+ ReturnType<AdminParameterController["getHistory"]>
35
+ >["versions"][number];
36
+
37
+ export interface ParameterHistoryItemProps {
38
+ version: HistoryVersion;
39
+ onRollback: (version: number) => void | Promise<void>;
40
+ }
41
+
42
+ /**
43
+ * One parameter version, rendered as a flush, square row in the history stack.
44
+ *
45
+ * The whole header row toggles the body (version / created-at / created-by /
46
+ * tags). The `…` menu (View JSON / Diff with previous / Rollback) stops click
47
+ * propagation so using it never toggles the row.
48
+ */
49
+ export const ParameterHistoryItem = (props: ParameterHistoryItemProps) => {
50
+ const { l, tr } = useI18n();
51
+ const router = useRouter();
52
+ const v = props.version;
53
+ const [open, setOpen] = useState(false);
54
+ const [jsonOpen, setJsonOpen] = useState(false);
55
+ const [diffOpen, setDiffOpen] = useState(false);
56
+
57
+ const hasPrevious = v.previousContent != null;
58
+ const isCurrent = v.status === "current";
59
+ const toggle = () => setOpen((o) => !o);
60
+
61
+ return (
62
+ <div className="border-b">
63
+ <div
64
+ role="button"
65
+ tabIndex={0}
66
+ onClick={toggle}
67
+ onKeyDown={(e) => {
68
+ if (e.key === "Enter" || e.key === " ") {
69
+ e.preventDefault();
70
+ toggle();
71
+ }
72
+ }}
73
+ className="hover:bg-accent/50 flex cursor-pointer select-none items-center gap-2 px-3 py-2.5 transition-colors"
74
+ >
75
+ <span className="text-muted-foreground flex size-4 shrink-0 items-center justify-center">
76
+ {statusIcon(v.status)}
77
+ </span>
78
+ <div className="flex min-w-0 flex-1 flex-col gap-0.5 ml-1">
79
+ <span className="text-sm font-semibold capitalize leading-tight">
80
+ {v.status}
81
+ </span>
82
+ <span className="text-muted-foreground flex items-center gap-1 text-xs leading-tight">
83
+ <Clock className="size-3" />
84
+ {String(l(v.activationDate, { date: "fromNow" }))}
85
+ </span>
86
+ </div>
87
+
88
+ {/* Actions: intercept clicks so the menu never toggles the row. */}
89
+ <div
90
+ className="shrink-0"
91
+ onClick={(e) => e.stopPropagation()}
92
+ onKeyDown={(e) => e.stopPropagation()}
93
+ >
94
+ <DropdownMenu>
95
+ <DropdownMenuTrigger
96
+ render={
97
+ <Button
98
+ variant="ghost"
99
+ size="icon"
100
+ className="size-6"
101
+ aria-label={tr("admin.parameters.versionActions", {
102
+ default: "Version actions",
103
+ })}
104
+ />
105
+ }
106
+ >
107
+ <MoreVertical className="size-4" />
108
+ </DropdownMenuTrigger>
109
+ <DropdownMenuContent align="end">
110
+ <DropdownMenuItem onClick={() => setJsonOpen(true)}>
111
+ <Eye className="mr-2 size-4" />
112
+ {tr("admin.parameters.view", { default: "View" })}
113
+ </DropdownMenuItem>
114
+ {hasPrevious && (
115
+ <DropdownMenuItem onClick={() => setDiffOpen(true)}>
116
+ <GitCompare className="mr-2 size-4" />
117
+ {tr("admin.parameters.diffWithPrevious", {
118
+ default: "Diff with previous",
119
+ })}
120
+ </DropdownMenuItem>
121
+ )}
122
+ {!isCurrent && (
123
+ <>
124
+ <DropdownMenuSeparator />
125
+ <DropdownMenuItem onClick={() => props.onRollback(v.version)}>
126
+ <RotateCcw className="mr-2 size-4" />
127
+ {tr("admin.parameters.rollback", { default: "Rollback" })}
128
+ </DropdownMenuItem>
129
+ </>
130
+ )}
131
+ </DropdownMenuContent>
132
+ </DropdownMenu>
133
+ </div>
134
+
135
+ <span className="text-muted-foreground flex size-4 shrink-0 items-center justify-center">
136
+ <ChevronRight
137
+ className={cn(
138
+ "size-4 transition-transform duration-200",
139
+ open && "rotate-90",
140
+ )}
141
+ />
142
+ </span>
143
+ </div>
144
+
145
+ {/* Animated collapse: grid-rows 0fr→1fr smoothly interpolates height
146
+ without measuring. The body stays mounted so the transition runs. */}
147
+ <div
148
+ className={cn(
149
+ "grid transition-[grid-template-rows] duration-200 ease-out",
150
+ open ? "grid-rows-[1fr]" : "grid-rows-[0fr]",
151
+ )}
152
+ >
153
+ <div className="overflow-hidden">
154
+ <div className="border-t px-3 py-2.5">
155
+ <dl className="grid grid-cols-[auto_1fr] gap-x-3 gap-y-1.5 text-xs">
156
+ <dt className="text-muted-foreground">
157
+ {tr("admin.parameters.fieldVersion", { default: "Version" })}
158
+ </dt>
159
+ <dd className="font-mono font-medium">v{v.version}</dd>
160
+
161
+ <dt className="text-muted-foreground">
162
+ {tr("admin.parameters.fieldCreatedAt", {
163
+ default: "Created at",
164
+ })}
165
+ </dt>
166
+ <dd>{String(l(v.createdAt, { date: "lll" }))}</dd>
167
+
168
+ <dt className="text-muted-foreground">
169
+ {tr("admin.parameters.fieldCreatedBy", {
170
+ default: "Created by",
171
+ })}
172
+ </dt>
173
+ <dd className="truncate">
174
+ {v.creatorId ? (
175
+ <button
176
+ type="button"
177
+ className="text-primary truncate hover:underline"
178
+ onClick={() =>
179
+ router.push(`/admin/users/${v.creatorId}` as never)
180
+ }
181
+ >
182
+ {v.creator?.username ??
183
+ v.creator?.email ??
184
+ v.creatorName ??
185
+ v.creatorId}
186
+ </button>
187
+ ) : (
188
+ (v.creatorName ?? "—")
189
+ )}
190
+ </dd>
191
+
192
+ {v.changeDescription && (
193
+ <>
194
+ <dt className="text-muted-foreground">
195
+ {tr("admin.parameters.fieldNote", { default: "Note" })}
196
+ </dt>
197
+ <dd className="leading-snug">{v.changeDescription}</dd>
198
+ </>
199
+ )}
200
+
201
+ {v.tags && v.tags.length > 0 && (
202
+ <>
203
+ <dt className="text-muted-foreground flex items-center gap-1">
204
+ <Tag className="size-3" />
205
+ {tr("admin.parameters.fieldTags", { default: "Tags" })}
206
+ </dt>
207
+ <dd className="flex flex-wrap gap-1">
208
+ {v.tags.map((tag) => (
209
+ <Badge
210
+ key={tag}
211
+ variant="outline"
212
+ className="text-[10px]"
213
+ >
214
+ {tag}
215
+ </Badge>
216
+ ))}
217
+ </dd>
218
+ </>
219
+ )}
220
+ </dl>
221
+ </div>
222
+ </div>
223
+ </div>
224
+
225
+ <ParameterJsonDialog
226
+ open={jsonOpen}
227
+ onOpenChange={setJsonOpen}
228
+ title={`v${v.version} — ${v.name}`}
229
+ content={v.content}
230
+ />
231
+ {hasPrevious && (
232
+ <ParameterDiffDialog
233
+ open={diffOpen}
234
+ onOpenChange={setDiffOpen}
235
+ title={`v${v.version} — ${v.name}`}
236
+ previous={v.previousContent}
237
+ current={v.content}
238
+ />
239
+ )}
240
+ </div>
241
+ );
242
+ };
243
+
244
+ const statusIcon = (status: HistoryVersion["status"]) => {
245
+ if (status === "current") {
246
+ return (
247
+ <CircleCheck className="size-4 text-emerald-600 dark:text-emerald-400" />
248
+ );
249
+ }
250
+ if (status === "expired") return <Archive className="size-4" />;
251
+ return <Clock className="size-4" />;
252
+ };
@@ -0,0 +1,93 @@
1
+ import * as React from "react";
2
+
3
+ void React;
4
+
5
+ import { Button } from "@alepha/ui/components/ui/button";
6
+ import {
7
+ Dialog,
8
+ DialogContent,
9
+ DialogDescription,
10
+ DialogHeader,
11
+ DialogTitle,
12
+ } from "@alepha/ui/components/ui/dialog";
13
+ import { useToast } from "@alepha/ui/components/use-toast/use-toast";
14
+ import { useI18n } from "alepha/react/i18n";
15
+ import { Check, Copy } from "lucide-react";
16
+ import { useEffect, useRef, useState } from "react";
17
+
18
+ export interface ParameterJsonDialogProps {
19
+ open: boolean;
20
+ onOpenChange: (open: boolean) => void;
21
+ title: string;
22
+ content: unknown;
23
+ }
24
+
25
+ /**
26
+ * Read-only dialog that pretty-prints a parameter version's content as JSON,
27
+ * with a copy-to-clipboard button.
28
+ */
29
+ export const ParameterJsonDialog = (props: ParameterJsonDialogProps) => {
30
+ const { tr } = useI18n();
31
+ const toast = useToast();
32
+ const [copied, setCopied] = useState(false);
33
+ const copyTimer = useRef<ReturnType<typeof setTimeout> | undefined>(
34
+ undefined,
35
+ );
36
+ const json = JSON.stringify(props.content ?? {}, null, 2);
37
+
38
+ // Clear the "copied" reset timer on unmount so it can't fire setState on an
39
+ // unmounted component.
40
+ useEffect(
41
+ () => () => {
42
+ if (copyTimer.current) clearTimeout(copyTimer.current);
43
+ },
44
+ [],
45
+ );
46
+
47
+ const onCopy = async () => {
48
+ try {
49
+ await navigator.clipboard.writeText(json);
50
+ setCopied(true);
51
+ if (copyTimer.current) clearTimeout(copyTimer.current);
52
+ copyTimer.current = setTimeout(() => setCopied(false), 1_500);
53
+ } catch {
54
+ toast.error(
55
+ tr("admin.parameters.copyFailed", { default: "Could not copy" }),
56
+ );
57
+ }
58
+ };
59
+
60
+ return (
61
+ <Dialog open={props.open} onOpenChange={props.onOpenChange}>
62
+ <DialogContent className="max-w-2xl">
63
+ <DialogHeader>
64
+ <DialogTitle className="flex items-center justify-between gap-2 pr-6">
65
+ <span className="truncate">{props.title}</span>
66
+ <Button
67
+ type="button"
68
+ variant="ghost"
69
+ size="sm"
70
+ className="h-7 px-2"
71
+ onClick={onCopy}
72
+ >
73
+ {copied ? (
74
+ <Check className="size-3.5" />
75
+ ) : (
76
+ <Copy className="size-3.5" />
77
+ )}
78
+ {tr("admin.parameters.copy", { default: "Copy" })}
79
+ </Button>
80
+ </DialogTitle>
81
+ <DialogDescription className="sr-only">
82
+ {tr("admin.parameters.jsonDialogDescription", {
83
+ default: "Raw JSON content of this parameter version.",
84
+ })}
85
+ </DialogDescription>
86
+ </DialogHeader>
87
+ <pre className="bg-muted max-h-[60vh] overflow-auto rounded-md p-3 font-mono text-xs leading-relaxed">
88
+ {json}
89
+ </pre>
90
+ </DialogContent>
91
+ </Dialog>
92
+ );
93
+ };