@telamonjs/ui 1.3.0 → 1.4.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 (60) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/README.md +7 -8
  3. package/dist/components/data/DataTableActions.js +4 -3
  4. package/dist/components/dialog/confirm-action-dialog.js +124 -111
  5. package/dist/data/ExportMenu.js +6 -3
  6. package/dist/data/InfiniteList.js +6 -2
  7. package/dist/data/datatable/sort-field.d.ts +14 -0
  8. package/dist/data/datatable/sort-field.js +24 -0
  9. package/dist/data/datatable/useDataTableInstance.js +3 -2
  10. package/dist/data/exportUtils.d.ts +14 -9
  11. package/dist/data/exportUtils.js +56 -56
  12. package/dist/data/missing-peer.d.ts +17 -0
  13. package/dist/data/missing-peer.js +22 -0
  14. package/dist/data/xlsx-writer.d.ts +24 -0
  15. package/dist/data/xlsx-writer.js +141 -0
  16. package/dist/exports/types-constants.d.ts +1 -1
  17. package/dist/exports/types-constants.js +1 -1
  18. package/dist/i18n/messages/en/data.d.ts +1 -0
  19. package/dist/i18n/messages/en/data.js +1 -0
  20. package/dist/i18n/messages/en/index.d.ts +3 -0
  21. package/dist/i18n/messages/en/queue.d.ts +2 -0
  22. package/dist/i18n/messages/en/queue.js +3 -1
  23. package/dist/i18n/messages/es/data.d.ts +1 -0
  24. package/dist/i18n/messages/es/data.js +1 -0
  25. package/dist/i18n/messages/es/index.d.ts +3 -0
  26. package/dist/i18n/messages/es/queue.d.ts +2 -0
  27. package/dist/i18n/messages/es/queue.js +3 -1
  28. package/dist/i18n/messages/pt-BR/data.d.ts +1 -0
  29. package/dist/i18n/messages/pt-BR/data.js +1 -0
  30. package/dist/i18n/messages/pt-BR/index.d.ts +3 -0
  31. package/dist/i18n/messages/pt-BR/queue.d.ts +2 -0
  32. package/dist/i18n/messages/pt-BR/queue.js +3 -1
  33. package/dist/i18n/use-t.d.ts +3 -0
  34. package/dist/pages/ListPage.js +6 -1
  35. package/dist/queue/components/DispatchJobModal.js +157 -115
  36. package/dist/queue/components/JobEventTimeline.js +321 -210
  37. package/dist/queue/hooks/use-queue-events-timeline.d.ts +7 -1
  38. package/dist/queue/hooks/use-queue-events-timeline.js +14 -43
  39. package/dist/queue/hooks/use-queue-sse.js +3 -1
  40. package/dist/queue/types.d.ts +2 -0
  41. package/dist/server/pagination/factory.js +5 -1
  42. package/dist/server/pagination/types.d.ts +6 -2
  43. package/dist/server/pagination/utils.d.ts +6 -3
  44. package/dist/server/pagination/utils.js +13 -7
  45. package/dist/server/prisma-helpers.d.ts +27 -19
  46. package/dist/server/prisma-helpers.js +37 -19
  47. package/dist/stores/datatable-store.d.ts +0 -4
  48. package/dist/stores/datatable-store.js +0 -5
  49. package/dist/stores/form-store.d.ts +5 -0
  50. package/dist/stores/form-store.js +8 -4
  51. package/dist/stores/index.d.ts +1 -1
  52. package/dist/stores/index.js +1 -3
  53. package/dist/stores/sidebar-store.d.ts +1 -1
  54. package/dist/types/actions.d.ts +4 -1
  55. package/dist/types/crud.d.ts +14 -1
  56. package/dist/types/system-config.d.ts +5 -0
  57. package/dist/ui/chart.d.ts +22 -27
  58. package/dist/ui/chart.js +2 -8
  59. package/dist/ui/form.d.ts +1 -1
  60. package/package.json +67 -64
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  // src/queue/components/DispatchJobModal.tsx
4
- import { Fragment, useState } from "react";
4
+ import { Fragment, useId, useState } from "react";
5
5
  import { X, Play, RefreshCw, Info, Zap, Code, AlertCircle } from "lucide-react";
6
6
  import { cn } from "../../utils/cn.js";
