@telamonjs/ui 1.0.4 → 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 +38 -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 +45 -77
- 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/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 +20 -2
- package/dist/queue/components/QueueTabbedDashboard.js +26 -3
- 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 +3 -2
- package/dist/queue/components/tabs/TempoRealTab.js +2 -2
- 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 +1 -1
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { TimePicker } from "../../components/forms/TimePicker.js";
|
|
12
12
|
import { WizardForm } from "../../components/forms/WizardForm.js";
|
|
13
13
|
import { getFieldAccessibilityAttrs } from "../../utils/test-ids.js";
|
|
14
|
+
import { resolveMask } from "../mask-presets.js";
|
|
14
15
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
15
16
|
var RichTextRenderer = {
|
|
16
17
|
render: ({ field, t }) => {
|
|
@@ -183,11 +184,8 @@ var RangeRenderer = {
|
|
|
183
184
|
] });
|
|
184
185
|
}
|
|
185
186
|
};
|
|
186
|
-
var TEL_MASK_LANDLINE = "(__) ____-____";
|
|
187
|
-
var TEL_MASK_MOBILE = "(__) _____-____";
|
|
188
187
|
var MASK_REPLACEMENT = { _: /\d/ };
|
|
189
188
|
var digitsOf = (raw) => raw.replace(/\D/g, "");
|
|
190
|
-
var telMaskFor = (digitCount) => digitCount > 10 ? TEL_MASK_MOBILE : TEL_MASK_LANDLINE;
|
|
191
189
|
function caretAfterDigit(text, n) {
|
|
192
190
|
if (n <= 0) return 0;
|
|
193
191
|
let seen = 0;
|
|
@@ -247,7 +245,7 @@ var MaskedRenderer = {
|
|
|
247
245
|
error: field.error,
|
|
248
246
|
description: field.description
|
|
249
247
|
});
|
|
250
|
-
const maskFor = (digits) => field.maskType
|
|
248
|
+
const maskFor = (digits) => resolveMask(field.maskType, field.mask, digits.length);
|
|
251
249
|
const value = String(field.value ?? "");
|
|
252
250
|
return /* @__PURE__ */ jsx(
|
|
253
251
|
MaskedInput,
|
|
@@ -23,7 +23,7 @@ var TextareaRenderer = {
|
|
|
23
23
|
onBlur: field.onBlur,
|
|
24
24
|
ref: field.ref,
|
|
25
25
|
placeholder: field.placeholder || t("form.enterText", { label: field.label.toLowerCase() }),
|
|
26
|
-
rows: 4,
|
|
26
|
+
rows: field.rows ?? 4,
|
|
27
27
|
readOnly: field.readOnly,
|
|
28
28
|
autoFocus: field.focus,
|
|
29
29
|
required: field.required
|
|
@@ -20,11 +20,26 @@ function useCrudMutations({
|
|
|
20
20
|
);
|
|
21
21
|
}
|
|
22
22
|
const invalidateQueries = (invalidates, id) => {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const keys = invalidates.map(
|
|
24
|
+
(keyOrFn) => typeof keyOrFn === "function" ? keyOrFn(id) : keyOrFn
|
|
25
|
+
);
|
|
26
|
+
for (const key of keys) {
|
|
27
|
+
void queryClient.invalidateQueries({ queryKey: key }).catch(() => void 0);
|
|
28
|
+
}
|
|
29
|
+
const cache = queryClient.getQueryCache();
|
|
30
|
+
const firstAttemptPending = () => keys.some(
|
|
31
|
+
(key) => cache.findAll({ queryKey: key }).some(
|
|
32
|
+
(q) => q.state.fetchStatus === "fetching" && q.state.fetchFailureCount === 0
|
|
33
|
+
)
|
|
34
|
+
);
|
|
35
|
+
if (!firstAttemptPending()) return Promise.resolve();
|
|
36
|
+
return new Promise((resolve) => {
|
|
37
|
+
const unsubscribe = cache.subscribe(() => {
|
|
38
|
+
if (firstAttemptPending()) return;
|
|
39
|
+
unsubscribe();
|
|
40
|
+
resolve();
|
|
41
|
+
});
|
|
26
42
|
});
|
|
27
|
-
void Promise.all(invalidationPromises).catch(() => void 0);
|
|
28
43
|
};
|
|
29
44
|
const createMutation = useMutation({
|
|
30
45
|
meta: LIB_QUERY_META,
|
|
@@ -34,14 +49,13 @@ function useCrudMutations({
|
|
|
34
49
|
}
|
|
35
50
|
return await mutations.create.mutationFn(data);
|
|
36
51
|
},
|
|
37
|
-
onSuccess: (result, variables) => {
|
|
38
|
-
|
|
39
|
-
invalidateQueries(mutations.create.invalidates);
|
|
40
|
-
}
|
|
52
|
+
onSuccess: async (result, variables) => {
|
|
53
|
+
const listRefetched = mutations.create?.invalidates ? invalidateQueries(mutations.create.invalidates) : void 0;
|
|
41
54
|
mutations.create?.onSuccess?.(result, variables);
|
|
42
55
|
if (result?.success && result?.message) {
|
|
43
56
|
toast.success(result.message);
|
|
44
57
|
}
|
|
58
|
+
await listRefetched;
|
|
45
59
|
},
|
|
46
60
|
onError: (error, variables) => {
|
|
47
61
|
mutations.create?.onError?.(error, variables);
|
|
@@ -57,14 +71,13 @@ function useCrudMutations({
|
|
|
57
71
|
}
|
|
58
72
|
return await mutations.update.mutationFn(variables);
|
|
59
73
|
},
|
|
60
|
-
onSuccess: (result, variables) => {
|
|
61
|
-
|
|
62
|
-
invalidateQueries(mutations.update.invalidates, variables.id);
|
|
63
|
-
}
|
|
74
|
+
onSuccess: async (result, variables) => {
|
|
75
|
+
const listRefetched = mutations.update?.invalidates ? invalidateQueries(mutations.update.invalidates, variables.id) : void 0;
|
|
64
76
|
mutations.update?.onSuccess?.(result, variables);
|
|
65
77
|
if (result?.success && result?.message) {
|
|
66
78
|
toast.success(result.message);
|
|
67
79
|
}
|
|
80
|
+
await listRefetched;
|
|
68
81
|
},
|
|
69
82
|
onError: (error, variables) => {
|
|
70
83
|
mutations.update?.onError?.(error, variables);
|
|
@@ -80,14 +93,13 @@ function useCrudMutations({
|
|
|
80
93
|
}
|
|
81
94
|
return await mutations.delete.mutationFn(variables);
|
|
82
95
|
},
|
|
83
|
-
onSuccess: (result, variables) => {
|
|
84
|
-
|
|
85
|
-
invalidateQueries(mutations.delete.invalidates, variables.id);
|
|
86
|
-
}
|
|
96
|
+
onSuccess: async (result, variables) => {
|
|
97
|
+
const listRefetched = mutations.delete?.invalidates ? invalidateQueries(mutations.delete.invalidates, variables.id) : void 0;
|
|
87
98
|
mutations.delete?.onSuccess?.(result, variables);
|
|
88
99
|
if (result?.success && result?.message) {
|
|
89
100
|
toast.success(result.message);
|
|
90
101
|
}
|
|
102
|
+
await listRefetched;
|
|
91
103
|
},
|
|
92
104
|
onError: (error, variables) => {
|
|
93
105
|
mutations.delete?.onError?.(error, variables);
|
package/dist/pages/ListPage.js
CHANGED
|
@@ -22,6 +22,7 @@ import { useListPageActions } from "./list-page/useListPageActions.js";
|
|
|
22
22
|
import { ListPageToolbar } from "./list-page/ListPageToolbar.js";
|
|
23
23
|
import { ListPageTable } from "./list-page/ListPageTable.js";
|
|
24
24
|
import { ListPageDialogs } from "./list-page/ListPageDialogs.js";
|
|
25
|
+
import { applyCrudPermissions } from "./list-page/apply-crud-permissions.js";
|
|
25
26
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
26
27
|
var logger = withComponent("ListPage");
|
|
27
28
|
function ListPage({
|
|
@@ -49,17 +50,16 @@ function ListPage({
|
|
|
49
50
|
embedded = false,
|
|
50
51
|
dialogUrlSync = true
|
|
51
52
|
}) {
|
|
52
|
-
const {
|
|
53
|
-
module,
|
|
54
|
-
list,
|
|
55
|
-
form,
|
|
56
|
-
mutations,
|
|
57
|
-
actionsConfig: rawActionsConfig,
|
|
58
|
-
dialogs
|
|
59
|
-
} = config;
|
|
53
|
+
const { module, list, form, mutations, actionsConfig: rawActionsConfig } = config;
|
|
60
54
|
const actionsDisabled = rawActionsConfig === false;
|
|
61
|
-
const
|
|
62
|
-
|
|
55
|
+
const { dialogs, actionsConfig } = useMemo(
|
|
56
|
+
() => applyCrudPermissions(
|
|
57
|
+
config,
|
|
58
|
+
actionsDisabled ? void 0 : rawActionsConfig
|
|
59
|
+
),
|
|
60
|
+
[config, actionsDisabled, rawActionsConfig]
|
|
61
|
+
);
|
|
62
|
+
const formSections = form?.sections ?? [];
|
|
63
63
|
const [filterOptions, setFilterOptions] = useState(
|
|
64
64
|
initialFilterOptions || {}
|
|
65
65
|
);
|
|
@@ -152,9 +152,9 @@ function ListPage({
|
|
|
152
152
|
() => ({
|
|
153
153
|
...customFilters,
|
|
154
154
|
...columnFilters,
|
|
155
|
-
...toolbarQueryFilters(toolbarFilters)
|
|
155
|
+
...toolbarQueryFilters(toolbarFilters, list.toolbar?.filters)
|
|
156
156
|
}),
|
|
157
|
-
[customFilters, columnFilters, toolbarFilters]
|
|
157
|
+
[customFilters, columnFilters, toolbarFilters, list.toolbar?.filters]
|
|
158
158
|
);
|
|
159
159
|
const isInfiniteScroll = list.infiniteScroll !== false;
|
|
160
160
|
const {
|
|
@@ -166,7 +166,8 @@ function ListPage({
|
|
|
166
166
|
effectiveTotal,
|
|
167
167
|
effectiveLoading,
|
|
168
168
|
effectiveIsFetching,
|
|
169
|
-
handleRefresh
|
|
169
|
+
handleRefresh,
|
|
170
|
+
paginationParams
|
|
170
171
|
} = useListPageData({
|
|
171
172
|
config,
|
|
172
173
|
page,
|
|
@@ -178,12 +179,18 @@ function ListPage({
|
|
|
178
179
|
disableAutoRefresh,
|
|
179
180
|
onRefreshAction
|
|
180
181
|
});
|
|
182
|
+
const listQuery = useMemo(
|
|
183
|
+
() => ({ search, filters: allFilters, sorting, params: paginationParams }),
|
|
184
|
+
[search, allFilters, sorting, paginationParams]
|
|
185
|
+
);
|
|
186
|
+
const resolvedToolbarContent = typeof toolbarContent === "function" ? toolbarContent(listQuery) : toolbarContent;
|
|
181
187
|
const rootRef = useRef(null);
|
|
182
188
|
const {
|
|
183
189
|
editDialogOpen,
|
|
184
190
|
setEditDialogOpen,
|
|
185
191
|
selectedEntityId,
|
|
186
192
|
selectedEditRow,
|
|
193
|
+
selectedViewRow,
|
|
187
194
|
viewDialogOpen,
|
|
188
195
|
setViewDialogOpen,
|
|
189
196
|
selectedViewEntityId,
|
|
@@ -253,7 +260,7 @@ function ListPage({
|
|
|
253
260
|
{
|
|
254
261
|
list,
|
|
255
262
|
toolbarPrepend,
|
|
256
|
-
toolbarContent,
|
|
263
|
+
toolbarContent: resolvedToolbarContent,
|
|
257
264
|
filtersPanel,
|
|
258
265
|
activeFilters,
|
|
259
266
|
onClearFilters,
|
|
@@ -308,12 +315,14 @@ function ListPage({
|
|
|
308
315
|
dialogs,
|
|
309
316
|
mutations,
|
|
310
317
|
form,
|
|
318
|
+
permissions: config.permissions,
|
|
311
319
|
formSections,
|
|
312
320
|
actionsConfig,
|
|
313
321
|
editDialogOpen,
|
|
314
322
|
setEditDialogOpen,
|
|
315
323
|
selectedEntityId,
|
|
316
324
|
selectedEditRow,
|
|
325
|
+
selectedViewRow,
|
|
317
326
|
fetchActionWrapper,
|
|
318
327
|
updateSubmitValues,
|
|
319
328
|
handleEditDialogSuccess,
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { FormSection, FormActionResult } from '../../components/forms/AdminForm';
|
|
2
2
|
import type { DataTableActionsConfig } from '../../types/actions';
|
|
3
|
-
import type { CrudConfigWithAnyForm, DialogsConfig, FormConfig } from '../../types/crud';
|
|
3
|
+
import type { CrudConfigWithAnyForm, CrudPermissions, DialogsConfig, FormConfig } from '../../types/crud';
|
|
4
4
|
interface ListPageDialogsProps<TData> {
|
|
5
5
|
dialogs: DialogsConfig<TData> | undefined;
|
|
6
6
|
mutations: CrudConfigWithAnyForm<TData>['mutations'];
|
|
7
|
-
|
|
7
|
+
/** Undefined for a read-only list (create/edit dialogs are already dropped) */
|
|
8
|
+
form: FormConfig | undefined;
|
|
9
|
+
/** `config.permissions` (section saving in the portal view dialog) */
|
|
10
|
+
permissions?: CrudPermissions;
|
|
8
11
|
/** form.sections normalized to an array (existing runtime contract) */
|
|
9
12
|
formSections: FormSection[];
|
|
10
13
|
/** Normalized actionsConfig (false already mapped to undefined) */
|
|
@@ -20,6 +23,8 @@ interface ListPageDialogsProps<TData> {
|
|
|
20
23
|
viewDialogOpen: boolean;
|
|
21
24
|
setViewDialogOpen: (open: boolean) => void;
|
|
22
25
|
selectedViewEntityId: string | null;
|
|
26
|
+
/** List row behind the view dialog (undefined on a deep link outside the loaded page) */
|
|
27
|
+
selectedViewRow?: TData;
|
|
23
28
|
handleViewDialogEdit: () => void;
|
|
24
29
|
handleViewDialogDelete: () => Promise<void>;
|
|
25
30
|
createDialogOpen: boolean;
|
|
@@ -35,5 +40,5 @@ interface ListPageDialogsProps<TData> {
|
|
|
35
40
|
*
|
|
36
41
|
* @internal Extracted from ListPage during the god-component decomposition.
|
|
37
42
|
*/
|
|
38
|
-
export declare function ListPageDialogs<TData>({ dialogs, mutations, form, formSections, actionsConfig, editDialogOpen, setEditDialogOpen, selectedEntityId, selectedEditRow, fetchActionWrapper, updateSubmitValues, handleEditDialogSuccess, viewDialogOpen, setViewDialogOpen, selectedViewEntityId, handleViewDialogEdit, handleViewDialogDelete, createDialogOpen, setCreateDialogOpen, createSubmitValues, handleRefresh, }: ListPageDialogsProps<TData>): import("react").JSX.Element;
|
|
43
|
+
export declare function ListPageDialogs<TData>({ dialogs, mutations, form, permissions, formSections, actionsConfig, editDialogOpen, setEditDialogOpen, selectedEntityId, selectedEditRow, fetchActionWrapper, updateSubmitValues, handleEditDialogSuccess, viewDialogOpen, setViewDialogOpen, selectedViewEntityId, selectedViewRow, handleViewDialogEdit, handleViewDialogDelete, createDialogOpen, setCreateDialogOpen, createSubmitValues, handleRefresh, }: ListPageDialogsProps<TData>): import("react").JSX.Element;
|
|
39
44
|
export {};
|
|
@@ -7,6 +7,11 @@ import {
|
|
|
7
7
|
useState
|
|
8
8
|
} from "react";
|
|
9
9
|
import { CrudViewDialog } from "../../components/dialog/crud-view-dialog.js";
|
|
10
|
+
import {
|
|
11
|
+
actionEnabled,
|
|
12
|
+
actionGranted,
|
|
13
|
+
actionVisible
|
|
14
|
+
} from "../../components/data/action-access.js";
|
|
10
15
|
import { resolveDialogTitle } from "../../components/dialog/resolve-dialog-title.js";
|
|
11
16
|
import { withComponent } from "../../utils/logger.js";
|
|
12
17
|
import { useTelamonjsT, useText } from "../../i18n/use-t.js";
|
|
@@ -31,6 +36,7 @@ function ListPageDialogs({
|
|
|
31
36
|
dialogs,
|
|
32
37
|
mutations,
|
|
33
38
|
form,
|
|
39
|
+
permissions,
|
|
34
40
|
formSections,
|
|
35
41
|
actionsConfig,
|
|
36
42
|
editDialogOpen,
|
|
@@ -43,6 +49,7 @@ function ListPageDialogs({
|
|
|
43
49
|
viewDialogOpen,
|
|
44
50
|
setViewDialogOpen,
|
|
45
51
|
selectedViewEntityId,
|
|
52
|
+
selectedViewRow,
|
|
46
53
|
handleViewDialogEdit,
|
|
47
54
|
handleViewDialogDelete,
|
|
48
55
|
createDialogOpen,
|
|
@@ -69,6 +76,26 @@ function ListPageDialogs({
|
|
|
69
76
|
description: resolveItemText(confirmCfg.description) ?? t("list.deleteConfirmDescription")
|
|
70
77
|
} : void 0
|
|
71
78
|
};
|
|
79
|
+
const standard = actionsConfig?.standard;
|
|
80
|
+
const footerAction = (offered, action) => {
|
|
81
|
+
const cfg = typeof action === "object" ? action : void 0;
|
|
82
|
+
return {
|
|
83
|
+
offered: offered && actionGranted(
|
|
84
|
+
cfg?.permission,
|
|
85
|
+
actionsConfig?.userPermissions,
|
|
86
|
+
actionsConfig?.can
|
|
87
|
+
),
|
|
88
|
+
can: cfg ? (item) => {
|
|
89
|
+
const row = selectedViewRow ?? item;
|
|
90
|
+
return actionVisible(cfg, row) && actionEnabled(cfg, row);
|
|
91
|
+
} : void 0
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
const footerEdit = footerAction(
|
|
95
|
+
Boolean(dialogs?.edit) && standard?.edit !== false,
|
|
96
|
+
standard?.edit
|
|
97
|
+
);
|
|
98
|
+
const footerDelete = footerAction(Boolean(standard?.delete), standard?.delete);
|
|
72
99
|
return /* @__PURE__ */ jsxs(Suspense, { fallback: null, children: [
|
|
73
100
|
dialogs?.edit && mutations && editMounted && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
74
101
|
logger.debug("[ListPage] Rendering EditDialog", {
|
|
@@ -85,7 +112,7 @@ function ListPageDialogs({
|
|
|
85
112
|
fetchAction: fetchActionWrapper,
|
|
86
113
|
onSubmitValues: updateSubmitValues,
|
|
87
114
|
sections: formSections,
|
|
88
|
-
validation: form
|
|
115
|
+
validation: form?.validation,
|
|
89
116
|
title: resolveDialogTitle(dialogs.edit.title, text),
|
|
90
117
|
description: text(dialogs.edit.description),
|
|
91
118
|
renderHeader: dialogs.edit.renderHeader,
|
|
@@ -97,7 +124,7 @@ function ListPageDialogs({
|
|
|
97
124
|
dialogHeight: dialogs.edit.dialogHeight,
|
|
98
125
|
useTabs: dialogs.edit.useTabs,
|
|
99
126
|
lockedFields: dialogs.edit.lockedFields,
|
|
100
|
-
onFieldChange: form
|
|
127
|
+
onFieldChange: form?.onFieldChange,
|
|
101
128
|
onSuccess: handleEditDialogSuccess
|
|
102
129
|
}
|
|
103
130
|
)
|
|
@@ -105,13 +132,15 @@ function ListPageDialogs({
|
|
|
105
132
|
dialogs?.view && mutations && viewMounted && /* @__PURE__ */ jsx(
|
|
106
133
|
CrudViewDialog,
|
|
107
134
|
{
|
|
108
|
-
config: { dialogs, mutations, form },
|
|
135
|
+
config: { dialogs, mutations, form, permissions, actionsConfig },
|
|
109
136
|
id: selectedViewEntityId,
|
|
110
137
|
open: viewDialogOpen,
|
|
111
138
|
onOpenChange: setViewDialogOpen,
|
|
112
139
|
footer: {
|
|
113
|
-
onEdit:
|
|
114
|
-
|
|
140
|
+
onEdit: footerEdit.offered ? handleViewDialogEdit : void 0,
|
|
141
|
+
canEdit: footerEdit.can,
|
|
142
|
+
onDelete: footerDelete.offered ? handleViewDialogDelete : void 0,
|
|
143
|
+
canDelete: footerDelete.can,
|
|
115
144
|
...deleteViewProps
|
|
116
145
|
}
|
|
117
146
|
}
|
|
@@ -123,7 +152,7 @@ function ListPageDialogs({
|
|
|
123
152
|
onOpenChange: setCreateDialogOpen,
|
|
124
153
|
onSubmitValues: createSubmitValues,
|
|
125
154
|
sections: formSections,
|
|
126
|
-
validation: form
|
|
155
|
+
validation: form?.validation,
|
|
127
156
|
title: resolveDialogTitle(dialogs.create.title, text),
|
|
128
157
|
description: text(dialogs.create.description),
|
|
129
158
|
renderHeader: (
|
|
@@ -136,7 +165,7 @@ function ListPageDialogs({
|
|
|
136
165
|
dialogHeight: dialogs.create.dialogHeight,
|
|
137
166
|
useTabs: dialogs.create.useTabs,
|
|
138
167
|
defaultValues: dialogs.create.defaultValues,
|
|
139
|
-
onFieldChange: form
|
|
168
|
+
onFieldChange: form?.onFieldChange,
|
|
140
169
|
onSuccess: () => {
|
|
141
170
|
setCreateDialogOpen(false);
|
|
142
171
|
handleRefresh().catch(
|
|
@@ -74,16 +74,15 @@ function ListPageToolbar({
|
|
|
74
74
|
[list.enableExport, list.columns, text]
|
|
75
75
|
);
|
|
76
76
|
const moreFilters = (list.toolbar?.filters ?? []).map((f) => ({ f, more: f.options.filter((o) => o.more) })).filter((x) => x.more.length > 0);
|
|
77
|
-
const
|
|
77
|
+
const resetOf = (f) => f.allValue ?? f.options[0]?.value ?? "";
|
|
78
|
+
const valueOf = (f) => toolbarFilters[f.key] || f.defaultValue || resetOf(f);
|
|
78
79
|
const moreChips = moreFilters.flatMap(({ f, more }) => {
|
|
79
|
-
const active = more.find(
|
|
80
|
-
(o) => o.value === valueOf(f.key, f.defaultValue, f.options[0]?.value)
|
|
81
|
-
);
|
|
80
|
+
const active = more.find((o) => o.value === valueOf(f));
|
|
82
81
|
return active ? [
|
|
83
82
|
{
|
|
84
83
|
key: f.key,
|
|
85
84
|
label: `${text(f.label)}: ${text(active.label)}`,
|
|
86
|
-
onRemove: () => onFilterChange(f.key, f
|
|
85
|
+
onRemove: () => onFilterChange(f.key, resetOf(f))
|
|
87
86
|
}
|
|
88
87
|
] : [];
|
|
89
88
|
});
|
|
@@ -113,7 +112,7 @@ function ListPageToolbar({
|
|
|
113
112
|
TabToolbar.FilterSelect,
|
|
114
113
|
{
|
|
115
114
|
options: resolvedOptions,
|
|
116
|
-
value:
|
|
115
|
+
value: valueOf(filter),
|
|
117
116
|
onChange: (value) => onFilterChange(filter.key, value),
|
|
118
117
|
label: text(filter.label),
|
|
119
118
|
className: filter.className
|
|
@@ -124,9 +123,10 @@ function ListPageToolbar({
|
|
|
124
123
|
TabToolbar.FilterButtons,
|
|
125
124
|
{
|
|
126
125
|
options: resolvedOptions.filter((o) => !o.more),
|
|
127
|
-
value:
|
|
126
|
+
value: valueOf(filter),
|
|
128
127
|
onChange: (value) => onFilterChange(filter.key, value),
|
|
129
|
-
className: filter.className
|
|
128
|
+
className: filter.className,
|
|
129
|
+
allValue: filter.allValue
|
|
130
130
|
}
|
|
131
131
|
)
|
|
132
132
|
)
|
|
@@ -156,11 +156,7 @@ function ListPageToolbar({
|
|
|
156
156
|
...filtersContentProps,
|
|
157
157
|
children: [
|
|
158
158
|
moreFilters.map(({ f, more }) => {
|
|
159
|
-
const current = valueOf(
|
|
160
|
-
f.key,
|
|
161
|
-
f.defaultValue,
|
|
162
|
-
f.options[0]?.value
|
|
163
|
-
);
|
|
159
|
+
const current = valueOf(f);
|
|
164
160
|
return /* @__PURE__ */ jsxs("div", { className: "space-y-1.5", children: [
|
|
165
161
|
/* @__PURE__ */ jsx("div", { className: "text-xs font-medium text-muted-foreground", children: text(f.label) }),
|
|
166
162
|
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1.5", children: more.map((o) => /* @__PURE__ */ jsxs(
|
|
@@ -175,7 +171,7 @@ function ListPageToolbar({
|
|
|
175
171
|
),
|
|
176
172
|
onClick: () => onFilterChange(
|
|
177
173
|
f.key,
|
|
178
|
-
current === o.value ? f
|
|
174
|
+
current === o.value ? resetOf(f) : o.value
|
|
179
175
|
),
|
|
180
176
|
children: [
|
|
181
177
|
o.dot && /* @__PURE__ */ jsx(
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DataTableActionsConfig } from '../../types/actions';
|
|
2
|
+
import type { CrudConfigWithAnyForm, DialogsConfig } from '../../types/crud';
|
|
3
|
+
/**
|
|
4
|
+
* Applies `config.permissions` (and the absence of `config.form`) once, where
|
|
5
|
+
* every ListPage surface reads from:
|
|
6
|
+
*
|
|
7
|
+
* - no `form` drops `dialogs.create` / `dialogs.edit` (read-only list);
|
|
8
|
+
* - a denied create/edit/view drops `dialogs.<op>` — no "New" button, no row
|
|
9
|
+
* edit/view injection, no footer Edit, no `?create=1` / `?edit=` deep link;
|
|
10
|
+
* - the row view/edit/delete (configured, or injected by a dialog) inherit
|
|
11
|
+
* `permissions.<op>` unless they declare their own `permission`;
|
|
12
|
+
* - `permissions.can` becomes `actionsConfig.can` unless that one is set.
|
|
13
|
+
*
|
|
14
|
+
* With a form and without `config.permissions` both inputs come back untouched.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export declare function applyCrudPermissions<TData>(config: CrudConfigWithAnyForm<TData>, actionsConfig: DataTableActionsConfig<TData> | undefined): {
|
|
19
|
+
dialogs: DialogsConfig<TData> | undefined;
|
|
20
|
+
actionsConfig: DataTableActionsConfig<TData> | undefined;
|
|
21
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/pages/list-page/apply-crud-permissions.ts
|
|
2
|
+
import { crudGranted } from "../../components/data/action-access.js";
|
|
3
|
+
function applyCrudPermissions(config, actionsConfig) {
|
|
4
|
+
const { permissions, form, dialogs: allDialogs } = config;
|
|
5
|
+
const withForm = form || !allDialogs ? allDialogs : { ...allDialogs, create: void 0, edit: void 0 };
|
|
6
|
+
if (!permissions) return { dialogs: withForm, actionsConfig };
|
|
7
|
+
const allowed = (op) => crudGranted(config, op);
|
|
8
|
+
const dialogs = withForm && {
|
|
9
|
+
...withForm,
|
|
10
|
+
create: allowed("create") ? withForm.create : void 0,
|
|
11
|
+
edit: allowed("edit") ? withForm.edit : void 0,
|
|
12
|
+
view: allowed("view") ? withForm.view : void 0
|
|
13
|
+
};
|
|
14
|
+
const standard = { ...actionsConfig?.standard };
|
|
15
|
+
for (const op of ["view", "edit", "delete"]) {
|
|
16
|
+
const entry = standard[op];
|
|
17
|
+
const required = permissions[op];
|
|
18
|
+
const injected = op !== "delete" && Boolean(dialogs?.[op]);
|
|
19
|
+
if (!required || entry === false || !entry && !injected) continue;
|
|
20
|
+
const own = typeof entry === "object" ? entry : {};
|
|
21
|
+
standard[op] = { ...own, permission: own.permission ?? required };
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
dialogs,
|
|
25
|
+
actionsConfig: {
|
|
26
|
+
...actionsConfig,
|
|
27
|
+
standard,
|
|
28
|
+
can: actionsConfig?.can ?? permissions.can
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
applyCrudPermissions
|
|
34
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ComponentType, ReactNode } from 'react';
|
|
2
2
|
import type { CrudConfigWithAnyForm } from '../../types/crud';
|
|
3
|
+
import type { PaginationParams, SortField } from '../../types/pagination';
|
|
3
4
|
import type { ColumnFilterConfig } from '../../types/filters';
|
|
4
5
|
import type { BulkAction } from '../../data/BulkActionsToolbar';
|
|
5
6
|
/**
|
|
@@ -70,8 +71,12 @@ export interface ListPageProps<TData> {
|
|
|
70
71
|
errorFallback?: ReactNode;
|
|
71
72
|
/** Custom React content to render BEFORE search in the embedded TabToolbar (e.g. DateRange picker) */
|
|
72
73
|
toolbarPrepend?: ReactNode;
|
|
73
|
-
/**
|
|
74
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Custom React content to render inside the embedded TabToolbar (after filters, before Spacer).
|
|
76
|
+
* Pass a function to receive the list's current query (`ListQueryState`) — e.g. an export/PDF
|
|
77
|
+
* button that must fetch exactly what the list shows.
|
|
78
|
+
*/
|
|
79
|
+
toolbarContent?: ReactNode | ((state: ListQueryState) => ReactNode);
|
|
75
80
|
/**
|
|
76
81
|
* Second level of the toolbar: content of the "Filters" popover
|
|
77
82
|
* (selects of client, period…). The button shows how many `activeFilters`.
|
|
@@ -102,3 +107,17 @@ export interface ActiveFilterChip {
|
|
|
102
107
|
label: string;
|
|
103
108
|
onRemove: () => void;
|
|
104
109
|
}
|
|
110
|
+
/** Current query of a ListPage, handed to `toolbarContent` when it is a function */
|
|
111
|
+
export interface ListQueryState {
|
|
112
|
+
/** Search box value, as typed */
|
|
113
|
+
search: string;
|
|
114
|
+
/** Every active filter: toolbar filters (resets dropped), column filters and `urlFilters` */
|
|
115
|
+
filters: Record<string, unknown>;
|
|
116
|
+
/** Current sort */
|
|
117
|
+
sorting: SortField[];
|
|
118
|
+
/**
|
|
119
|
+
* The params the list passes to `query.queryFn` (debounced search). `page`/`pageSize` are the
|
|
120
|
+
* paginated view's; set your own when fetching everything for an export.
|
|
121
|
+
*/
|
|
122
|
+
params: PaginationParams;
|
|
123
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type UseInfiniteListQueryReturn } from '../../hooks/useInfiniteListQuery';
|
|
2
2
|
import type { CrudConfigWithAnyForm } from '../../types/crud';
|
|
3
|
-
import type { SortField } from '../../types/pagination';
|
|
3
|
+
import type { PaginationParams, SortField } from '../../types/pagination';
|
|
4
4
|
interface UseListPageDataParams<TData> {
|
|
5
5
|
config: CrudConfigWithAnyForm<TData>;
|
|
6
6
|
page: number;
|
|
@@ -37,6 +37,8 @@ interface UseListPageDataReturn<TData> {
|
|
|
37
37
|
effectiveIsFetching: boolean;
|
|
38
38
|
/** Refresh handler with cache revalidation */
|
|
39
39
|
handleRefresh: () => Promise<void>;
|
|
40
|
+
/** The params passed to `query.queryFn` (debounced search) */
|
|
41
|
+
paginationParams: PaginationParams;
|
|
40
42
|
}
|
|
41
43
|
/**
|
|
42
44
|
* useListPageData - Data fetching orchestration for ListPage (internal)
|
|
@@ -50,6 +50,7 @@ export declare function useListPageDialogs<TData>({ dialogs, mutations, actionsC
|
|
|
50
50
|
setEditDialogOpen: (open: boolean) => void;
|
|
51
51
|
selectedEntityId: string | null;
|
|
52
52
|
selectedEditRow: TData | undefined;
|
|
53
|
+
selectedViewRow: TData | undefined;
|
|
53
54
|
viewDialogOpen: boolean;
|
|
54
55
|
setViewDialogOpen: (open: boolean) => void;
|
|
55
56
|
selectedViewEntityId: string | null;
|
|
@@ -36,11 +36,19 @@ function useListPageDialogs({
|
|
|
36
36
|
const selectedViewEntityId = dialogState.type === "view" ? dialogState.id : null;
|
|
37
37
|
const editDialogOpen = dialogState.type === "edit";
|
|
38
38
|
const selectedEntityId = dialogState.type === "edit" ? dialogState.id : null;
|
|
39
|
-
const
|
|
40
|
-
() =>
|
|
41
|
-
(item) => String(item.id) ===
|
|
39
|
+
const rowById = useCallback(
|
|
40
|
+
(id) => id === null ? void 0 : data.find(
|
|
41
|
+
(item) => String(item.id) === id
|
|
42
42
|
),
|
|
43
|
-
[data
|
|
43
|
+
[data]
|
|
44
|
+
);
|
|
45
|
+
const selectedEditRow = useMemo(
|
|
46
|
+
() => rowById(selectedEntityId),
|
|
47
|
+
[rowById, selectedEntityId]
|
|
48
|
+
);
|
|
49
|
+
const selectedViewRow = useMemo(
|
|
50
|
+
() => rowById(selectedViewEntityId),
|
|
51
|
+
[rowById, selectedViewEntityId]
|
|
44
52
|
);
|
|
45
53
|
const createDialogOpen = dialogState.type === "create";
|
|
46
54
|
const setEditDialogOpen = useCallback(
|
|
@@ -161,6 +169,7 @@ function useListPageDialogs({
|
|
|
161
169
|
setEditDialogOpen,
|
|
162
170
|
selectedEntityId,
|
|
163
171
|
selectedEditRow,
|
|
172
|
+
selectedViewRow,
|
|
164
173
|
// View dialog
|
|
165
174
|
viewDialogOpen,
|
|
166
175
|
setViewDialogOpen,
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import type { ListConfig } from '../../types/crud';
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { ListConfig, ToolbarFilterConfig } from '../../types/crud';
|
|
2
|
+
/**
|
|
3
|
+
* A value of this filter that means "no filter": `''`, or its `allValue` when
|
|
4
|
+
* declared, else the legacy magic values `'todos'` / `'all'`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isFilterReset(filter: Pick<ToolbarFilterConfig, 'allValue'> | undefined, value: string | undefined): boolean;
|
|
7
|
+
/** Toolbar selection → query filters: drops the "no filter" values */
|
|
8
|
+
export declare function toolbarQueryFilters(filters: Record<string, string>, configs?: readonly ToolbarFilterConfig[]): Record<string, string>;
|
|
6
9
|
interface UseListPageToolbarParams<TData> {
|
|
7
10
|
list: ListConfig<TData>;
|
|
8
11
|
/** Global filter value from the Zustand datatable store */
|