@telamonjs/ui 1.0.3 → 1.1.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/CHANGELOG.md +53 -0
- package/dist/components/business/CalendarWithEvents.d.ts +7 -1
- package/dist/components/business/CalendarWithEvents.js +8 -9
- package/dist/components/cards/stat-card.js +22 -3
- package/dist/components/charts/BarChart.d.ts +12 -1
- package/dist/components/charts/BarChart.js +6 -1
- package/dist/components/crud/crud-field.js +1 -0
- package/dist/components/data/DataTableActions.js +89 -85
- package/dist/components/data/action-access.d.ts +22 -0
- package/dist/components/data/action-access.js +33 -0
- package/dist/components/data/report-table.d.ts +3 -1
- package/dist/components/data/report-table.js +2 -1
- package/dist/components/dialog/DialogHeaderContent.js +1 -1
- package/dist/components/dialog/confirm-action-dialog.d.ts +54 -0
- package/dist/components/dialog/confirm-action-dialog.js +182 -0
- package/dist/components/dialog/crud-view-dialog.d.ts +7 -3
- package/dist/components/dialog/crud-view-dialog.js +3 -2
- package/dist/components/dialog/view-dialog.d.ts +9 -1
- package/dist/components/dialog/view-dialog.js +8 -3
- package/dist/components/forms/BaseForm.js +4 -3
- package/dist/components/forms/WizardForm.js +3 -2
- package/dist/components/forms/ZustandForm.js +5 -4
- package/dist/components/forms/admin-form/field-group.js +5 -4
- package/dist/components/forms/admin-form/visibility.js +2 -0
- package/dist/components/forms/grid-classes.d.ts +4 -0
- package/dist/components/forms/grid-classes.js +40 -0
- package/dist/components/forms/validators/config-validator.js +2 -1
- package/dist/components/toolbar/TabToolbar.d.ts +6 -1
- package/dist/components/toolbar/TabToolbar.js +5 -3
- package/dist/exports/data-crud.d.ts +1 -1
- package/dist/exports/pages-dialogs.d.ts +3 -1
- package/dist/exports/pages-dialogs.js +2 -0
- package/dist/exports/types-constants.d.ts +2 -2
- package/dist/exports/types-constants.js +1 -1
- package/dist/field-system/mask-presets.d.ts +5 -0
- package/dist/field-system/mask-presets.js +18 -0
- package/dist/field-system/renderers/advanced-renderers.js +2 -4
- package/dist/field-system/renderers/textarea-renderers.js +1 -1
- package/dist/hooks/useCrudMutations.js +28 -16
- package/dist/pages/ListPage.js +23 -14
- package/dist/pages/list-page/ListPageDialogs.d.ts +8 -3
- package/dist/pages/list-page/ListPageDialogs.js +36 -7
- package/dist/pages/list-page/ListPageToolbar.js +10 -14
- package/dist/pages/list-page/apply-crud-permissions.d.ts +21 -0
- package/dist/pages/list-page/apply-crud-permissions.js +34 -0
- package/dist/pages/list-page/types.d.ts +21 -2
- package/dist/pages/list-page/useListPageData.d.ts +3 -1
- package/dist/pages/list-page/useListPageData.js +2 -1
- package/dist/pages/list-page/useListPageDialogs.d.ts +1 -0
- package/dist/pages/list-page/useListPageDialogs.js +13 -4
- package/dist/pages/list-page/useListPageToolbar.d.ts +8 -5
- package/dist/pages/list-page/useListPageToolbar.js +14 -10
- package/dist/queue/components/FailureGroupsModal.js +4 -3
- package/dist/queue/components/JobConfigDialog.js +9 -1
- package/dist/queue/components/JobDetailModal.js +3 -2
- package/dist/queue/components/JobDetailPage.js +10 -2
- package/dist/queue/components/JobEventModal.js +3 -2
- package/dist/queue/components/QueueTabbedDashboard.d.ts +25 -2
- package/dist/queue/components/QueueTabbedDashboard.js +37 -5
- package/dist/queue/components/QueuesTable.d.ts +3 -2
- package/dist/queue/components/QueuesTable.js +31 -27
- package/dist/queue/components/job-shared.d.ts +2 -0
- package/dist/queue/components/job-shared.js +2 -0
- package/dist/queue/components/jobs-history-modal/fullscreen-modal.js +3 -2
- package/dist/queue/components/jobs-history-modal/job-detail-modal.js +3 -2
- package/dist/queue/components/jobs-list-modal/job-row.js +3 -2
- package/dist/queue/components/labels-context.d.ts +31 -0
- package/dist/queue/components/labels-context.js +34 -0
- package/dist/queue/components/module-icon.d.ts +9 -0
- package/dist/queue/components/module-icon.js +14 -0
- package/dist/queue/components/tabs/ConfiguracaoTab.d.ts +2 -1
- package/dist/queue/components/tabs/ConfiguracaoTab.js +13 -9
- package/dist/queue/components/tabs/HistoricoTab.js +4 -3
- package/dist/queue/components/tabs/TempoRealTab.d.ts +8 -3
- package/dist/queue/components/tabs/TempoRealTab.js +13 -7
- package/dist/queue/hooks/use-queue-events-timeline.d.ts +19 -1
- package/dist/queue/hooks/use-queue-events-timeline.js +23 -3
- package/dist/server/pagination/factory.js +8 -1
- package/dist/server/pagination/types.d.ts +6 -0
- package/dist/server/pagination/utils.d.ts +13 -0
- package/dist/server/pagination/utils.js +27 -16
- package/dist/types/actions.d.ts +43 -14
- package/dist/types/crud.d.ts +47 -6
- package/dist/types/dialog-header.d.ts +2 -2
- package/dist/types/forms/admin-form.d.ts +8 -1
- package/dist/utils/with-scope.js +5 -3
- package/package.json +2 -2
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { I18nText } from '../../i18n/msg';
|
|
2
|
+
/**
|
|
3
|
+
* Presentation labels set on `QueueTabbedDashboard` (`moduleLabels`,
|
|
4
|
+
* `jobLabel`) plus the job contracts' display names, read from the stats
|
|
5
|
+
* query by the dashboard. Module keys and job names are Redis keys (no
|
|
6
|
+
* accents, no spaces); these let the UI show real names instead.
|
|
7
|
+
* @internal not exported — the public switches are the dashboard props.
|
|
8
|
+
*/
|
|
9
|
+
export interface QueueLabels {
|
|
10
|
+
/** Module key → group title. Its key order is also the group order. */
|
|
11
|
+
moduleLabels?: Record<string, I18nText>;
|
|
12
|
+
/** Job name → label; `undefined` falls back to the display name. */
|
|
13
|
+
jobLabel?: (jobName: string) => I18nText | undefined;
|
|
14
|
+
/** Job name → the contract's `displayName`, as served by the stats endpoint. */
|
|
15
|
+
displayNames?: Readonly<Record<string, string>>;
|
|
16
|
+
}
|
|
17
|
+
export declare const QueueLabelsContext: import("react").Context<QueueLabels>;
|
|
18
|
+
export interface QueueLabelResolvers {
|
|
19
|
+
/** `jobLabel` override → contract display name → `formatQueueName`. */
|
|
20
|
+
jobLabel: (jobName: string, displayName?: string) => string;
|
|
21
|
+
/** The `moduleLabels` entry, or `undefined` (render the raw key). */
|
|
22
|
+
moduleLabel: (module: string) => string | undefined;
|
|
23
|
+
/** `moduleLabels` key order first, then alphabetical by label. */
|
|
24
|
+
orderModules: (modules: string[]) => string[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Label resolvers for the queue dashboard. Outside `QueueTabbedDashboard`
|
|
28
|
+
* (standalone components, tests) every lookup falls back to the raw key /
|
|
29
|
+
* `formatQueueName`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function useQueueLabels(): QueueLabelResolvers;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/queue/components/labels-context.ts
|
|
4
|
+
import { createContext, useContext, useMemo } from "react";
|
|
5
|
+
import { useText } from "../../i18n/use-t.js";
|
|
6
|
+
import { formatQueueName } from "../lib/format.js";
|
|
7
|
+
var QueueLabelsContext = createContext({});
|
|
8
|
+
function useQueueLabels() {
|
|
9
|
+
const { moduleLabels, jobLabel, displayNames } = useContext(QueueLabelsContext);
|
|
10
|
+
const text = useText();
|
|
11
|
+
return useMemo(() => {
|
|
12
|
+
const moduleLabel = (module) => text(moduleLabels?.[module]);
|
|
13
|
+
const rank = new Map(Object.keys(moduleLabels ?? {}).map((m, i) => [m, i]));
|
|
14
|
+
const sortKey = (m) => moduleLabel(m) ?? m;
|
|
15
|
+
return {
|
|
16
|
+
jobLabel: (jobName, displayName) => {
|
|
17
|
+
const contract = displayName ?? displayNames?.[jobName];
|
|
18
|
+
return text(jobLabel?.(jobName)) ?? // The backend serves the raw name when the contract has none
|
|
19
|
+
(contract && contract !== jobName ? contract : formatQueueName(jobName));
|
|
20
|
+
},
|
|
21
|
+
moduleLabel,
|
|
22
|
+
orderModules: (modules) => [...modules].sort(
|
|
23
|
+
(a, b) => (
|
|
24
|
+
// Infinity - Infinity is NaN (falsy) → both unranked: compare labels
|
|
25
|
+
(rank.get(a) ?? Infinity) - (rank.get(b) ?? Infinity) || sortKey(a).localeCompare(sortKey(b))
|
|
26
|
+
)
|
|
27
|
+
)
|
|
28
|
+
};
|
|
29
|
+
}, [moduleLabels, jobLabel, displayNames, text]);
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
QueueLabelsContext,
|
|
33
|
+
useQueueLabels
|
|
34
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { IconComponent } from '../../types/menu';
|
|
3
|
+
/** A `moduleIcons` entry: an emoji/text, a rendered node, or an icon component (e.g. Lucide). */
|
|
4
|
+
export type QueueModuleIcon = ReactNode | IconComponent;
|
|
5
|
+
/** Renders a `moduleIcons` entry; components get the group-header icon size. */
|
|
6
|
+
export declare function ModuleIcon({ icon, className }: {
|
|
7
|
+
icon: QueueModuleIcon;
|
|
8
|
+
className?: string;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/queue/components/module-icon.tsx
|
|
2
|
+
import { isValidElement } from "react";
|
|
3
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
4
|
+
function ModuleIcon({ icon, className }) {
|
|
5
|
+
const isComponent = typeof icon === "function" || typeof icon === "object" && icon !== null && "$$typeof" in icon && !isValidElement(icon);
|
|
6
|
+
if (isComponent) {
|
|
7
|
+
const Icon = icon;
|
|
8
|
+
return /* @__PURE__ */ jsx(Icon, { className: className ?? "h-4 w-4", "aria-hidden": "true" });
|
|
9
|
+
}
|
|
10
|
+
return /* @__PURE__ */ jsx(Fragment, { children: icon });
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
ModuleIcon
|
|
14
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { type QueueModuleIcon } from '../module-icon';
|
|
2
3
|
interface ConfiguracaoTabProps {
|
|
3
|
-
moduleIcons?: Record<string,
|
|
4
|
+
moduleIcons?: Record<string, QueueModuleIcon>;
|
|
4
5
|
}
|
|
5
6
|
export default function ConfiguracaoTab({ moduleIcons: moduleIconsProp, }: ConfiguracaoTabProps): React.JSX.Element;
|
|
6
7
|
export {};
|
|
@@ -24,9 +24,10 @@ import {
|
|
|
24
24
|
useUpdateJobConfig
|
|
25
25
|
} from "../../hooks/index.js";
|
|
26
26
|
import JobConfigDialog from "../JobConfigDialog.js";
|
|
27
|
-
import { formatQueueName } from "../../lib/format.js";
|
|
28
27
|
import { useTelamonjsT } from "../../../i18n/use-t.js";
|
|
29
28
|
import { useQueueReadOnly } from "../read-only-context.js";
|
|
29
|
+
import { useQueueLabels } from "../labels-context.js";
|
|
30
|
+
import { ModuleIcon } from "../module-icon.js";
|
|
30
31
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
31
32
|
var defaultModuleIcons = {
|
|
32
33
|
alertas: "\u{1F6A8}",
|
|
@@ -56,6 +57,7 @@ function ConfiguracaoTab({
|
|
|
56
57
|
const t = useTelamonjsT();
|
|
57
58
|
const readOnly = useQueueReadOnly();
|
|
58
59
|
const icons = moduleIconsProp ?? defaultModuleIcons;
|
|
60
|
+
const { jobLabel, moduleLabel, orderModules } = useQueueLabels();
|
|
59
61
|
const { data: allJobs, isLoading } = useAllJobs();
|
|
60
62
|
const [searchQuery, setSearchQuery] = useState("");
|
|
61
63
|
const [expandedModules, setExpandedModules] = useState(/* @__PURE__ */ new Set());
|
|
@@ -92,8 +94,8 @@ function ConfiguracaoTab({
|
|
|
92
94
|
return grouped;
|
|
93
95
|
}, [filteredJobs]);
|
|
94
96
|
const sortedModules = useMemo(
|
|
95
|
-
() => Object.
|
|
96
|
-
[jobsByModule]
|
|
97
|
+
() => orderModules(Object.keys(jobsByModule)).map((m) => [m, jobsByModule[m]]),
|
|
98
|
+
[jobsByModule, orderModules]
|
|
97
99
|
);
|
|
98
100
|
const toggleModule = (module) => {
|
|
99
101
|
const newExpanded = new Set(expandedModules);
|
|
@@ -199,6 +201,7 @@ function ConfiguracaoTab({
|
|
|
199
201
|
const isExpanded = expandedModules.has(module);
|
|
200
202
|
const moduleStats = getModuleStats(moduleJobs);
|
|
201
203
|
const moduleIcon = icons[module] || "\u{1F4E6}";
|
|
204
|
+
const label = moduleLabel(module);
|
|
202
205
|
const isTogglingModule = togglingModules.has(module);
|
|
203
206
|
const allEnabled = moduleJobs.every((j) => j.enabled);
|
|
204
207
|
const allDisabled = moduleJobs.every((j) => !j.enabled);
|
|
@@ -212,8 +215,8 @@ function ConfiguracaoTab({
|
|
|
212
215
|
className: "flex flex-1 items-center gap-2",
|
|
213
216
|
children: [
|
|
214
217
|
isExpanded ? /* @__PURE__ */ jsx(ChevronDown, { className: "text-muted-foreground h-4 w-4" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "text-muted-foreground h-4 w-4" }),
|
|
215
|
-
/* @__PURE__ */ jsx("span", { className: "text-base", children: moduleIcon }),
|
|
216
|
-
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium capitalize", children: module }),
|
|
218
|
+
/* @__PURE__ */ jsx("span", { className: "text-base", children: /* @__PURE__ */ jsx(ModuleIcon, { icon: moduleIcon }) }),
|
|
219
|
+
/* @__PURE__ */ jsx("span", { className: cn("text-sm font-medium", !label && "capitalize"), children: label ?? module }),
|
|
217
220
|
/* @__PURE__ */ jsxs("span", { className: "text-muted-foreground text-xs", children: [
|
|
218
221
|
"\xB7 ",
|
|
219
222
|
moduleJobs.length
|
|
@@ -241,7 +244,7 @@ function ConfiguracaoTab({
|
|
|
241
244
|
disabled: isTogglingModule,
|
|
242
245
|
className: "hover:bg-muted rounded p-1 transition-colors",
|
|
243
246
|
title: t("queue.config.activateAll"),
|
|
244
|
-
"aria-label": t("queue.config.activateAllModule", { module }),
|
|
247
|
+
"aria-label": t("queue.config.activateAllModule", { module: label ?? module }),
|
|
245
248
|
children: /* @__PURE__ */ jsx(
|
|
246
249
|
Play,
|
|
247
250
|
{
|
|
@@ -260,7 +263,7 @@ function ConfiguracaoTab({
|
|
|
260
263
|
disabled: isTogglingModule,
|
|
261
264
|
className: "hover:bg-muted rounded p-1 transition-colors",
|
|
262
265
|
title: t("queue.config.deactivateAll"),
|
|
263
|
-
"aria-label": t("queue.config.deactivateAllModule", { module }),
|
|
266
|
+
"aria-label": t("queue.config.deactivateAllModule", { module: label ?? module }),
|
|
264
267
|
children: /* @__PURE__ */ jsx(
|
|
265
268
|
Pause,
|
|
266
269
|
{
|
|
@@ -277,6 +280,7 @@ function ConfiguracaoTab({
|
|
|
277
280
|
] }),
|
|
278
281
|
isExpanded && /* @__PURE__ */ jsx("div", { className: "bg-muted/70 dark:bg-muted/60 border-t", children: moduleJobs.sort((a, b) => a.jobName.localeCompare(b.jobName)).map((job) => {
|
|
279
282
|
const isToggling = togglingJobs.has(job.jobName);
|
|
283
|
+
const title = jobLabel(job.jobName);
|
|
280
284
|
return /* @__PURE__ */ jsxs(
|
|
281
285
|
"div",
|
|
282
286
|
{
|
|
@@ -301,7 +305,7 @@ function ConfiguracaoTab({
|
|
|
301
305
|
),
|
|
302
306
|
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
303
307
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
304
|
-
/* @__PURE__ */ jsx("span", { className: "truncate text-sm font-medium", children:
|
|
308
|
+
/* @__PURE__ */ jsx("span", { className: "truncate text-sm font-medium", children: title }),
|
|
305
309
|
job.orphan && /* @__PURE__ */ jsx(
|
|
306
310
|
Badge,
|
|
307
311
|
{
|
|
@@ -312,7 +316,7 @@ function ConfiguracaoTab({
|
|
|
312
316
|
}
|
|
313
317
|
)
|
|
314
318
|
] }),
|
|
315
|
-
/* @__PURE__ */ jsx("p", { className: "text-muted-foreground truncate text-xs", children: job.description
|
|
319
|
+
/* @__PURE__ */ jsx("p", { className: "text-muted-foreground truncate text-xs", children: job.description && job.description !== title ? job.description : job.jobName })
|
|
316
320
|
] })
|
|
317
321
|
] }),
|
|
318
322
|
/* @__PURE__ */ jsxs("div", { className: "ml-4 flex shrink-0 items-center gap-3", children: [
|
|
@@ -27,7 +27,7 @@ import { subHours } from "date-fns";
|
|
|
27
27
|
import { useQueueApi } from "../../api/provider.js";
|
|
28
28
|
import { useQueueHistoryAll, useCopyToClipboard } from "../../hooks/index.js";
|
|
29
29
|
import { TabToolbar } from "../../../components/toolbar/TabToolbar.js";
|
|
30
|
-
import {
|
|
30
|
+
import { useQueueLabels } from "../labels-context.js";
|
|
31
31
|
import { useLocale } from "next-intl";
|
|
32
32
|
import { useTelamonjsT } from "../../../i18n/use-t.js";
|
|
33
33
|
import { useQueueReadOnly } from "../read-only-context.js";
|
|
@@ -44,6 +44,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
44
44
|
function HistoricoTab() {
|
|
45
45
|
"use no memo";
|
|
46
46
|
const t = useTelamonjsT();
|
|
47
|
+
const { jobLabel } = useQueueLabels();
|
|
47
48
|
const readOnly = useQueueReadOnly();
|
|
48
49
|
const format = useFormat();
|
|
49
50
|
const locale = useLocale();
|
|
@@ -290,7 +291,7 @@ function HistoricoTab() {
|
|
|
290
291
|
onClick: () => setSelectedJob(job),
|
|
291
292
|
formatDate,
|
|
292
293
|
formatDuration: formatJobDuration,
|
|
293
|
-
formatQueueName,
|
|
294
|
+
formatQueueName: jobLabel,
|
|
294
295
|
truncateId
|
|
295
296
|
}
|
|
296
297
|
)
|
|
@@ -354,7 +355,7 @@ function HistoricoTab() {
|
|
|
354
355
|
onRemove: handleRemove,
|
|
355
356
|
formatDate,
|
|
356
357
|
formatDuration: formatJobDuration,
|
|
357
|
-
formatQueueName,
|
|
358
|
+
formatQueueName: jobLabel,
|
|
358
359
|
copyToClipboard,
|
|
359
360
|
copied,
|
|
360
361
|
renderValue
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { QueueModuleIcon } from '../module-icon';
|
|
2
3
|
interface TempoRealTabProps {
|
|
3
4
|
/** Enable SSE real-time updates (default: true) */
|
|
4
5
|
enableSSE?: boolean;
|
|
5
|
-
/** Module icons for the queues table (module name → emoji) */
|
|
6
|
-
moduleIcons?: Record<string,
|
|
6
|
+
/** Module icons for the queues table (module name → emoji, node or icon component) */
|
|
7
|
+
moduleIcons?: Record<string, QueueModuleIcon>;
|
|
8
|
+
/** This tab is the visible one — visited tabs stay mounted (default: true) */
|
|
9
|
+
active?: boolean;
|
|
10
|
+
/** Timeline poll interval in ms while SSE is down (default: 2000) */
|
|
11
|
+
pollInterval?: number;
|
|
7
12
|
}
|
|
8
|
-
export default function TempoRealTab({ enableSSE, moduleIcons, }: TempoRealTabProps): React.JSX.Element;
|
|
13
|
+
export default function TempoRealTab({ enableSSE, moduleIcons, active, pollInterval, }: TempoRealTabProps): React.JSX.Element;
|
|
9
14
|
export {};
|
|
@@ -38,7 +38,7 @@ import { Badge } from "../../../ui/badge.js";
|
|
|
38
38
|
import JobStatsCards from "../JobStatsCards.js";
|
|
39
39
|
import QueuesTable from "../QueuesTable.js";
|
|
40
40
|
import { TabToolbar } from "../../../components/toolbar/TabToolbar.js";
|
|
41
|
-
import {
|
|
41
|
+
import { useQueueLabels } from "../labels-context.js";
|
|
42
42
|
import { useTelamonjsT } from "../../../i18n/use-t.js";
|
|
43
43
|
import { useFormat, useTickingNow } from "../../../i18n/use-format.js";
|
|
44
44
|
import { actionDoneMessage } from "../../lib/action-message.js";
|
|
@@ -217,7 +217,7 @@ var JobRow = React.memo(({ job, isSelected, onClick }) => {
|
|
|
217
217
|
const duration = formatDuration(job.processedOn, job.finishedOn, locale);
|
|
218
218
|
const relativeTs = job.finishedOn || job.processedOn || job.timestamp;
|
|
219
219
|
const timeAgo = relativeTs ? format.relative(relativeTs, now) : "\u2014";
|
|
220
|
-
const queueDisplay =
|
|
220
|
+
const queueDisplay = useQueueLabels().jobLabel(job.queueName);
|
|
221
221
|
const StatusIcon = job.status === "active" ? Clock : job.status === "completed" ? CheckCircle : AlertCircle;
|
|
222
222
|
return /* @__PURE__ */ jsxs(
|
|
223
223
|
"div",
|
|
@@ -391,7 +391,9 @@ var JobDetailPanel = React.memo(function JobDetailPanel2({
|
|
|
391
391
|
});
|
|
392
392
|
function TempoRealTab({
|
|
393
393
|
enableSSE = true,
|
|
394
|
-
moduleIcons
|
|
394
|
+
moduleIcons,
|
|
395
|
+
active = true,
|
|
396
|
+
pollInterval
|
|
395
397
|
}) {
|
|
396
398
|
"use no memo";
|
|
397
399
|
const t = useTelamonjsT();
|
|
@@ -408,7 +410,11 @@ function TempoRealTab({
|
|
|
408
410
|
isError,
|
|
409
411
|
isFetching,
|
|
410
412
|
refetch: refetchTimeline
|
|
411
|
-
} = useQueueEventsTimeline(
|
|
413
|
+
} = useQueueEventsTimeline({
|
|
414
|
+
sseConnected: sseStatus === "connected",
|
|
415
|
+
active,
|
|
416
|
+
pollInterval
|
|
417
|
+
});
|
|
412
418
|
const handleQueueAction = useCallback(
|
|
413
419
|
async (action) => {
|
|
414
420
|
try {
|
|
@@ -448,13 +454,13 @@ function TempoRealTab({
|
|
|
448
454
|
const search = deferredSearch.toLowerCase();
|
|
449
455
|
return job.name.toLowerCase().includes(search) || job.queueName.toLowerCase().includes(search);
|
|
450
456
|
}) : allJobs;
|
|
451
|
-
let
|
|
457
|
+
let active2 = 0, completed = 0, failed = 0;
|
|
452
458
|
for (const job of searchFiltered) {
|
|
453
|
-
if (job.status === "active")
|
|
459
|
+
if (job.status === "active") active2++;
|
|
454
460
|
else if (job.status === "completed") completed++;
|
|
455
461
|
else if (job.status === "failed") failed++;
|
|
456
462
|
}
|
|
457
|
-
return { total: searchFiltered.length, active, completed, failed };
|
|
463
|
+
return { total: searchFiltered.length, active: active2, completed, failed };
|
|
458
464
|
}, [allJobs, deferredSearch]);
|
|
459
465
|
const selectedJob = useMemo(() => {
|
|
460
466
|
if (!selectedJobId) return null;
|
|
@@ -8,6 +8,24 @@ import type { TimelineJob } from '../types';
|
|
|
8
8
|
export interface TimelineData {
|
|
9
9
|
jobs: TimelineJob[];
|
|
10
10
|
}
|
|
11
|
+
export interface QueueEventsTimelineOptions {
|
|
12
|
+
/** SSE stream is live (it already pushes events into this query's cache) */
|
|
13
|
+
sseConnected?: boolean;
|
|
14
|
+
/** The view showing the timeline is the active one (default: true) */
|
|
15
|
+
active?: boolean;
|
|
16
|
+
/** Poll interval in ms while SSE is down (default: 2000) */
|
|
17
|
+
pollInterval?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Poll interval for the timeline: none while hidden or on another tab, a
|
|
21
|
+
* 30s safety net while SSE is live, otherwise `pollInterval` (2s default).
|
|
22
|
+
*/
|
|
23
|
+
export declare function timelinePollInterval({ isVisible, active, sseConnected, pollInterval, }: {
|
|
24
|
+
isVisible: boolean;
|
|
25
|
+
active: boolean;
|
|
26
|
+
sseConnected: boolean;
|
|
27
|
+
pollInterval?: number;
|
|
28
|
+
}): number | false;
|
|
11
29
|
/**
|
|
12
30
|
* Hook for real-time job timeline events.
|
|
13
31
|
*
|
|
@@ -20,4 +38,4 @@ export interface TimelineData {
|
|
|
20
38
|
* const { data: jobs } = useQueueEventsTimeline()
|
|
21
39
|
* ```
|
|
22
40
|
*/
|
|
23
|
-
export declare function useQueueEventsTimeline(): import("@tanstack/react-query").UseQueryResult<TimelineData, Error>;
|
|
41
|
+
export declare function useQueueEventsTimeline({ sseConnected, active, pollInterval, }?: QueueEventsTimelineOptions): import("@tanstack/react-query").UseQueryResult<TimelineData, Error>;
|
|
@@ -3,7 +3,22 @@ import { useQuery } from "@tanstack/react-query";
|
|
|
3
3
|
import { useQueueApi } from "../api/provider.js";
|
|
4
4
|
import { usePageVisibility } from "../../hooks/usePageVisibility.js";
|
|
5
5
|
import { LIB_QUERY_META } from "../../utils/query-meta.js";
|
|
6
|
-
|
|
6
|
+
var SSE_SAFETY_NET_INTERVAL = 3e4;
|
|
7
|
+
var DEFAULT_POLL_INTERVAL = 2e3;
|
|
8
|
+
function timelinePollInterval({
|
|
9
|
+
isVisible,
|
|
10
|
+
active,
|
|
11
|
+
sseConnected,
|
|
12
|
+
pollInterval = DEFAULT_POLL_INTERVAL
|
|
13
|
+
}) {
|
|
14
|
+
if (!isVisible || !active) return false;
|
|
15
|
+
return sseConnected ? SSE_SAFETY_NET_INTERVAL : pollInterval;
|
|
16
|
+
}
|
|
17
|
+
function useQueueEventsTimeline({
|
|
18
|
+
sseConnected = false,
|
|
19
|
+
active = true,
|
|
20
|
+
pollInterval
|
|
21
|
+
} = {}) {
|
|
7
22
|
const api = useQueueApi();
|
|
8
23
|
const isVisible = usePageVisibility();
|
|
9
24
|
return useQuery({
|
|
@@ -94,10 +109,15 @@ function useQueueEventsTimeline() {
|
|
|
94
109
|
};
|
|
95
110
|
},
|
|
96
111
|
staleTime: 1e3,
|
|
97
|
-
|
|
98
|
-
|
|
112
|
+
refetchInterval: timelinePollInterval({
|
|
113
|
+
isVisible,
|
|
114
|
+
active,
|
|
115
|
+
sseConnected,
|
|
116
|
+
pollInterval
|
|
117
|
+
})
|
|
99
118
|
});
|
|
100
119
|
}
|
|
101
120
|
export {
|
|
121
|
+
timelinePollInterval,
|
|
102
122
|
useQueueEventsTimeline
|
|
103
123
|
};
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
buildSearchConditions,
|
|
11
11
|
buildWhereClause,
|
|
12
12
|
getFilterOptionsForField,
|
|
13
|
+
resolveSort,
|
|
13
14
|
sanitizePaginationParams
|
|
14
15
|
} from "./utils.js";
|
|
15
16
|
import { logger } from "../../utils/logger.js";
|
|
@@ -25,6 +26,7 @@ function createPaginationContext(context) {
|
|
|
25
26
|
select,
|
|
26
27
|
defaultOrderBy = "id",
|
|
27
28
|
defaultOrderDirection = "asc",
|
|
29
|
+
sortableFields,
|
|
28
30
|
visibility,
|
|
29
31
|
counts,
|
|
30
32
|
baseWhere,
|
|
@@ -79,7 +81,12 @@ function createPaginationContext(context) {
|
|
|
79
81
|
};
|
|
80
82
|
where = beforeQuery(queryParams, where);
|
|
81
83
|
}
|
|
82
|
-
const
|
|
84
|
+
const sort = resolveSort(sortBy, sortOrder, {
|
|
85
|
+
defaultOrderBy,
|
|
86
|
+
defaultOrderDirection,
|
|
87
|
+
sortableFields
|
|
88
|
+
});
|
|
89
|
+
const orderBy = buildOrderByClause(sort.sortBy, sort.sortOrder);
|
|
83
90
|
const includeClause = buildIncludeClause(include, counts);
|
|
84
91
|
const queryOptions = {
|
|
85
92
|
where,
|
|
@@ -55,6 +55,12 @@ export interface PaginatedServiceConfig<TModel extends string = string> {
|
|
|
55
55
|
select?: Record<string, boolean | Record<string, unknown>>;
|
|
56
56
|
defaultOrderBy?: string | string[];
|
|
57
57
|
defaultOrderDirection?: 'asc' | 'desc';
|
|
58
|
+
/**
|
|
59
|
+
* Fields the client may sort by (as sent in `sortBy`, e.g. `'customer.name'`).
|
|
60
|
+
* When set, any other `sortBy` is ignored and the default sort applies.
|
|
61
|
+
* When absent, any field is accepted.
|
|
62
|
+
*/
|
|
63
|
+
sortableFields?: string[];
|
|
58
64
|
visibility?: (user: AuthUser) => PrismaWhereClause;
|
|
59
65
|
counts?: string[];
|
|
60
66
|
baseWhere?: PrismaWhereClause;
|
|
@@ -20,6 +20,19 @@ export declare function buildFilterConditions(filters: Record<string, FilterValu
|
|
|
20
20
|
* Build complete where clause combining all conditions
|
|
21
21
|
*/
|
|
22
22
|
export declare function buildWhereClause(searchConditions: SearchCondition | undefined, filterConditions: PrismaWhereClause[], baseWhere?: PrismaWhereClause, visibilityWhere?: PrismaWhereClause): PrismaWhereClause;
|
|
23
|
+
/**
|
|
24
|
+
* Sanitize a client-supplied sort: an invalid direction becomes the default
|
|
25
|
+
* one, and with `sortableFields` set, fields outside it are dropped (an empty
|
|
26
|
+
* result falls back to the default sort).
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveSort(sortBy: string | string[] | SortField[], sortOrder: unknown, defaults: {
|
|
29
|
+
defaultOrderBy: string | string[];
|
|
30
|
+
defaultOrderDirection: 'asc' | 'desc';
|
|
31
|
+
sortableFields?: string[];
|
|
32
|
+
}): {
|
|
33
|
+
sortBy: string | string[] | SortField[];
|
|
34
|
+
sortOrder: 'asc' | 'desc';
|
|
35
|
+
};
|
|
23
36
|
/**
|
|
24
37
|
* Build orderBy clause from sortBy and sortOrder
|
|
25
38
|
*/
|
|
@@ -94,23 +94,33 @@ function buildWhereClause(searchConditions, filterConditions, baseWhere, visibil
|
|
|
94
94
|
conditions.push(searchConditions);
|
|
95
95
|
}
|
|
96
96
|
conditions.push(...filterConditions);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
97
|
+
const parts = [
|
|
98
|
+
conditions.length > 0 ? { AND: conditions } : void 0,
|
|
99
|
+
baseWhere,
|
|
100
|
+
visibilityWhere
|
|
101
|
+
].filter(
|
|
102
|
+
(part) => !!part && Object.keys(part).length > 0
|
|
103
|
+
);
|
|
104
|
+
if (parts.length === 0) return {};
|
|
105
|
+
return parts.length === 1 ? parts[0] : { AND: parts };
|
|
106
|
+
}
|
|
107
|
+
var isSortOrder = (value) => value === "asc" || value === "desc";
|
|
108
|
+
function resolveSort(sortBy, sortOrder, defaults) {
|
|
109
|
+
const { defaultOrderBy, defaultOrderDirection, sortableFields } = defaults;
|
|
110
|
+
const fallback = { sortBy: defaultOrderBy, sortOrder: defaultOrderDirection };
|
|
111
|
+
const allowed = (field) => !sortableFields || sortableFields.includes(field);
|
|
112
|
+
const order = isSortOrder(sortOrder) ? sortOrder : defaultOrderDirection;
|
|
113
|
+
if (sortBy === defaultOrderBy) return { sortBy, sortOrder: order };
|
|
114
|
+
if (typeof sortBy === "string") {
|
|
115
|
+
return allowed(sortBy) ? { sortBy, sortOrder: order } : fallback;
|
|
112
116
|
}
|
|
113
|
-
|
|
117
|
+
const fields = sortBy.filter(
|
|
118
|
+
(s) => !!s && typeof s === "object" && typeof s.field === "string" && allowed(s.field)
|
|
119
|
+
).map((s) => ({
|
|
120
|
+
field: s.field,
|
|
121
|
+
order: isSortOrder(s.order) ? s.order : defaultOrderDirection
|
|
122
|
+
}));
|
|
123
|
+
return fields.length > 0 ? { sortBy: fields, sortOrder: order } : fallback;
|
|
114
124
|
}
|
|
115
125
|
function buildOrderByClause(sortBy, sortOrder) {
|
|
116
126
|
if (!sortBy) {
|
|
@@ -193,5 +203,6 @@ export {
|
|
|
193
203
|
buildSearchConditions,
|
|
194
204
|
buildWhereClause,
|
|
195
205
|
getFilterOptionsForField,
|
|
206
|
+
resolveSort,
|
|
196
207
|
sanitizePaginationParams
|
|
197
208
|
};
|
package/dist/types/actions.d.ts
CHANGED
|
@@ -28,15 +28,34 @@ export interface ConfirmDialogConfig<TData = any> {
|
|
|
28
28
|
cancelText?: I18nText;
|
|
29
29
|
/** Dialog variant */
|
|
30
30
|
variant?: 'default' | 'destructive';
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Fields asked before confirming (a reason, a note…). Their values reach the
|
|
33
|
+
* action as the second argument of `handler`/`onClick`: `(row, { inputs })`.
|
|
34
|
+
*/
|
|
35
|
+
inputs?: ConfirmDialogInput[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A field of a confirmation dialog (`ConfirmDialogConfig.inputs`,
|
|
39
|
+
* `ConfirmActionDialog`'s `inputs`)
|
|
40
|
+
*/
|
|
41
|
+
export interface ConfirmDialogInput {
|
|
42
|
+
/** Key of the value in `inputs` */
|
|
43
|
+
name: string;
|
|
44
|
+
label: I18nText;
|
|
45
|
+
type: 'text' | 'textarea' | 'select';
|
|
46
|
+
/** Confirming is blocked while it is empty */
|
|
47
|
+
required?: boolean;
|
|
48
|
+
/** Choices of a `select` (value = label) */
|
|
49
|
+
options?: string[];
|
|
50
|
+
defaultValue?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Second argument of an action's `handler`/`onClick`, passed when its
|
|
54
|
+
* `confirmDialog` declares `inputs`
|
|
55
|
+
*/
|
|
56
|
+
export interface ActionContext {
|
|
57
|
+
/** Values of `confirmDialog.inputs`, by `name` */
|
|
58
|
+
inputs: Record<string, string>;
|
|
40
59
|
}
|
|
41
60
|
/**
|
|
42
61
|
* Tooltip configuration for actions
|
|
@@ -69,17 +88,20 @@ export interface ActionConfig<TData = any> {
|
|
|
69
88
|
tooltip?: I18nText | TooltipConfig | ((row: TData) => string);
|
|
70
89
|
/** Navigation URL */
|
|
71
90
|
href?: string | ((row: TData) => string);
|
|
72
|
-
/** Direct click handler */
|
|
73
|
-
onClick?: (row: TData) => void | Promise<void>;
|
|
74
|
-
/** Async handler with result */
|
|
75
|
-
handler?: (row: TData) => Promise<unknown>;
|
|
91
|
+
/** Direct click handler (`ctx` only when `confirmDialog.inputs` is set) */
|
|
92
|
+
onClick?: (row: TData, ctx?: ActionContext) => void | Promise<void>;
|
|
93
|
+
/** Async handler with result (`ctx` only when `confirmDialog.inputs` is set) */
|
|
94
|
+
handler?: (row: TData, ctx?: ActionContext) => Promise<unknown>;
|
|
76
95
|
/** Confirmation dialog configuration */
|
|
77
96
|
confirmDialog?: boolean | ConfirmDialogConfig<TData>;
|
|
78
97
|
/** Called on successful action completion */
|
|
79
98
|
onSuccess?: (row: TData, result?: unknown) => void;
|
|
80
99
|
/** Called on action error */
|
|
81
100
|
onError?: (error: Error, row: TData) => void;
|
|
82
|
-
/**
|
|
101
|
+
/**
|
|
102
|
+
* Required permission(s) to show this action (any of them). Checked with
|
|
103
|
+
* `DataTableActionsConfig.can` when set, else against `userPermissions`.
|
|
104
|
+
*/
|
|
83
105
|
permission?: string | string[];
|
|
84
106
|
/** Success message to display (I18nText) */
|
|
85
107
|
successMessage?: I18nText | ((row: TData) => I18nText);
|
|
@@ -136,4 +158,11 @@ export interface DataTableActionsConfig<TData = any> {
|
|
|
136
158
|
onAfterAction?: (actionId: string, row: TData, result?: unknown) => void | Promise<void>;
|
|
137
159
|
/** Current user permissions for permission checking */
|
|
138
160
|
userPermissions?: string[];
|
|
161
|
+
/**
|
|
162
|
+
* Permission checker. When set it decides every `permission` instead of the
|
|
163
|
+
* exact lookup in `userPermissions`, so bypass roles and wildcards work, e.g.
|
|
164
|
+
* `can: perm => checker.can(user, perm)` with `createPermissionChecker` from
|
|
165
|
+
* `@telamonjs/permissions`.
|
|
166
|
+
*/
|
|
167
|
+
can?: (permission: string) => boolean;
|
|
139
168
|
}
|