7
7
  import { logger } from "../../utils/logger.js";
@@ -9,6 +9,7 @@ import { toast } from "sonner";
9
9
  import { useQueueApi } from "../api/provider.js";
10
10
  import { useTelamonjsT } from "../../i18n/use-t.js";
11
11
  import { useQueueLabels } from "./labels-context.js";
12
+ import { useEscapeToClose } from "../hooks/use-escape-to-close.js";
12
13
  import { jsx, jsxs } from "react/jsx-runtime";
13
14
  function getDefaultKnownSchemaFields(t) {
14
15
  return {
@@ -68,6 +69,14 @@ function getDefaultKnownSchemaFields(t) {
68
69
  ]
69
70
  };
70
71
  }
72
+ function parseJsonArray(text) {
73
+ try {
74
+ const value = JSON.parse(text);
75
+ return Array.isArray(value) ? value : null;
76
+ } catch {
77
+ return null;
78
+ }
79
+ }
71
80
  function DispatchJobModal({
72
81
  job,
73
82
  onClose,
@@ -84,6 +93,8 @@ function DispatchJobModal({
84
93
  const [jsonMode, setJsonMode] = useState(false);
85
94
  const [jsonData, setJsonData] = useState("{}");
86
95
  const [jsonError, setJsonError] = useState(null);
96
+ const fieldIdPrefix = useId();
97
+ useEscapeToClose(!!job, onClose);
87
98
  const schemaFields = job ? resolvedSchemaFields[job.name] : void 0;
88
99
  const hasRequiredFields = schemaFields && schemaFields.some((f) => f.required);
89
100
  const [prevJobName, setPrevJobName] = useState(job?.name);
@@ -122,9 +133,23 @@ function DispatchJobModal({
122
133
  toast.error(t("queue.dispatch.invalidJson"));
123
134
  return;
124
135
  }
136
+ let data;
137
+ if (jsonMode) {
138
+ data = JSON.parse(jsonData);
139
+ } else {
140
+ data = { ...formData };
141
+ for (const f of schemaFields ?? []) {
142
+ if (f.type !== "array" || !formData[f.name]) continue;
143
+ const parsed = parseJsonArray(formData[f.name]);
144
+ if (!parsed) {
145
+ toast.error(t("queue.dispatch.invalidJson"));
146
+ return;
147
+ }
148
+ data[f.name] = parsed;
149
+ }
150
+ }
125
151
  setDispatching(true);
126
152
  try {
127
- const data = jsonMode ? JSON.parse(jsonData) : formData;
128
153
  const result = await api.dispatchJob({
129
154
  queueName: job.name,
130
155
  data
@@ -163,131 +188,148 @@ function DispatchJobModal({
163
188
  onClick: onClose
164
189
  }
165
190
  ),
166
- /* @__PURE__ */ jsxs("div", { className: "fixed inset-4 md:inset-auto md:left-1/2 md:top-1/2 md:-translate-x-1/2 md:-translate-y-1/2 md:w-full md:max-w-lg bg-background rounded-xl shadow-2xl z-50 flex flex-col animate-in zoom-in-95 duration-200 max-h-[90vh]", children: [
167
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4 border-b", children: [
168
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
169
- /* @__PURE__ */ jsx("div", { className: "p-2 rounded-lg bg-blue-100 dark:bg-blue-900/30", children: /* @__PURE__ */ jsx(Zap, { className: "h-5 w-5 text-blue-600 dark:text-blue-400" }) }),
170
- /* @__PURE__ */ jsxs("div", { children: [
171
- /* @__PURE__ */ jsx("h2", { className: "text-lg font-semibold", children: t("queue.dispatch.title") }),
172
- /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("queue.dispatch.subtitle") })
173
- ] })
174
- ] }),
175
- /* @__PURE__ */ jsx(
176
- "button",
177
- {
178
- onClick: onClose,
179
- className: "p-2 rounded-lg hover:bg-muted transition-colors",
180
- "aria-label": t("queue.dispatch.close"),
181
- children: /* @__PURE__ */ jsx(X, { className: "h-5 w-5" })
182
- }
183
- )
184
- ] }),
185
- /* @__PURE__ */ jsx("div", { className: "flex-1 overflow-y-auto p-6 space-y-6", children: /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
186
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
187
- /* @__PURE__ */ jsx(
188
- "span",
189
- {
190
- className: cn(
191
- "px-2 py-0.5 rounded-md text-xs font-medium",
192
- moduleColor
193
- ),
194
- children: job.module.toUpperCase()
195
- }
196
- ),
197
- /* @__PURE__ */ jsx("span", { className: "font-medium", children: title })
198
- ] }),
199
- /* @__PURE__ */ jsxs("div", { className: "bg-muted/50 rounded-lg p-4 space-y-2", children: [
200
- /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-2", children: [
201
- /* @__PURE__ */ jsx(Info, { className: "h-4 w-4 text-muted-foreground mt-0.5" }),
202
- /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: job.description })
203
- ] }),
204
- /* @__PURE__ */ jsx("code", { className: "block text-xs font-mono text-muted-foreground", children: t("queue.dispatch.queueLabel", { name: job.name }) })
205
- ] }),
206
- !job.dispatchable && /* @__PURE__ */ jsx("div", { className: "bg-yellow-50 dark:bg-yellow-950/30 border border-yellow-200 dark:border-yellow-900 rounded-lg p-4", children: /* @__PURE__ */ jsx("p", { className: "text-sm text-yellow-700 dark:text-yellow-300", children: t("queue.dispatch.notDispatchableInfo") }) }),
207
- job.dispatchable && (schemaFields || hasRequiredFields) && /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
208
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
209
- /* @__PURE__ */ jsx("h3", { className: "text-sm font-medium", children: t("queue.dispatch.inputDataTitle") }),
210
- /* @__PURE__ */ jsxs(
191
+ /* @__PURE__ */ jsxs(
192
+ "div",
193
+ {
194
+ role: "dialog",
195
+ "aria-modal": "true",
196
+ "aria-labelledby": `${fieldIdPrefix}-title`,
197
+ className: "fixed inset-4 md:inset-auto md:left-1/2 md:top-1/2 md:-translate-x-1/2 md:-translate-y-1/2 md:w-full md:max-w-lg bg-background rounded-xl shadow-2xl z-50 flex flex-col animate-in zoom-in-95 duration-200 max-h-[90vh]",
198
+ children: [
199
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4 border-b", children: [
200
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
201
+ /* @__PURE__ */ jsx("div", { className: "p-2 rounded-lg bg-blue-100 dark:bg-blue-900/30", children: /* @__PURE__ */ jsx(Zap, { className: "h-5 w-5 text-blue-600 dark:text-blue-400" }) }),
202
+ /* @__PURE__ */ jsxs("div", { children: [
203
+ /* @__PURE__ */ jsx("h2", { id: `${fieldIdPrefix}-title`, className: "text-lg font-semibold", children: t("queue.dispatch.title") }),
204
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("queue.dispatch.subtitle") })
205
+ ] })
206
+ ] }),
207
+ /* @__PURE__ */ jsx(
211
208
  "button",
212
209
  {
213
- onClick: () => setJsonMode(!jsonMode),
214
- "data-testid": "dispatch-toggle-json-mode",
215
- className: "text-xs text-muted-foreground hover:text-foreground flex items-center gap-1",
216
- children: [
217
- /* @__PURE__ */ jsx(Code, { className: "h-3 w-3" }),
218
- jsonMode ? t("queue.dispatch.formMode") : t("queue.dispatch.jsonMode")
219
- ]
210
+ onClick: onClose,
211
+ className: "p-2 rounded-lg hover:bg-muted transition-colors",
212
+ "aria-label": t("queue.dispatch.close"),
213
+ children: /* @__PURE__ */ jsx(X, { className: "h-5 w-5" })
220
214
  }
221
215
  )
