@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.
- package/README.md +12 -0
- package/components.json +20 -0
- package/package.json +85 -0
- package/src/components/action-error-toaster/action-error-toaster.tsx +70 -0
- package/src/components/admin/admin-audits.tsx +247 -0
- package/src/components/admin/admin-files.tsx +346 -0
- package/src/components/admin/admin-jobs-executions-panel.tsx +235 -0
- package/src/components/admin/admin-jobs-status-badge.tsx +33 -0
- package/src/components/admin/admin-jobs.tsx +294 -0
- package/src/components/admin/admin-keys.tsx +162 -0
- package/src/components/admin/admin-notifications.tsx +130 -0
- package/src/components/admin/admin-page.tsx +24 -0
- package/src/components/admin/admin-parameters.tsx +864 -0
- package/src/components/admin/admin-payments.tsx +93 -0
- package/src/components/admin/admin-sessions.tsx +174 -0
- package/src/components/admin/admin-user-detail-audits-tab.tsx +82 -0
- package/src/components/admin/admin-user-detail-identity-aside.tsx +218 -0
- package/src/components/admin/admin-user-detail-overview-tab.tsx +87 -0
- package/src/components/admin/admin-user-detail-password-dialog.tsx +85 -0
- package/src/components/admin/admin-user-detail-password-schema.ts +11 -0
- package/src/components/admin/admin-user-detail-profile-schema.ts +19 -0
- package/src/components/admin/admin-user-detail-provider-labels.ts +15 -0
- package/src/components/admin/admin-user-detail-security-tab.tsx +146 -0
- package/src/components/admin/admin-user-detail-sessions-tab.tsx +93 -0
- package/src/components/admin/admin-user-detail.tsx +606 -0
- package/src/components/admin/admin-users-roles-picker.tsx +126 -0
- package/src/components/admin/admin-users-status-filter.tsx +51 -0
- package/src/components/admin/admin-users.tsx +518 -0
- package/src/components/admin/diff-lines.spec.ts +58 -0
- package/src/components/admin/diff-lines.ts +58 -0
- package/src/components/admin/parameter-diff-dialog.tsx +119 -0
- package/src/components/admin/parameter-history-item.tsx +252 -0
- package/src/components/admin/parameter-json-dialog.tsx +93 -0
- package/src/components/admin/parameter-save-dialog.tsx +126 -0
- package/src/components/admin/use-confirmed-action.tsx +93 -0
- package/src/components/alepha-table/__tests__/use-table-selection.browser.spec.tsx +92 -0
- package/src/components/alepha-table/alepha-table.tsx +1158 -0
- package/src/components/alepha-table/use-table-selection.ts +95 -0
- package/src/components/app-shell/app-shell.tsx +568 -0
- package/src/components/auth/__tests__/auth-router.spec.ts +52 -0
- package/src/components/auth/auth-login.tsx +382 -0
- package/src/components/auth/auth-register.tsx +786 -0
- package/src/components/auth/auth-reset-password.tsx +349 -0
- package/src/components/auth/auth-router.tsx +126 -0
- package/src/components/auth/auth-verify-email.tsx +179 -0
- package/src/components/auto-form/auto-form.tsx +867 -0
- package/src/components/brand-icon/brand-icon.tsx +104 -0
- package/src/components/button-dark/button-dark.tsx +78 -0
- package/src/components/button-language/button-language.tsx +98 -0
- package/src/components/button-theme/button-theme.tsx +148 -0
- package/src/components/button-user/button-user.tsx +214 -0
- package/src/components/captcha/turnstile-widget.tsx +157 -0
- package/src/components/control/control.tsx +735 -0
- package/src/components/control-array/control-array.tsx +700 -0
- package/src/components/control-base/__tests__/form-field-a11y.browser.spec.tsx +93 -0
- package/src/components/control-base/field-i18n.ts +60 -0
- package/src/components/control-base/form-field.tsx +275 -0
- package/src/components/control-base/grid.tsx +59 -0
- package/src/components/control-base/icon-hint.tsx +64 -0
- package/src/components/control-date/control-date.tsx +190 -0
- package/src/components/control-number/control-number.tsx +136 -0
- package/src/components/control-object/control-object.tsx +200 -0
- package/src/components/control-select/control-select.tsx +774 -0
- package/src/components/control-upload/control-upload.tsx +475 -0
- package/src/components/file-image/file-image.tsx +52 -0
- package/src/components/language-toggle/language-toggle.tsx +66 -0
- package/src/components/markdown-view/markdown-view.css +114 -0
- package/src/components/markdown-view/markdown-view.tsx +92 -0
- package/src/components/nav-shell/nav-page.tsx +56 -0
- package/src/components/nav-shell/nav-shell.tsx +72 -0
- package/src/components/nav-shell/nav-tree-util.ts +62 -0
- package/src/components/nav-shell/spotlight.tsx +163 -0
- package/src/components/nav-shell/use-nav-breadcrumbs.ts +52 -0
- package/src/components/nav-shell/use-nav-entries.ts +101 -0
- package/src/components/nav-shell/use-nav-tree.ts +61 -0
- package/src/components/ui/accordion.tsx +77 -0
- package/src/components/ui/alert-dialog.tsx +186 -0
- package/src/components/ui/alert.tsx +75 -0
- package/src/components/ui/aspect-ratio.tsx +22 -0
- package/src/components/ui/avatar.tsx +106 -0
- package/src/components/ui/badge.tsx +51 -0
- package/src/components/ui/breadcrumb.tsx +121 -0
- package/src/components/ui/button-group.tsx +86 -0
- package/src/components/ui/button.tsx +83 -0
- package/src/components/ui/calendar.tsx +235 -0
- package/src/components/ui/card.tsx +102 -0
- package/src/components/ui/carousel.tsx +241 -0
- package/src/components/ui/chart.tsx +370 -0
- package/src/components/ui/checkbox.tsx +27 -0
- package/src/components/ui/collapsible.tsx +19 -0
- package/src/components/ui/combobox.tsx +298 -0
- package/src/components/ui/command.tsx +196 -0
- package/src/components/ui/context-menu.tsx +271 -0
- package/src/components/ui/dialog.tsx +153 -0
- package/src/components/ui/direction.tsx +4 -0
- package/src/components/ui/drawer.tsx +130 -0
- package/src/components/ui/dropdown-menu.tsx +269 -0
- package/src/components/ui/empty.tsx +100 -0
- package/src/components/ui/hover-card.tsx +50 -0
- package/src/components/ui/input-group.tsx +157 -0
- package/src/components/ui/input-otp.tsx +83 -0
- package/src/components/ui/input.tsx +19 -0
- package/src/components/ui/item.tsx +200 -0
- package/src/components/ui/kbd.tsx +26 -0
- package/src/components/ui/label.tsx +19 -0
- package/src/components/ui/menubar.tsx +283 -0
- package/src/components/ui/navigation-menu.tsx +170 -0
- package/src/components/ui/pagination.tsx +133 -0
- package/src/components/ui/popover.tsx +87 -0
- package/src/components/ui/progress.tsx +82 -0
- package/src/components/ui/radio-group.tsx +35 -0
- package/src/components/ui/resizable.tsx +49 -0
- package/src/components/ui/scroll-area.tsx +51 -0
- package/src/components/ui/segmented.tsx +232 -0
- package/src/components/ui/select.tsx +201 -0
- package/src/components/ui/separator.tsx +22 -0
- package/src/components/ui/sheet.tsx +133 -0
- package/src/components/ui/sidebar.tsx +723 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/slider.tsx +51 -0
- package/src/components/ui/sonner.tsx +46 -0
- package/src/components/ui/spinner.tsx +15 -0
- package/src/components/ui/switch.tsx +29 -0
- package/src/components/ui/table.tsx +115 -0
- package/src/components/ui/tabs.tsx +79 -0
- package/src/components/ui/textarea.tsx +17 -0
- package/src/components/ui/toggle-group.tsx +86 -0
- package/src/components/ui/toggle.tsx +44 -0
- package/src/components/ui/tooltip.tsx +63 -0
- package/src/components/use-dialog/use-dialog.tsx +244 -0
- package/src/components/use-toast/use-toast.tsx +89 -0
- package/src/hooks/use-mobile.ts +21 -0
- package/src/lib/__tests__/i18n-fr.spec.ts +72 -0
- package/src/lib/i18n-fr.ts +500 -0
- package/src/lib/utils.ts +6 -0
- package/src/styles.css +129 -0
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
void React;
|
|
4
|
+
|
|
5
|
+
import { AdminPage } from "@alepha/ui/components/admin/admin-page";
|
|
6
|
+
import { useConfirmedAction } from "@alepha/ui/components/admin/use-confirmed-action";
|
|
7
|
+
import { AlephaTable } from "@alepha/ui/components/alepha-table/alepha-table";
|
|
8
|
+
import { Control } from "@alepha/ui/components/control/control";
|
|
9
|
+
import { Badge } from "@alepha/ui/components/ui/badge";
|
|
10
|
+
import {
|
|
11
|
+
HoverCard,
|
|
12
|
+
HoverCardContent,
|
|
13
|
+
HoverCardTrigger,
|
|
14
|
+
} from "@alepha/ui/components/ui/hover-card";
|
|
15
|
+
import { useToast } from "@alepha/ui/components/use-toast/use-toast";
|
|
16
|
+
import { type Infer, z } from "alepha";
|
|
17
|
+
import type {
|
|
18
|
+
AdminFileStatsController,
|
|
19
|
+
FileController,
|
|
20
|
+
FileResource,
|
|
21
|
+
} from "alepha/api/files";
|
|
22
|
+
import { useAction, useClient, useQuery } from "alepha/react";
|
|
23
|
+
import { useI18n } from "alepha/react/i18n";
|
|
24
|
+
import { Download, Search, Trash2, Upload } from "lucide-react";
|
|
25
|
+
import {
|
|
26
|
+
type ChangeEvent,
|
|
27
|
+
useCallback,
|
|
28
|
+
useMemo,
|
|
29
|
+
useRef,
|
|
30
|
+
useState,
|
|
31
|
+
} from "react";
|
|
32
|
+
|
|
33
|
+
const formatBytes = (n: number) => {
|
|
34
|
+
if (!n) return "0 B";
|
|
35
|
+
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
36
|
+
const i = Math.min(
|
|
37
|
+
units.length - 1,
|
|
38
|
+
Math.floor(Math.log(n) / Math.log(1024)),
|
|
39
|
+
);
|
|
40
|
+
return `${(n / 1024 ** i).toFixed(1)} ${units[i]}`;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Filter schema at module scope so its identity stays stable across renders
|
|
44
|
+
// — AlephaTable's internal `useForm` captures it once.
|
|
45
|
+
const filtersSchema = z.object({
|
|
46
|
+
name: z.string().optional(),
|
|
47
|
+
bucket: z.string().optional(),
|
|
48
|
+
});
|
|
49
|
+
type AdminFileFilters = Infer<typeof filtersSchema>;
|
|
50
|
+
|
|
51
|
+
const isImage = (mimeType?: string) => Boolean(mimeType?.startsWith("image/"));
|
|
52
|
+
|
|
53
|
+
export function AdminFiles() {
|
|
54
|
+
const client = useClient<FileController>();
|
|
55
|
+
const statsClient = useClient<AdminFileStatsController>();
|
|
56
|
+
const { l, tr } = useI18n();
|
|
57
|
+
const toast = useToast();
|
|
58
|
+
// Bumped after a successful upload to reload the bucket-stats query (which
|
|
59
|
+
// lists it in its deps) and the table (via AlephaTable's `refreshSignal`
|
|
60
|
+
// prop). Row/bulk actions reload via the table's own ctx.refresh() and
|
|
61
|
+
// don't touch this.
|
|
62
|
+
const [refreshKey, setRefreshKey] = useState(0);
|
|
63
|
+
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
64
|
+
|
|
65
|
+
// Populate the bucket filter from storage stats. Re-runs after uploads so
|
|
66
|
+
// counts (and any newly-created bucket) stay current. If stats can't be
|
|
67
|
+
// fetched the filter degrades to empty.
|
|
68
|
+
const { data: stats } = useQuery(
|
|
69
|
+
{
|
|
70
|
+
handler: ({ signal }) =>
|
|
71
|
+
statsClient.getFileStats({} as never, { request: { signal } }),
|
|
72
|
+
onError: () => {},
|
|
73
|
+
},
|
|
74
|
+
[statsClient, refreshKey],
|
|
75
|
+
);
|
|
76
|
+
const bucketItems = useMemo(
|
|
77
|
+
() =>
|
|
78
|
+
(stats?.byBucket ?? []).map((b) => ({
|
|
79
|
+
value: b.bucket,
|
|
80
|
+
label: `${b.bucket} (${b.fileCount})`,
|
|
81
|
+
})),
|
|
82
|
+
[stats],
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const downloadFile = useCallback((f: FileResource) => {
|
|
86
|
+
window.open(`/api/files/${f.id}`, "_blank");
|
|
87
|
+
}, []);
|
|
88
|
+
|
|
89
|
+
const upload = useAction<[ChangeEvent<HTMLInputElement>], void>(
|
|
90
|
+
{
|
|
91
|
+
handler: async (e) => {
|
|
92
|
+
const file = e.target.files?.[0];
|
|
93
|
+
// Reset so the same file can be re-selected on a subsequent click,
|
|
94
|
+
// regardless of whether the upload succeeds.
|
|
95
|
+
if (fileInputRef.current) fileInputRef.current.value = "";
|
|
96
|
+
if (!file) return;
|
|
97
|
+
await client.uploadFile({ body: { file } });
|
|
98
|
+
toast.success(
|
|
99
|
+
tr("admin.files.uploaded", {
|
|
100
|
+
default: `Uploaded ${file.name}`,
|
|
101
|
+
args: [file.name],
|
|
102
|
+
}),
|
|
103
|
+
);
|
|
104
|
+
setRefreshKey((k) => k + 1);
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
[client, toast, tr],
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const fetcher = useCallback(
|
|
111
|
+
async (params: {
|
|
112
|
+
page: number;
|
|
113
|
+
size: number;
|
|
114
|
+
sort?: string;
|
|
115
|
+
filters?: AdminFileFilters;
|
|
116
|
+
}) => {
|
|
117
|
+
return client.findFiles({
|
|
118
|
+
query: {
|
|
119
|
+
page: params.page,
|
|
120
|
+
size: params.size,
|
|
121
|
+
sort: params.sort,
|
|
122
|
+
name: params.filters?.name || undefined,
|
|
123
|
+
bucket: params.filters?.bucket || undefined,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
[client],
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const deleteFile = useConfirmedAction<[FileResource, () => void]>(
|
|
131
|
+
{
|
|
132
|
+
confirm: (file) => ({
|
|
133
|
+
title: tr("admin.files.deleteTitle", { default: "Delete file" }),
|
|
134
|
+
description: tr("admin.files.deleteConfirm", {
|
|
135
|
+
default: `Permanently delete "${file.name}"?`,
|
|
136
|
+
args: [file.name],
|
|
137
|
+
}),
|
|
138
|
+
destructive: true,
|
|
139
|
+
}),
|
|
140
|
+
handler: async (file, refresh) => {
|
|
141
|
+
await client.deleteFile({ params: { id: file.id } });
|
|
142
|
+
refresh();
|
|
143
|
+
},
|
|
144
|
+
success: tr("admin.files.deleted", { default: "File deleted" }),
|
|
145
|
+
},
|
|
146
|
+
[client, tr],
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const bulkDelete = useConfirmedAction<
|
|
150
|
+
[FileResource[], { clearSelection: () => void; refresh: () => void }]
|
|
151
|
+
>(
|
|
152
|
+
{
|
|
153
|
+
confirm: (items) => ({
|
|
154
|
+
title: tr("admin.files.bulkDeleteTitle", { default: "Delete files" }),
|
|
155
|
+
description: tr("admin.files.bulkDeleteConfirm", {
|
|
156
|
+
default: `Permanently delete ${items.length} file(s)? This cannot be undone.`,
|
|
157
|
+
args: [String(items.length)],
|
|
158
|
+
}),
|
|
159
|
+
destructive: true,
|
|
160
|
+
}),
|
|
161
|
+
handler: async (items, { clearSelection, refresh }) => {
|
|
162
|
+
if (items.length === 0) return;
|
|
163
|
+
const res = await client.deleteFiles({
|
|
164
|
+
body: { ids: items.map((f) => f.id) },
|
|
165
|
+
});
|
|
166
|
+
toast.success(
|
|
167
|
+
tr("admin.files.bulkDeleted", {
|
|
168
|
+
default: `${res.deleted.length} file(s) deleted`,
|
|
169
|
+
args: [String(res.deleted.length)],
|
|
170
|
+
}),
|
|
171
|
+
);
|
|
172
|
+
clearSelection();
|
|
173
|
+
refresh();
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
[client, toast, tr],
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
return (
|
|
180
|
+
<AdminPage>
|
|
181
|
+
<input
|
|
182
|
+
ref={fileInputRef}
|
|
183
|
+
type="file"
|
|
184
|
+
className="hidden"
|
|
185
|
+
onChange={(e) => upload.run(e)}
|
|
186
|
+
/>
|
|
187
|
+
<AlephaTable<FileResource>
|
|
188
|
+
className="min-h-0 flex-1"
|
|
189
|
+
persistenceKey="admin.files"
|
|
190
|
+
fetch={fetcher}
|
|
191
|
+
refreshSignal={refreshKey}
|
|
192
|
+
actions={[
|
|
193
|
+
{
|
|
194
|
+
icon: Upload,
|
|
195
|
+
label: upload.loading
|
|
196
|
+
? tr("admin.files.uploading", { default: "Uploading…" })
|
|
197
|
+
: tr("admin.files.upload", { default: "Upload" }),
|
|
198
|
+
disabled: upload.loading,
|
|
199
|
+
onClick: () => fileInputRef.current?.click(),
|
|
200
|
+
},
|
|
201
|
+
]}
|
|
202
|
+
filters={{
|
|
203
|
+
schema: filtersSchema,
|
|
204
|
+
render: (form) => (
|
|
205
|
+
<div className="flex items-center gap-2">
|
|
206
|
+
<div className="w-64">
|
|
207
|
+
<Control
|
|
208
|
+
input={form.input.name}
|
|
209
|
+
label=""
|
|
210
|
+
icon={Search}
|
|
211
|
+
placeholder={String(
|
|
212
|
+
tr("admin.files.searchPlaceholder", {
|
|
213
|
+
default: "Search by name…",
|
|
214
|
+
}),
|
|
215
|
+
)}
|
|
216
|
+
/>
|
|
217
|
+
</div>
|
|
218
|
+
<Control
|
|
219
|
+
input={form.input.bucket}
|
|
220
|
+
label=""
|
|
221
|
+
clearable
|
|
222
|
+
clearLabel={String(
|
|
223
|
+
tr("admin.files.allBuckets", { default: "All buckets" }),
|
|
224
|
+
)}
|
|
225
|
+
triggerClassName="w-48"
|
|
226
|
+
placeholder={String(
|
|
227
|
+
tr("admin.files.bucketPlaceholder", { default: "Bucket" }),
|
|
228
|
+
)}
|
|
229
|
+
items={bucketItems}
|
|
230
|
+
/>
|
|
231
|
+
</div>
|
|
232
|
+
),
|
|
233
|
+
}}
|
|
234
|
+
bulkActions={[
|
|
235
|
+
{
|
|
236
|
+
label: tr("admin.files.bulkDelete", {
|
|
237
|
+
default: "Delete selected",
|
|
238
|
+
}),
|
|
239
|
+
icon: Trash2,
|
|
240
|
+
destructive: true,
|
|
241
|
+
onClick: (items, ctx) => bulkDelete.run(items, ctx),
|
|
242
|
+
},
|
|
243
|
+
]}
|
|
244
|
+
columns={{
|
|
245
|
+
name: {
|
|
246
|
+
label: tr("admin.files.colName", { default: "Name" }),
|
|
247
|
+
cell: (f) => {
|
|
248
|
+
const trigger = (
|
|
249
|
+
<button
|
|
250
|
+
type="button"
|
|
251
|
+
onClick={() => downloadFile(f)}
|
|
252
|
+
className="hover:text-primary truncate text-left font-medium underline-offset-2 hover:underline"
|
|
253
|
+
>
|
|
254
|
+
{f.name}
|
|
255
|
+
</button>
|
|
256
|
+
);
|
|
257
|
+
if (!isImage(f.mimeType)) return trigger;
|
|
258
|
+
return (
|
|
259
|
+
<HoverCard>
|
|
260
|
+
<HoverCardTrigger render={trigger} />
|
|
261
|
+
<HoverCardContent className="w-auto p-1">
|
|
262
|
+
<img
|
|
263
|
+
src={`/api/files/${f.id}`}
|
|
264
|
+
alt={f.name}
|
|
265
|
+
loading="lazy"
|
|
266
|
+
className="max-h-48 max-w-64 rounded object-contain"
|
|
267
|
+
/>
|
|
268
|
+
</HoverCardContent>
|
|
269
|
+
</HoverCard>
|
|
270
|
+
);
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
user: {
|
|
274
|
+
label: tr("admin.files.colUser", { default: "Uploaded by" }),
|
|
275
|
+
cell: (f) => {
|
|
276
|
+
const label =
|
|
277
|
+
f.user?.email ||
|
|
278
|
+
f.user?.username ||
|
|
279
|
+
[f.user?.firstName, f.user?.lastName]
|
|
280
|
+
.filter(Boolean)
|
|
281
|
+
.join(" ") ||
|
|
282
|
+
f.creatorName ||
|
|
283
|
+
null;
|
|
284
|
+
return label ? (
|
|
285
|
+
<span className="truncate">{label}</span>
|
|
286
|
+
) : (
|
|
287
|
+
<span className="text-muted-foreground font-mono text-xs">
|
|
288
|
+
{f.creator?.slice(0, 8) ?? "—"}
|
|
289
|
+
</span>
|
|
290
|
+
);
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
size: {
|
|
294
|
+
label: tr("admin.files.colSize", { default: "Size" }),
|
|
295
|
+
align: "right",
|
|
296
|
+
cell: (f) => (
|
|
297
|
+
<span className="text-muted-foreground text-xs">
|
|
298
|
+
{formatBytes(f.size ?? 0)}
|
|
299
|
+
</span>
|
|
300
|
+
),
|
|
301
|
+
},
|
|
302
|
+
mimeType: {
|
|
303
|
+
label: tr("admin.files.colType", { default: "Type" }),
|
|
304
|
+
cell: (f) => (
|
|
305
|
+
<Badge variant="secondary">
|
|
306
|
+
{f.mimeType ??
|
|
307
|
+
tr("admin.files.unknown", { default: "unknown" })}
|
|
308
|
+
</Badge>
|
|
309
|
+
),
|
|
310
|
+
},
|
|
311
|
+
bucket: {
|
|
312
|
+
label: tr("admin.files.colBucket", { default: "Bucket" }),
|
|
313
|
+
cell: (f) => <code className="text-xs">{f.bucket ?? "—"}</code>,
|
|
314
|
+
},
|
|
315
|
+
createdAt: {
|
|
316
|
+
label: tr("admin.files.colUploaded", { default: "Uploaded" }),
|
|
317
|
+
sortable: true,
|
|
318
|
+
cell: (f) => (
|
|
319
|
+
<span
|
|
320
|
+
className="text-muted-foreground text-xs"
|
|
321
|
+
title={String(l(f.createdAt, { date: "lll" }))}
|
|
322
|
+
>
|
|
323
|
+
{String(l(f.createdAt, { date: "fromNow" }))}
|
|
324
|
+
</span>
|
|
325
|
+
),
|
|
326
|
+
},
|
|
327
|
+
}}
|
|
328
|
+
rowActions={(f) => [
|
|
329
|
+
{
|
|
330
|
+
label: tr("admin.files.download", { default: "Download" }),
|
|
331
|
+
icon: Download,
|
|
332
|
+
onClick: () => downloadFile(f),
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
label: tr("admin.files.delete", { default: "Delete" }),
|
|
336
|
+
icon: Trash2,
|
|
337
|
+
destructive: true,
|
|
338
|
+
onClick: (_f, { refresh }) => deleteFile.run(f, refresh),
|
|
339
|
+
},
|
|
340
|
+
]}
|
|
341
|
+
/>
|
|
342
|
+
</AdminPage>
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export default AdminFiles;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { JobStatusBadge } from "@alepha/ui/components/admin/admin-jobs-status-badge";
|
|
2
|
+
import { useConfirmedAction } from "@alepha/ui/components/admin/use-confirmed-action";
|
|
3
|
+
import { AlephaTable } from "@alepha/ui/components/alepha-table/alepha-table";
|
|
4
|
+
import { Control } from "@alepha/ui/components/control/control";
|
|
5
|
+
import { type Infer, type Page, z } from "alepha";
|
|
6
|
+
import type { AdminJobController, JobExecutionResource } from "alepha/api/jobs";
|
|
7
|
+
import { useClient } from "alepha/react";
|
|
8
|
+
import { useI18n } from "alepha/react/i18n";
|
|
9
|
+
import { Ban, RotateCcw } from "lucide-react";
|
|
10
|
+
import { useCallback } from "react";
|
|
11
|
+
|
|
12
|
+
const EXEC_POLL_MS = 10_000;
|
|
13
|
+
|
|
14
|
+
const execFiltersSchema = z.object({
|
|
15
|
+
status: z.string().optional(),
|
|
16
|
+
});
|
|
17
|
+
type ExecFilters = Infer<typeof execFiltersSchema>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Wrap an in-memory array as a `Page<T>` so it can feed `AlephaTable`'s fetcher
|
|
21
|
+
* without server-side pagination (the executions endpoint returns a bounded
|
|
22
|
+
* window).
|
|
23
|
+
*/
|
|
24
|
+
function asPage<T>(items: T[]): Page<T> {
|
|
25
|
+
return {
|
|
26
|
+
content: items,
|
|
27
|
+
page: {
|
|
28
|
+
number: 0,
|
|
29
|
+
size: items.length,
|
|
30
|
+
offset: 0,
|
|
31
|
+
numberOfElements: items.length,
|
|
32
|
+
totalElements: items.length,
|
|
33
|
+
totalPages: 1,
|
|
34
|
+
isEmpty: items.length === 0,
|
|
35
|
+
isFirst: true,
|
|
36
|
+
isLast: true,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface JobExecutionsPanelProps {
|
|
42
|
+
jobName: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Executions table for a single job — a polling `AlephaTable` of
|
|
47
|
+
* `JobExecutionResource` with status filter and retry/cancel row actions
|
|
48
|
+
* (gated server-side via `e.can.*`). Self-contained: resolves its own client,
|
|
49
|
+
* i18n and dialogs rather than receiving them as props.
|
|
50
|
+
*/
|
|
51
|
+
export const JobExecutionsPanel = (props: JobExecutionsPanelProps) => {
|
|
52
|
+
const { jobName } = props;
|
|
53
|
+
const client = useClient<AdminJobController>();
|
|
54
|
+
const { l, tr } = useI18n();
|
|
55
|
+
|
|
56
|
+
const fetcher = useCallback(
|
|
57
|
+
async (params: { filters?: ExecFilters }) => {
|
|
58
|
+
const status = params.filters?.status as
|
|
59
|
+
| "pending"
|
|
60
|
+
| "running"
|
|
61
|
+
| "scheduled"
|
|
62
|
+
| "ok"
|
|
63
|
+
| "error"
|
|
64
|
+
| "cancelled"
|
|
65
|
+
| undefined;
|
|
66
|
+
const rows = await client.listExecutions({
|
|
67
|
+
params: { name: jobName },
|
|
68
|
+
query: status ? { status, limit: 100 } : { limit: 100 },
|
|
69
|
+
});
|
|
70
|
+
return asPage(rows as JobExecutionResource[]);
|
|
71
|
+
},
|
|
72
|
+
[client, jobName],
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const retry = useConfirmedAction<[JobExecutionResource, () => void]>(
|
|
76
|
+
{
|
|
77
|
+
confirm: {
|
|
78
|
+
title: tr("admin.jobs.retryTitle", { default: "Retry execution" }),
|
|
79
|
+
description: tr("admin.jobs.retryConfirm", {
|
|
80
|
+
default: "Re-queue this execution for another attempt?",
|
|
81
|
+
}),
|
|
82
|
+
},
|
|
83
|
+
handler: async (e, refresh) => {
|
|
84
|
+
await client.retryExecution({ params: { id: e.id } });
|
|
85
|
+
refresh();
|
|
86
|
+
},
|
|
87
|
+
success: tr("admin.jobs.retried", { default: "Execution re-queued" }),
|
|
88
|
+
},
|
|
89
|
+
[client, tr],
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const cancel = useConfirmedAction<[JobExecutionResource, () => void]>(
|
|
93
|
+
{
|
|
94
|
+
confirm: {
|
|
95
|
+
title: tr("admin.jobs.cancelTitle", { default: "Cancel execution" }),
|
|
96
|
+
description: tr("admin.jobs.cancelConfirm", {
|
|
97
|
+
default: "Cancel this pending execution? It will not run.",
|
|
98
|
+
}),
|
|
99
|
+
destructive: true,
|
|
100
|
+
},
|
|
101
|
+
handler: async (e, refresh) => {
|
|
102
|
+
await client.cancelExecution({ params: { id: e.id } });
|
|
103
|
+
refresh();
|
|
104
|
+
},
|
|
105
|
+
success: tr("admin.jobs.cancelled", { default: "Execution cancelled" }),
|
|
106
|
+
},
|
|
107
|
+
[client, tr],
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<AlephaTable<JobExecutionResource>
|
|
112
|
+
className="min-h-0 flex-1"
|
|
113
|
+
persistenceKey={`admin.jobs.executions.${jobName}`}
|
|
114
|
+
pollMs={EXEC_POLL_MS}
|
|
115
|
+
rowKey={(e) => e.id}
|
|
116
|
+
fetch={fetcher}
|
|
117
|
+
filters={{
|
|
118
|
+
schema: execFiltersSchema,
|
|
119
|
+
render: (form) => (
|
|
120
|
+
<Control
|
|
121
|
+
input={form.input.status}
|
|
122
|
+
label=""
|
|
123
|
+
clearable
|
|
124
|
+
clearLabel={String(
|
|
125
|
+
tr("admin.jobs.statusAll", { default: "All statuses" }),
|
|
126
|
+
)}
|
|
127
|
+
triggerClassName="w-40"
|
|
128
|
+
items={[
|
|
129
|
+
{ value: "pending", label: "pending" },
|
|
130
|
+
{ value: "running", label: "running" },
|
|
131
|
+
{ value: "scheduled", label: "scheduled" },
|
|
132
|
+
{ value: "ok", label: "ok" },
|
|
133
|
+
{ value: "error", label: "error" },
|
|
134
|
+
{ value: "cancelled", label: "cancelled" },
|
|
135
|
+
]}
|
|
136
|
+
/>
|
|
137
|
+
),
|
|
138
|
+
}}
|
|
139
|
+
columns={{
|
|
140
|
+
status: {
|
|
141
|
+
label: tr("admin.jobs.colStatus", { default: "Status" }),
|
|
142
|
+
cell: (e) => <JobStatusBadge status={e.status} />,
|
|
143
|
+
},
|
|
144
|
+
startedAt: {
|
|
145
|
+
label: tr("admin.jobs.colStarted", { default: "Started" }),
|
|
146
|
+
cell: (e) => (
|
|
147
|
+
<span className="text-muted-foreground text-xs">
|
|
148
|
+
{e.startedAt
|
|
149
|
+
? String(l(e.startedAt, { date: "fromNow" }))
|
|
150
|
+
: tr("admin.jobs.notStarted", { default: "—" })}
|
|
151
|
+
</span>
|
|
152
|
+
),
|
|
153
|
+
},
|
|
154
|
+
duration: {
|
|
155
|
+
label: tr("admin.jobs.colDuration", { default: "Duration" }),
|
|
156
|
+
align: "right",
|
|
157
|
+
cell: (e) => {
|
|
158
|
+
if (!e.startedAt || !e.completedAt) {
|
|
159
|
+
return <span className="text-muted-foreground">—</span>;
|
|
160
|
+
}
|
|
161
|
+
const ms =
|
|
162
|
+
new Date(e.completedAt).getTime() -
|
|
163
|
+
new Date(e.startedAt).getTime();
|
|
164
|
+
return (
|
|
165
|
+
<span className="text-xs">
|
|
166
|
+
{ms < 1000 ? `${ms} ms` : `${(ms / 1000).toFixed(1)} s`}
|
|
167
|
+
</span>
|
|
168
|
+
);
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
attempt: {
|
|
172
|
+
label: tr("admin.jobs.colAttempt", { default: "Attempt" }),
|
|
173
|
+
align: "right",
|
|
174
|
+
cell: (e) => (
|
|
175
|
+
<span className="text-xs">
|
|
176
|
+
{e.attempt}/{e.maxAttempts}
|
|
177
|
+
</span>
|
|
178
|
+
),
|
|
179
|
+
},
|
|
180
|
+
triggeredBy: {
|
|
181
|
+
label: tr("admin.jobs.colTriggeredBy", { default: "Triggered by" }),
|
|
182
|
+
cell: (e) => (
|
|
183
|
+
<span className="text-muted-foreground text-xs">
|
|
184
|
+
{e.triggeredByName ?? e.triggeredBy ?? "—"}
|
|
185
|
+
</span>
|
|
186
|
+
),
|
|
187
|
+
},
|
|
188
|
+
error: {
|
|
189
|
+
label: tr("admin.jobs.colError", { default: "Error" }),
|
|
190
|
+
cell: (e) =>
|
|
191
|
+
e.error ? (
|
|
192
|
+
<span
|
|
193
|
+
className="text-destructive line-clamp-2 text-xs"
|
|
194
|
+
title={e.error}
|
|
195
|
+
>
|
|
196
|
+
{e.error}
|
|
197
|
+
</span>
|
|
198
|
+
) : (
|
|
199
|
+
<span className="text-muted-foreground">—</span>
|
|
200
|
+
),
|
|
201
|
+
},
|
|
202
|
+
}}
|
|
203
|
+
rowActions={(e) => {
|
|
204
|
+
const actions = [] as Array<{
|
|
205
|
+
label: string;
|
|
206
|
+
icon: typeof RotateCcw;
|
|
207
|
+
onClick: (
|
|
208
|
+
_e: JobExecutionResource,
|
|
209
|
+
ctx: { refresh: () => void },
|
|
210
|
+
) => void;
|
|
211
|
+
destructive?: boolean;
|
|
212
|
+
}>;
|
|
213
|
+
if (e.can.retry) {
|
|
214
|
+
actions.push({
|
|
215
|
+
label: tr("admin.jobs.retry", { default: "Retry" }),
|
|
216
|
+
icon: RotateCcw,
|
|
217
|
+
onClick: (_e, { refresh }) => retry.run(e, refresh),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
if (e.can.cancel) {
|
|
221
|
+
actions.push({
|
|
222
|
+
label: tr("admin.jobs.cancel", { default: "Cancel" }),
|
|
223
|
+
icon: Ban,
|
|
224
|
+
destructive: true,
|
|
225
|
+
onClick: (_e, { refresh }) => cancel.run(e, refresh),
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
return actions;
|
|
229
|
+
}}
|
|
230
|
+
emptyMessage={String(
|
|
231
|
+
tr("admin.jobs.noExecs", { default: "No executions yet." }),
|
|
232
|
+
)}
|
|
233
|
+
/>
|
|
234
|
+
);
|
|
235
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Badge } from "@alepha/ui/components/ui/badge";
|
|
2
|
+
import type { JobExecutionResource } from "alepha/api/jobs";
|
|
3
|
+
import { useI18n } from "alepha/react/i18n";
|
|
4
|
+
|
|
5
|
+
export interface JobStatusBadgeProps {
|
|
6
|
+
status: JobExecutionResource["status"];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const VARIANTS: Record<
|
|
10
|
+
JobExecutionResource["status"],
|
|
11
|
+
"default" | "secondary" | "outline" | "destructive"
|
|
12
|
+
> = {
|
|
13
|
+
pending: "secondary",
|
|
14
|
+
scheduled: "secondary",
|
|
15
|
+
running: "default",
|
|
16
|
+
ok: "outline",
|
|
17
|
+
error: "destructive",
|
|
18
|
+
cancelled: "outline",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Coloured badge for a job execution's status.
|
|
23
|
+
*/
|
|
24
|
+
export const JobStatusBadge = (props: JobStatusBadgeProps) => {
|
|
25
|
+
const { tr } = useI18n();
|
|
26
|
+
return (
|
|
27
|
+
<Badge variant={VARIANTS[props.status]}>
|
|
28
|
+
{tr(`admin.jobs.status.${props.status}` as any, {
|
|
29
|
+
default: props.status,
|
|
30
|
+
})}
|
|
31
|
+
</Badge>
|
|
32
|
+
);
|
|
33
|
+
};
|