222
216
  ] }),
223
- jsonMode ? /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
217
+ /* @__PURE__ */ jsx("div", { className: "flex-1 overflow-y-auto p-6 space-y-6", children: /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
218
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
219
+ /* @__PURE__ */ jsx(
220
+ "span",
221
+ {
222
+ className: cn(
223
+ "px-2 py-0.5 rounded-md text-xs font-medium",
224
+ moduleColor
225
+ ),
226
+ children: job.module.toUpperCase()
227
+ }
228
+ ),
229
+ /* @__PURE__ */ jsx("span", { className: "font-medium", children: title })
230
+ ] }),
231
+ /* @__PURE__ */ jsxs("div", { className: "bg-muted/50 rounded-lg p-4 space-y-2", children: [
232
+ /* @__PURE__ */ jsxs("div", { className: "flex items-start gap-2", children: [
233
+ /* @__PURE__ */ jsx(Info, { className: "h-4 w-4 text-muted-foreground mt-0.5" }),
234
+ /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: job.description })
235
+ ] }),
236
+ /* @__PURE__ */ jsx("code", { className: "block text-xs font-mono text-muted-foreground", children: t("queue.dispatch.queueLabel", { name: job.name }) })
237
+ ] }),
238
+ !job.dispatchable && /* @__PURE__ */ jsx("div", { className: "bg-yellow-50 dark:bg-yellow-950/30 border border-yellow-200 dark:border-yellow-900 rounded-lg p-4", children: /* @__PURE__ */ jsx("p", { className: "text-sm text-yellow-700 dark:text-yellow-300", children: t("queue.dispatch.notDispatchableInfo") }) }),
239
+ job.dispatchable && (schemaFields || hasRequiredFields) && /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
240
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
241
+ /* @__PURE__ */ jsx("h3", { className: "text-sm font-medium", children: t("queue.dispatch.inputDataTitle") }),
242
+ /* @__PURE__ */ jsxs(
243
+ "button",
244
+ {
245
+ onClick: () => setJsonMode(!jsonMode),
246
+ "data-testid": "dispatch-toggle-json-mode",
247
+ className: "text-xs text-muted-foreground hover:text-foreground flex items-center gap-1",
248
+ children: [
249
+ /* @__PURE__ */ jsx(Code, { className: "h-3 w-3" }),
250
+ jsonMode ? t("queue.dispatch.formMode") : t("queue.dispatch.jsonMode")
251
+ ]
252
+ }
253
+ )
254
+ ] }),
255
+ jsonMode ? /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
256
+ /* @__PURE__ */ jsx(
257
+ "textarea",
258
+ {
259
+ value: jsonData,
260
+ onChange: (e) => {
261
+ setJsonData(e.target.value);
262
+ validateJson(e.target.value);
263
+ },
264
+ className: cn(
265
+ "w-full h-32 px-3 py-2 text-sm font-mono bg-muted rounded-lg border resize-none",
266
+ jsonError && "border-red-500"
267
+ ),
268
+ placeholder: '{"rotaId": "..."}'
269
+ }
270
+ ),
271
+ jsonError && /* @__PURE__ */ jsxs("p", { className: "text-xs text-red-500 flex items-center gap-1", children: [
272
+ /* @__PURE__ */ jsx(AlertCircle, { className: "h-3 w-3" }),
273
+ jsonError
274
+ ] })
275
+ ] }) : /* @__PURE__ */ jsx("div", { className: "space-y-3", children: schemaFields?.map((field) => /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
276
+ /* @__PURE__ */ jsxs(
277
+ "label",
278
+ {
279
+ htmlFor: `${fieldIdPrefix}-field-${field.name}`,
280
+ className: "text-sm font-medium flex items-center gap-1",
281
+ children: [
282
+ field.name,
283
+ field.required && /* @__PURE__ */ jsx("span", { className: "text-red-500", children: "*" })
284
+ ]
285
+ }
286
+ ),
287
+ field.description && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: field.description }),
288
+ /* @__PURE__ */ jsx(
289
+ "input",
290
+ {
291
+ id: `${fieldIdPrefix}-field-${field.name}`,
292
+ type: "text",
293
+ value: formData[field.name] || "",
294
+ onChange: (e) => setFormData((prev) => ({
295
+ ...prev,
296
+ [field.name]: e.target.value
297
+ })),
298
+ className: "w-full px-3 py-2 text-sm bg-muted rounded-lg border",
299
+ placeholder: field.type === "array" ? '["id1", "id2"]' : `${field.name}...`
300
+ }
301
+ )
302
+ ] }, field.name)) })
303
+ ] }),
304
+ job.dispatchable && !schemaFields && /* @__PURE__ */ jsx("div", { className: "bg-green-50 dark:bg-green-950/30 border border-green-200 dark:border-green-900 rounded-lg p-4", children: /* @__PURE__ */ jsx("p", { className: "text-sm text-green-700 dark:text-green-300", children: t("queue.dispatch.noInputNeeded") }) })
305
+ ] }) }),
306
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4 border-t bg-muted/30", children: [
224
307
  /* @__PURE__ */ jsx(
225
- "textarea",
308
+ "button",
226
309
  {
227
- value: jsonData,
228
- onChange: (e) => {
229
- setJsonData(e.target.value);
230
- validateJson(e.target.value);
231
- },
232
- className: cn(
233
- "w-full h-32 px-3 py-2 text-sm font-mono bg-muted rounded-lg border resize-none",
234
- jsonError && "border-red-500"
235
- ),
236
- placeholder: '{"rotaId": "..."}'
310
+ onClick: onClose,
311
+ "data-testid": "dispatch-cancel",
312
+ className: "px-4 py-2 text-sm font-medium rounded-lg hover:bg-muted transition-colors",
313
+ children: t("common.cancel")
237
314
  }
238
315
  ),
239
- jsonError && /* @__PURE__ */ jsxs("p", { className: "text-xs text-red-500 flex items-center gap-1", children: [
240
- /* @__PURE__ */ jsx(AlertCircle, { className: "h-3 w-3" }),
241
- jsonError
242
- ] })
243
- ] }) : /* @__PURE__ */ jsx("div", { className: "space-y-3", children: schemaFields?.map((field) => /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
244
- /* @__PURE__ */ jsxs("label", { className: "text-sm font-medium flex items-center gap-1", children: [
245
- field.name,
246
- field.required && /* @__PURE__ */ jsx("span", { className: "text-red-500", children: "*" })
247
- ] }),
248
- field.description && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: field.description }),
249
- /* @__PURE__ */ jsx(
250
- "input",
316
+ job.dispatchable && /* @__PURE__ */ jsxs(
317
+ "button",
251
318
  {
252
- type: "text",
253
- value: formData[field.name] || "",
254
- onChange: (e) => setFormData((prev) => ({
255
- ...prev,
256
- [field.name]: e.target.value
257
- })),
258
- className: "w-full px-3 py-2 text-sm bg-muted rounded-lg border",
259
- placeholder: field.type === "array" ? '["id1", "id2"]' : `${field.name}...`
319
+ onClick: handleDispatch,
320
+ disabled: dispatching,
321
+ "data-testid": "dispatch-execute",
322
+ className: "inline-flex items-center gap-2 px-4 py-2 text-sm font-medium bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors disabled:opacity-50",
323
+ children: [
324
+ dispatching ? /* @__PURE__ */ jsx(RefreshCw, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ jsx(Play, { className: "h-4 w-4" }),
325
+ t("queue.dispatch.executeNow")
326
+ ]
260
327
  }
261
328
  )
262
- ] }, field.name)) })
263
- ] }),
264
- job.dispatchable && !schemaFields && /* @__PURE__ */ jsx("div", { className: "bg-green-50 dark:bg-green-950/30 border border-green-200 dark:border-green-900 rounded-lg p-4", children: /* @__PURE__ */ jsx("p", { className: "text-sm text-green-700 dark:text-green-300", children: t("queue.dispatch.noInputNeeded") }) })
265
- ] }) }),
266
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4 border-t bg-muted/30", children: [
267
- /* @__PURE__ */ jsx(
268
- "button",
269
- {
270
- onClick: onClose,
271
- "data-testid": "dispatch-cancel",
272
- className: "px-4 py-2 text-sm font-medium rounded-lg hover:bg-muted transition-colors",
273
- children: t("common.cancel")
274
- }
275
- ),
276
- job.dispatchable && /* @__PURE__ */ jsxs(
277
- "button",
278
- {
279
- onClick: handleDispatch,
280
- disabled: dispatching,
281
- "data-testid": "dispatch-execute",
282
- className: "inline-flex items-center gap-2 px-4 py-2 text-sm font-medium bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors disabled:opacity-50",
283
- children: [
284
- dispatching ? /* @__PURE__ */ jsx(RefreshCw, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ jsx(Play, { className: "h-4 w-4" }),
285
- t("queue.dispatch.executeNow")
286
- ]
287
- }
288
- )
289
- ] })
290
- ] })
329
+ ] })
330
+ ]
331
+ }
332
+ )
291
333
  ] });
292
334
  }
293
335
  export {