@telamonjs/ui 1.2.1 → 1.3.1
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 +40 -0
- package/README.md +1 -1
- package/dist/components/data/DataTableActions.js +1 -0
- package/dist/components/data/action-access.d.ts +9 -2
- package/dist/components/data/action-access.js +10 -3
- package/dist/components/dialog/CrudDialogShell.d.ts +2 -0
- package/dist/components/dialog/CrudDialogShell.js +9 -7
- package/dist/components/dialog/DialogLoadingState.d.ts +16 -0
- package/dist/components/dialog/DialogLoadingState.js +16 -0
- package/dist/components/dialog/confirm-action-dialog.d.ts +12 -4
- package/dist/components/dialog/confirm-action-dialog.js +156 -82
- package/dist/components/dialog/create-dialog.js +1 -12
- package/dist/components/dialog/edit-dialog.js +5 -4
- package/dist/components/dialog/index.d.ts +1 -1
- package/dist/components/dialog/index.js +1 -2
- package/dist/components/dialog/view-dialog.js +5 -4
- package/dist/components/utilities/QueryErrorState.d.ts +47 -0
- package/dist/components/utilities/QueryErrorState.js +85 -0
- package/dist/data/DataTable.d.ts +2 -2
- package/dist/data/DataTable.js +2 -0
- package/dist/data/ExportMenu.d.ts +30 -3
- package/dist/data/ExportMenu.js +69 -5
- package/dist/data/datatable/TableToolbar.d.ts +3 -2
- package/dist/data/datatable/TableToolbar.js +30 -13
- package/dist/data/datatable/types.d.ts +9 -0
- package/dist/data/fetch-all-pages.d.ts +30 -0
- package/dist/data/fetch-all-pages.js +44 -0
- package/dist/exports/data-crud.d.ts +7 -3
- package/dist/exports/data-crud.js +4 -0
- package/dist/exports/types-constants.d.ts +2 -2
- package/dist/exports/types-constants.js +1 -1
- package/dist/i18n/messages/en/data.d.ts +3 -0
- package/dist/i18n/messages/en/data.js +3 -0
- package/dist/i18n/messages/en/index.d.ts +5 -0
- package/dist/i18n/messages/en/validation.d.ts +2 -0
- package/dist/i18n/messages/en/validation.js +2 -0
- package/dist/i18n/messages/es/data.d.ts +3 -0
- package/dist/i18n/messages/es/data.js +3 -0
- package/dist/i18n/messages/es/index.d.ts +5 -0
- package/dist/i18n/messages/es/validation.d.ts +2 -0
- package/dist/i18n/messages/es/validation.js +2 -0
- package/dist/i18n/messages/pt-BR/data.d.ts +3 -0
- package/dist/i18n/messages/pt-BR/data.js +3 -0
- package/dist/i18n/messages/pt-BR/index.d.ts +5 -0
- package/dist/i18n/messages/pt-BR/validation.d.ts +2 -0
- package/dist/i18n/messages/pt-BR/validation.js +2 -0
- package/dist/i18n/use-t.d.ts +5 -0
- package/dist/pages/ListPage.js +9 -13
- package/dist/pages/list-page/ListPageTable.d.ts +4 -2
- package/dist/pages/list-page/ListPageTable.js +3 -3
- package/dist/pages/list-page/ListPageToolbar.d.ts +4 -1
- package/dist/pages/list-page/ListPageToolbar.js +10 -4
- package/dist/pages/list-page/apply-crud-permissions.d.ts +4 -1
- package/dist/pages/list-page/apply-crud-permissions.js +20 -3
- package/dist/pages/list-page/types.d.ts +2 -16
- package/dist/pages/list-page/useListPageExport.d.ts +24 -0
- package/dist/pages/list-page/useListPageExport.js +54 -0
- package/dist/types/actions.d.ts +43 -4
- package/dist/types/crud.d.ts +48 -2
- package/package.json +1 -1
- package/dist/components/dialog/DialogErrorState.d.ts +0 -44
- package/dist/components/dialog/DialogErrorState.js +0 -57
|
@@ -15,6 +15,9 @@ export declare const data: {
|
|
|
15
15
|
noDataToExport: string;
|
|
16
16
|
exportSuccess: string;
|
|
17
17
|
exportError: string;
|
|
18
|
+
exportFetching: string;
|
|
19
|
+
exportCancelled: string;
|
|
20
|
+
exportTruncated: string;
|
|
18
21
|
scopeAll: string;
|
|
19
22
|
scopeSelected: string;
|
|
20
23
|
scopeCurrentPage: string;
|
|
@@ -16,6 +16,9 @@ var data = {
|
|
|
16
16
|
noDataToExport: "No data to export",
|
|
17
17
|
exportSuccess: "{format} exported successfully ({scope})",
|
|
18
18
|
exportError: "Error exporting data",
|
|
19
|
+
exportFetching: "Fetching records to export: {loaded, number} of {total, number}",
|
|
20
|
+
exportCancelled: "Export cancelled",
|
|
21
|
+
exportTruncated: "Exported the first {count, number} of {total, number} records (export limit)",
|
|
19
22
|
scopeAll: "all data",
|
|
20
23
|
scopeSelected: "{count, plural, one {# row selected} other {# rows selected}}",
|
|
21
24
|
scopeCurrentPage: "current page",
|
|
@@ -211,6 +211,9 @@ export declare const en: {
|
|
|
211
211
|
noDataToExport: string;
|
|
212
212
|
exportSuccess: string;
|
|
213
213
|
exportError: string;
|
|
214
|
+
exportFetching: string;
|
|
215
|
+
exportCancelled: string;
|
|
216
|
+
exportTruncated: string;
|
|
214
217
|
scopeAll: string;
|
|
215
218
|
scopeSelected: string;
|
|
216
219
|
scopeCurrentPage: string;
|
|
@@ -402,6 +405,8 @@ export declare const en: {
|
|
|
402
405
|
invalidOption: string;
|
|
403
406
|
tooSmallString: string;
|
|
404
407
|
tooBigString: string;
|
|
408
|
+
charactersMissing: string;
|
|
409
|
+
charactersOver: string;
|
|
405
410
|
tooSmallNumber: string;
|
|
406
411
|
tooBigNumber: string;
|
|
407
412
|
tooSmallArray: string;
|
|
@@ -9,6 +9,8 @@ var validation = {
|
|
|
9
9
|
invalidOption: "Invalid option",
|
|
10
10
|
tooSmallString: "{min, plural, one {At least # character} other {At least # characters}}",
|
|
11
11
|
tooBigString: "{max, plural, one {At most # character} other {At most # characters}}",
|
|
12
|
+
charactersMissing: "{count, plural, one {# more character needed} other {# more characters needed}}",
|
|
13
|
+
charactersOver: "{count, plural, one {# character too many} other {# characters too many}}",
|
|
12
14
|
tooSmallNumber: "Must be at least {min, number}",
|
|
13
15
|
tooBigNumber: "Must be at most {max, number}",
|
|
14
16
|
tooSmallArray: "{min, plural, one {Select at least # item} other {Select at least # items}}",
|
|
@@ -15,6 +15,9 @@ export declare const data: {
|
|
|
15
15
|
noDataToExport: string;
|
|
16
16
|
exportSuccess: string;
|
|
17
17
|
exportError: string;
|
|
18
|
+
exportFetching: string;
|
|
19
|
+
exportCancelled: string;
|
|
20
|
+
exportTruncated: string;
|
|
18
21
|
scopeAll: string;
|
|
19
22
|
scopeSelected: string;
|
|
20
23
|
scopeCurrentPage: string;
|
|
@@ -16,6 +16,9 @@ var data = {
|
|
|
16
16
|
noDataToExport: "Sin datos para exportar",
|
|
17
17
|
exportSuccess: "{format} exportado con \xE9xito ({scope})",
|
|
18
18
|
exportError: "Error al exportar datos",
|
|
19
|
+
exportFetching: "Buscando registros para exportar: {loaded, number} de {total, number}",
|
|
20
|
+
exportCancelled: "Exportaci\xF3n cancelada",
|
|
21
|
+
exportTruncated: "Se exportaron los primeros {count, number} de {total, number} registros (l\xEDmite de exportaci\xF3n)",
|
|
19
22
|
scopeAll: "todos los datos",
|
|
20
23
|
scopeSelected: "{count, plural, one {# fila seleccionada} other {# filas seleccionadas}}",
|
|
21
24
|
scopeCurrentPage: "p\xE1gina actual",
|
|
@@ -211,6 +211,9 @@ export declare const es: {
|
|
|
211
211
|
noDataToExport: string;
|
|
212
212
|
exportSuccess: string;
|
|
213
213
|
exportError: string;
|
|
214
|
+
exportFetching: string;
|
|
215
|
+
exportCancelled: string;
|
|
216
|
+
exportTruncated: string;
|
|
214
217
|
scopeAll: string;
|
|
215
218
|
scopeSelected: string;
|
|
216
219
|
scopeCurrentPage: string;
|
|
@@ -402,6 +405,8 @@ export declare const es: {
|
|
|
402
405
|
invalidOption: string;
|
|
403
406
|
tooSmallString: string;
|
|
404
407
|
tooBigString: string;
|
|
408
|
+
charactersMissing: string;
|
|
409
|
+
charactersOver: string;
|
|
405
410
|
tooSmallNumber: string;
|
|
406
411
|
tooBigNumber: string;
|
|
407
412
|
tooSmallArray: string;
|
|
@@ -9,6 +9,8 @@ var validation = {
|
|
|
9
9
|
invalidOption: "Opci\xF3n inv\xE1lida",
|
|
10
10
|
tooSmallString: "{min, plural, one {M\xEDnimo # car\xE1cter} other {M\xEDnimo # caracteres}}",
|
|
11
11
|
tooBigString: "{max, plural, one {M\xE1ximo # car\xE1cter} other {M\xE1ximo # caracteres}}",
|
|
12
|
+
charactersMissing: "{count, plural, one {Falta # car\xE1cter} other {Faltan # caracteres}}",
|
|
13
|
+
charactersOver: "{count, plural, one {# car\xE1cter de m\xE1s} other {# caracteres de m\xE1s}}",
|
|
12
14
|
tooSmallNumber: "Debe ser mayor o igual a {min, number}",
|
|
13
15
|
tooBigNumber: "Debe ser menor o igual a {max, number}",
|
|
14
16
|
tooSmallArray: "{min, plural, one {Seleccione al menos # elemento} other {Seleccione al menos # elementos}}",
|
|
@@ -15,6 +15,9 @@ export declare const data: {
|
|
|
15
15
|
readonly noDataToExport: "Nenhum dado para exportar";
|
|
16
16
|
readonly exportSuccess: "{format} exportado com sucesso ({scope})";
|
|
17
17
|
readonly exportError: "Erro ao exportar dados";
|
|
18
|
+
readonly exportFetching: "Buscando registros para exportar: {loaded, number} de {total, number}";
|
|
19
|
+
readonly exportCancelled: "Exportação cancelada";
|
|
20
|
+
readonly exportTruncated: "Exportados os primeiros {count, number} de {total, number} registros (limite da exportação)";
|
|
18
21
|
readonly scopeAll: "todos os dados";
|
|
19
22
|
readonly scopeSelected: "{count, plural, one {# linha selecionada} other {# linhas selecionadas}}";
|
|
20
23
|
readonly scopeCurrentPage: "página atual";
|
|
@@ -16,6 +16,9 @@ var data = {
|
|
|
16
16
|
noDataToExport: "Nenhum dado para exportar",
|
|
17
17
|
exportSuccess: "{format} exportado com sucesso ({scope})",
|
|
18
18
|
exportError: "Erro ao exportar dados",
|
|
19
|
+
exportFetching: "Buscando registros para exportar: {loaded, number} de {total, number}",
|
|
20
|
+
exportCancelled: "Exporta\xE7\xE3o cancelada",
|
|
21
|
+
exportTruncated: "Exportados os primeiros {count, number} de {total, number} registros (limite da exporta\xE7\xE3o)",
|
|
19
22
|
scopeAll: "todos os dados",
|
|
20
23
|
scopeSelected: "{count, plural, one {# linha selecionada} other {# linhas selecionadas}}",
|
|
21
24
|
scopeCurrentPage: "p\xE1gina atual",
|
|
@@ -211,6 +211,9 @@ export declare const ptBR: {
|
|
|
211
211
|
readonly noDataToExport: "Nenhum dado para exportar";
|
|
212
212
|
readonly exportSuccess: "{format} exportado com sucesso ({scope})";
|
|
213
213
|
readonly exportError: "Erro ao exportar dados";
|
|
214
|
+
readonly exportFetching: "Buscando registros para exportar: {loaded, number} de {total, number}";
|
|
215
|
+
readonly exportCancelled: "Exportação cancelada";
|
|
216
|
+
readonly exportTruncated: "Exportados os primeiros {count, number} de {total, number} registros (limite da exportação)";
|
|
214
217
|
readonly scopeAll: "todos os dados";
|
|
215
218
|
readonly scopeSelected: "{count, plural, one {# linha selecionada} other {# linhas selecionadas}}";
|
|
216
219
|
readonly scopeCurrentPage: "página atual";
|
|
@@ -402,6 +405,8 @@ export declare const ptBR: {
|
|
|
402
405
|
readonly invalidOption: "Opção inválida";
|
|
403
406
|
readonly tooSmallString: "{min, plural, one {Mínimo de # caractere} other {Mínimo de # caracteres}}";
|
|
404
407
|
readonly tooBigString: "{max, plural, one {Máximo de # caractere} other {Máximo de # caracteres}}";
|
|
408
|
+
readonly charactersMissing: "{count, plural, one {Falta # caractere} other {Faltam # caracteres}}";
|
|
409
|
+
readonly charactersOver: "{count, plural, one {# caractere a mais} other {# caracteres a mais}}";
|
|
405
410
|
readonly tooSmallNumber: "Deve ser maior ou igual a {min, number}";
|
|
406
411
|
readonly tooBigNumber: "Deve ser menor ou igual a {max, number}";
|
|
407
412
|
readonly tooSmallArray: "{min, plural, one {Selecione ao menos # item} other {Selecione ao menos # itens}}";
|
|
@@ -8,6 +8,8 @@ export declare const validation: {
|
|
|
8
8
|
readonly invalidOption: "Opção inválida";
|
|
9
9
|
readonly tooSmallString: "{min, plural, one {Mínimo de # caractere} other {Mínimo de # caracteres}}";
|
|
10
10
|
readonly tooBigString: "{max, plural, one {Máximo de # caractere} other {Máximo de # caracteres}}";
|
|
11
|
+
readonly charactersMissing: "{count, plural, one {Falta # caractere} other {Faltam # caracteres}}";
|
|
12
|
+
readonly charactersOver: "{count, plural, one {# caractere a mais} other {# caracteres a mais}}";
|
|
11
13
|
readonly tooSmallNumber: "Deve ser maior ou igual a {min, number}";
|
|
12
14
|
readonly tooBigNumber: "Deve ser menor ou igual a {max, number}";
|
|
13
15
|
readonly tooSmallArray: "{min, plural, one {Selecione ao menos # item} other {Selecione ao menos # itens}}";
|
|
@@ -9,6 +9,8 @@ var validation = {
|
|
|
9
9
|
invalidOption: "Op\xE7\xE3o inv\xE1lida",
|
|
10
10
|
tooSmallString: "{min, plural, one {M\xEDnimo de # caractere} other {M\xEDnimo de # caracteres}}",
|
|
11
11
|
tooBigString: "{max, plural, one {M\xE1ximo de # caractere} other {M\xE1ximo de # caracteres}}",
|
|
12
|
+
charactersMissing: "{count, plural, one {Falta # caractere} other {Faltam # caracteres}}",
|
|
13
|
+
charactersOver: "{count, plural, one {# caractere a mais} other {# caracteres a mais}}",
|
|
12
14
|
tooSmallNumber: "Deve ser maior ou igual a {min, number}",
|
|
13
15
|
tooBigNumber: "Deve ser menor ou igual a {max, number}",
|
|
14
16
|
tooSmallArray: "{min, plural, one {Selecione ao menos # item} other {Selecione ao menos # itens}}",
|
package/dist/i18n/use-t.d.ts
CHANGED
|
@@ -213,6 +213,9 @@ export declare function useTelamonjsT(): import("next-intl")._Translator<import(
|
|
|
213
213
|
readonly noDataToExport: "Nenhum dado para exportar";
|
|
214
214
|
readonly exportSuccess: "{format} exportado com sucesso ({scope})";
|
|
215
215
|
readonly exportError: "Erro ao exportar dados";
|
|
216
|
+
readonly exportFetching: "Buscando registros para exportar: {loaded, number} de {total, number}";
|
|
217
|
+
readonly exportCancelled: "Exportação cancelada";
|
|
218
|
+
readonly exportTruncated: "Exportados os primeiros {count, number} de {total, number} registros (limite da exportação)";
|
|
216
219
|
readonly scopeAll: "todos os dados";
|
|
217
220
|
readonly scopeSelected: "{count, plural, one {# linha selecionada} other {# linhas selecionadas}}";
|
|
218
221
|
readonly scopeCurrentPage: "página atual";
|
|
@@ -404,6 +407,8 @@ export declare function useTelamonjsT(): import("next-intl")._Translator<import(
|
|
|
404
407
|
readonly invalidOption: "Opção inválida";
|
|
405
408
|
readonly tooSmallString: "{min, plural, one {Mínimo de # caractere} other {Mínimo de # caracteres}}";
|
|
406
409
|
readonly tooBigString: "{max, plural, one {Máximo de # caractere} other {Máximo de # caracteres}}";
|
|
410
|
+
readonly charactersMissing: "{count, plural, one {Falta # caractere} other {Faltam # caracteres}}";
|
|
411
|
+
readonly charactersOver: "{count, plural, one {# caractere a mais} other {# caracteres a mais}}";
|
|
407
412
|
readonly tooSmallNumber: "Deve ser maior ou igual a {min, number}";
|
|
408
413
|
readonly tooBigNumber: "Deve ser menor ou igual a {max, number}";
|
|
409
414
|
readonly tooSmallArray: "{min, plural, one {Selecione ao menos # item} other {Selecione ao menos # itens}}";
|
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 { useListPageExport } from "./list-page/useListPageExport.js";
|
|
25
26
|
import { applyCrudPermissions } from "./list-page/apply-crud-permissions.js";
|
|
26
27
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
27
28
|
var logger = withComponent("ListPage");
|
|
@@ -184,6 +185,11 @@ function ListPage({
|
|
|
184
185
|
[search, allFilters, sorting, paginationParams]
|
|
185
186
|
);
|
|
186
187
|
const resolvedToolbarContent = typeof toolbarContent === "function" ? toolbarContent(listQuery) : toolbarContent;
|
|
188
|
+
const exportMenu = useListPageExport({
|
|
189
|
+
config,
|
|
190
|
+
listQuery,
|
|
191
|
+
total: effectiveTotal
|
|
192
|
+
});
|
|
187
193
|
const rootRef = useRef(null);
|
|
188
194
|
const {
|
|
189
195
|
editDialogOpen,
|
|
@@ -241,17 +247,6 @@ function ListPage({
|
|
|
241
247
|
});
|
|
242
248
|
}
|
|
243
249
|
}, [loadFilterOptions]);
|
|
244
|
-
const handleExport = () => {
|
|
245
|
-
if (!list.enableExport) return;
|
|
246
|
-
const csvContent = data.map((item) => Object.values(item).join(",")).join("\n");
|
|
247
|
-
const blob = new Blob([csvContent], { type: "text/csv" });
|
|
248
|
-
const url = window.URL.createObjectURL(blob);
|
|
249
|
-
const a = document.createElement("a");
|
|
250
|
-
a.href = url;
|
|
251
|
-
a.download = list.exportFilename || `${module.name}.csv`;
|
|
252
|
-
a.click();
|
|
253
|
-
window.URL.revokeObjectURL(url);
|
|
254
|
-
};
|
|
255
250
|
const rootClassName = isInfiniteScroll || embedded ? `flex flex-col h-full min-h-0 ${className || ""}` : `container mx-auto space-y-6 p-4 lg:p-6 ${className || ""}`;
|
|
256
251
|
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
257
252
|
/* @__PURE__ */ jsxs("div", { ref: rootRef, className: rootClassName, children: [
|
|
@@ -275,7 +270,8 @@ function ListPage({
|
|
|
275
270
|
onAdd: handleAdd,
|
|
276
271
|
onRefresh: handleRefresh,
|
|
277
272
|
exportData: isInfiniteScroll ? infiniteQuery.data : data,
|
|
278
|
-
exportFilename: module.name
|
|
273
|
+
exportFilename: module.name,
|
|
274
|
+
exportMenu
|
|
279
275
|
}
|
|
280
276
|
),
|
|
281
277
|
/* @__PURE__ */ jsx(
|
|
@@ -303,7 +299,7 @@ function ListPage({
|
|
|
303
299
|
onRowClick: dialogs?.view ? handleRowClick : void 0,
|
|
304
300
|
actionsConfig: finalActionsConfig,
|
|
305
301
|
onRefresh: handleRefresh,
|
|
306
|
-
|
|
302
|
+
exportMenu,
|
|
307
303
|
onAdd: handleAdd,
|
|
308
304
|
hasActiveQuery: Boolean(search) || Object.keys(allFilters).length > 0
|
|
309
305
|
}
|
|
@@ -4,6 +4,7 @@ import type { DataTableActionsConfig } from '../../types/actions';
|
|
|
4
4
|
import type { ListConfig } from '../../types/crud';
|
|
5
5
|
import type { ColumnFilterConfig } from '../../types/filters';
|
|
6
6
|
import type { BulkAction } from '../../data/BulkActionsToolbar';
|
|
7
|
+
import type { DataTableExportMenuProps } from '../../data/datatable/types';
|
|
7
8
|
import type { ListPageProps } from './types';
|
|
8
9
|
interface ListPageTableProps<TData> {
|
|
9
10
|
list: ListConfig<TData>;
|
|
@@ -36,7 +37,8 @@ interface ListPageTableProps<TData> {
|
|
|
36
37
|
onRowClick: ((row: TData) => void) | undefined;
|
|
37
38
|
actionsConfig: DataTableActionsConfig<TData> | undefined;
|
|
38
39
|
onRefresh: () => Promise<void>;
|
|
39
|
-
|
|
40
|
+
/** Export menu props (`useListPageExport`); undefined = no export */
|
|
41
|
+
exportMenu?: DataTableExportMenuProps<TData>;
|
|
40
42
|
onAdd: () => void;
|
|
41
43
|
/** Search or filters active → "no results" copy instead of "start by adding". */
|
|
42
44
|
hasActiveQuery?: boolean;
|
|
@@ -53,5 +55,5 @@ interface ListPageTableProps<TData> {
|
|
|
53
55
|
*
|
|
54
56
|
* @internal Extracted from ListPage during the god-component decomposition.
|
|
55
57
|
*/
|
|
56
|
-
export declare function ListPageTable<TData>({ list, footerContent, data, total, loading, error, tableId, page, pageSize, isServerSidePagination, filterOptions, enableBulkActions, bulkActions, headerActions, cardComponent, embedded, isInfiniteScroll, infiniteQuery, hasCreateDialog, onRowClick, actionsConfig, onRefresh,
|
|
58
|
+
export declare function ListPageTable<TData>({ list, footerContent, data, total, loading, error, tableId, page, pageSize, isServerSidePagination, filterOptions, enableBulkActions, bulkActions, headerActions, cardComponent, embedded, isInfiniteScroll, infiniteQuery, hasCreateDialog, onRowClick, actionsConfig, onRefresh, exportMenu, onAdd, hasActiveQuery, }: ListPageTableProps<TData>): import("react").JSX.Element;
|
|
57
59
|
export {};
|
|
@@ -30,7 +30,7 @@ function ListPageTable({
|
|
|
30
30
|
onRowClick,
|
|
31
31
|
actionsConfig,
|
|
32
32
|
onRefresh,
|
|
33
|
-
|
|
33
|
+
exportMenu,
|
|
34
34
|
onAdd,
|
|
35
35
|
hasActiveQuery = false
|
|
36
36
|
}) {
|
|
@@ -72,7 +72,8 @@ function ListPageTable({
|
|
|
72
72
|
enableSearch: true,
|
|
73
73
|
enableFilters: true,
|
|
74
74
|
filterOptions,
|
|
75
|
-
enableExport:
|
|
75
|
+
enableExport: Boolean(exportMenu),
|
|
76
|
+
exportMenuProps: exportMenu,
|
|
76
77
|
enableAdd: hasCreateDialog,
|
|
77
78
|
enableRefresh: true,
|
|
78
79
|
enableColumnVisibility: true,
|
|
@@ -82,7 +83,6 @@ function ListPageTable({
|
|
|
82
83
|
enableBulkActions,
|
|
83
84
|
pageSize,
|
|
84
85
|
onRefresh,
|
|
85
|
-
onExport,
|
|
86
86
|
onAdd,
|
|
87
87
|
bulkActions: refreshingBulkActions,
|
|
88
88
|
headerActions,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import type { ListConfig } from '../../types/crud';
|
|
3
|
+
import type { DataTableExportMenuProps } from '../../data/datatable/types';
|
|
3
4
|
import type { ActiveFilterChip } from './types';
|
|
4
5
|
interface ListPageToolbarProps<TData> {
|
|
5
6
|
list: ListConfig<TData>;
|
|
@@ -27,6 +28,8 @@ interface ListPageToolbarProps<TData> {
|
|
|
27
28
|
exportData?: TData[];
|
|
28
29
|
/** Base name of the exported file (default: module name). */
|
|
29
30
|
exportFilename?: string;
|
|
31
|
+
/** Export menu extras from `useListPageExport` (`loadAll`, `onServerExport`, formats) */
|
|
32
|
+
exportMenu?: DataTableExportMenuProps<TData>;
|
|
30
33
|
/** "Filters" popover content (second level) */
|
|
31
34
|
filtersPanel?: ReactNode;
|
|
32
35
|
/** Chips of the active `filtersPanel` filters */
|
|
@@ -41,5 +44,5 @@ interface ListPageToolbarProps<TData> {
|
|
|
41
44
|
*
|
|
42
45
|
* @internal Extracted from ListPage during the god-component decomposition.
|
|
43
46
|
*/
|
|
44
|
-
export declare function ListPageToolbar<TData>({ list, toolbarPrepend, toolbarContent, localSearch, onSearchChange, toolbarFilters, onFilterChange, total, loading, isFetching, showAddButton, onAdd, onRefresh, exportData, exportFilename, filtersPanel, activeFilters, onClearFilters, }: ListPageToolbarProps<TData>): import("react").JSX.Element;
|
|
47
|
+
export declare function ListPageToolbar<TData>({ list, toolbarPrepend, toolbarContent, localSearch, onSearchChange, toolbarFilters, onFilterChange, total, loading, isFetching, showAddButton, onAdd, onRefresh, exportData, exportFilename, exportMenu, filtersPanel, activeFilters, onClearFilters, }: ListPageToolbarProps<TData>): import("react").JSX.Element;
|
|
45
48
|
export {};
|
|
@@ -56,6 +56,7 @@ function ListPageToolbar({
|
|
|
56
56
|
onRefresh,
|
|
57
57
|
exportData,
|
|
58
58
|
exportFilename,
|
|
59
|
+
exportMenu,
|
|
59
60
|
filtersPanel,
|
|
60
61
|
activeFilters = [],
|
|
61
62
|
onClearFilters
|
|
@@ -69,9 +70,10 @@ function ListPageToolbar({
|
|
|
69
70
|
contentProps: filtersContentProps
|
|
70
71
|
} = useHoverPopover();
|
|
71
72
|
const counter = useCounterLabel(list.toolbar?.counterLabel);
|
|
73
|
+
const exportEnabled = Boolean(list.enableExport || list.onExport);
|
|
72
74
|
const exportColumns = useMemo(
|
|
73
|
-
() =>
|
|
74
|
-
[
|
|
75
|
+
() => exportEnabled ? resolveColumns(list.columns, text) : [],
|
|
76
|
+
[exportEnabled, list.columns, text]
|
|
75
77
|
);
|
|
76
78
|
const moreFilters = (list.toolbar?.filters ?? []).map((f) => ({ f, more: f.options.filter((o) => o.more) })).filter((x) => x.more.length > 0);
|
|
77
79
|
const resetOf = (f) => f.allValue ?? f.options[0]?.value ?? "";
|
|
@@ -88,7 +90,7 @@ function ListPageToolbar({
|
|
|
88
90
|
});
|
|
89
91
|
const chips = [...moreChips, ...activeFilters];
|
|
90
92
|
const showFiltersButton = Boolean(filtersPanel) || moreFilters.length > 0;
|
|
91
|
-
const actionsMenu = list.toolbar?.actionsMenu &&
|
|
93
|
+
const actionsMenu = list.toolbar?.actionsMenu && exportEnabled;
|
|
92
94
|
return /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
93
95
|
/* @__PURE__ */ jsxs(TabToolbar, { children: [
|
|
94
96
|
toolbarPrepend,
|
|
@@ -203,13 +205,15 @@ function ListPageToolbar({
|
|
|
203
205
|
loading
|
|
204
206
|
}
|
|
205
207
|
),
|
|
206
|
-
|
|
208
|
+
exportEnabled && !actionsMenu && /* @__PURE__ */ jsx(
|
|
207
209
|
ExportMenu,
|
|
208
210
|
{
|
|
209
211
|
data: exportData ?? [],
|
|
210
212
|
columns: exportColumns,
|
|
211
213
|
currentPageRows: exportData ?? [],
|
|
212
214
|
filename: list.exportFilename || exportFilename,
|
|
215
|
+
formats: list.exportFormats,
|
|
216
|
+
...exportMenu,
|
|
213
217
|
className: "h-8"
|
|
214
218
|
}
|
|
215
219
|
),
|
|
@@ -229,6 +233,8 @@ function ListPageToolbar({
|
|
|
229
233
|
columns: exportColumns,
|
|
230
234
|
currentPageRows: exportData ?? [],
|
|
231
235
|
filename: list.exportFilename || exportFilename,
|
|
236
|
+
formats: list.exportFormats,
|
|
237
|
+
...exportMenu,
|
|
232
238
|
trigger: /* @__PURE__ */ jsx(
|
|
233
239
|
Button,
|
|
234
240
|
{
|
|
@@ -9,7 +9,10 @@ import type { CrudConfigWithAnyForm, DialogsConfig } from '../../types/crud';
|
|
|
9
9
|
* edit/view injection, no footer Edit, no `?create=1` / `?edit=` deep link;
|
|
10
10
|
* - the row view/edit/delete (configured, or injected by a dialog) inherit
|
|
11
11
|
* `permissions.<op>` unless they declare their own `permission`;
|
|
12
|
-
* - `permissions.can` becomes `actionsConfig.can` unless that one is set
|
|
12
|
+
* - `permissions.can` becomes `actionsConfig.can` unless that one is set;
|
|
13
|
+
* - with no checker at all, `permissions.failClosed` makes that `can` deny
|
|
14
|
+
* everything; without `failClosed` the gate stays open and a development
|
|
15
|
+
* warning names the config (once).
|
|
13
16
|
*
|
|
14
17
|
* With a form and without `config.permissions` both inputs come back untouched.
|
|
15
18
|
*
|
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
// src/pages/list-page/apply-crud-permissions.ts
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
crudChecker,
|
|
4
|
+
crudGranted
|
|
5
|
+
} from "../../components/data/action-access.js";
|
|
6
|
+
var OPERATIONS = ["create", "edit", "delete", "view"];
|
|
7
|
+
var warned = /* @__PURE__ */ new WeakSet();
|
|
8
|
+
function warnUnchecked(config, permissions, checked) {
|
|
9
|
+
if (process.env.NODE_ENV === "production") return;
|
|
10
|
+
if (checked || permissions.failClosed || warned.has(config)) return;
|
|
11
|
+
if (!OPERATIONS.some((op) => permissions[op])) return;
|
|
12
|
+
warned.add(config);
|
|
13
|
+
console.warn(
|
|
14
|
+
`[telamonjs] CrudConfig "${config.module.name}" declares permissions but has no way to check them (neither permissions.can, actionsConfig.can nor actionsConfig.userPermissions): every operation is allowed. Pass a checker, or set permissions.failClosed to deny until one exists.`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
3
17
|
function applyCrudPermissions(config, actionsConfig) {
|
|
4
18
|
const { permissions, form, dialogs: allDialogs } = config;
|
|
5
19
|
const withForm = form || !allDialogs ? allDialogs : { ...allDialogs, create: void 0, edit: void 0 };
|
|
6
20
|
if (!permissions) return { dialogs: withForm, actionsConfig };
|
|
7
|
-
const
|
|
21
|
+
const access = { permissions, actionsConfig };
|
|
22
|
+
const can = crudChecker(access);
|
|
23
|
+
warnUnchecked(config, permissions, Boolean(can || actionsConfig?.userPermissions));
|
|
24
|
+
const allowed = (op) => crudGranted(access, op);
|
|
8
25
|
const dialogs = withForm && {
|
|
9
26
|
...withForm,
|
|
10
27
|
create: allowed("create") ? withForm.create : void 0,
|
|
@@ -25,7 +42,7 @@ function applyCrudPermissions(config, actionsConfig) {
|
|
|
25
42
|
actionsConfig: {
|
|
26
43
|
...actionsConfig,
|
|
27
44
|
standard,
|
|
28
|
-
can
|
|
45
|
+
can
|
|
29
46
|
}
|
|
30
47
|
};
|
|
31
48
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { ComponentType, ReactNode } from 'react';
|
|
2
|
-
import type { CrudConfigWithAnyForm } from '../../types/crud';
|
|
3
|
-
import type { PaginationParams, SortField } from '../../types/pagination';
|
|
2
|
+
import type { CrudConfigWithAnyForm, ListQueryState } from '../../types/crud';
|
|
4
3
|
import type { ColumnFilterConfig } from '../../types/filters';
|
|
5
4
|
import type { BulkAction } from '../../data/BulkActionsToolbar';
|
|
6
5
|
/**
|
|
@@ -107,17 +106,4 @@ export interface ActiveFilterChip {
|
|
|
107
106
|
label: string;
|
|
108
107
|
onRemove: () => void;
|
|
109
108
|
}
|
|
110
|
-
|
|
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
|
-
}
|
|
109
|
+
export type { ListQueryState } from '../../types/crud';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DataTableExportMenuProps } from '../../data/datatable/types';
|
|
2
|
+
import type { CrudConfigWithAnyForm, ListQueryState } from '../../types/crud';
|
|
3
|
+
/** Default row cap of `list.exportAll` */
|
|
4
|
+
export declare const EXPORT_ALL_MAX_ROWS = 10000;
|
|
5
|
+
interface UseListPageExportParams<TData> {
|
|
6
|
+
config: CrudConfigWithAnyForm<TData>;
|
|
7
|
+
/** The list's current query (search, filters, sort) */
|
|
8
|
+
listQuery: ListQueryState;
|
|
9
|
+
/** Rows matching on the server (the "All" count) */
|
|
10
|
+
total: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Export menu props of a ListPage, from `list.enableExport` / `exportAll` /
|
|
14
|
+
* `exportFormats` / `onExport` — shared by the list toolbar and the paginated
|
|
15
|
+
* DataTable. `undefined` when the list has no export.
|
|
16
|
+
*
|
|
17
|
+
* - `onExport`: the app exports (formats only, gets the current query);
|
|
18
|
+
* - `exportAll`: "All" fetches every matching page through `query.queryFn`;
|
|
19
|
+
* - neither: "All" exports the loaded rows (unchanged default).
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export declare function useListPageExport<TData>({ config, listQuery, total, }: UseListPageExportParams<TData>): DataTableExportMenuProps<TData> | undefined;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/pages/list-page/useListPageExport.ts
|
|
4
|
+
import { useMemo } from "react";
|
|
5
|
+
import { fetchAllPages } from "../../data/fetch-all-pages.js";
|
|
6
|
+
var EXPORT_ALL_MAX_ROWS = 1e4;
|
|
7
|
+
function useListPageExport({
|
|
8
|
+
config,
|
|
9
|
+
listQuery,
|
|
10
|
+
total
|
|
11
|
+
}) {
|
|
12
|
+
const { module, list, query } = config;
|
|
13
|
+
const { enableExport, exportAll, exportFormats, exportFilename, onExport } = list;
|
|
14
|
+
const listPageSize = list.defaultPageSize || 50;
|
|
15
|
+
return useMemo(() => {
|
|
16
|
+
if (!enableExport && !onExport) return void 0;
|
|
17
|
+
const base = {
|
|
18
|
+
formats: exportFormats,
|
|
19
|
+
filename: exportFilename || module.name
|
|
20
|
+
};
|
|
21
|
+
if (onExport) {
|
|
22
|
+
return { ...base, onServerExport: (format) => onExport(listQuery, format) };
|
|
23
|
+
}
|
|
24
|
+
if (!exportAll) return base;
|
|
25
|
+
const options = typeof exportAll === "object" ? exportAll : {};
|
|
26
|
+
return {
|
|
27
|
+
...base,
|
|
28
|
+
allCount: total,
|
|
29
|
+
loadAll: ({ signal, onProgress }) => fetchAllPages({
|
|
30
|
+
queryFn: query.queryFn,
|
|
31
|
+
params: listQuery.params,
|
|
32
|
+
pageSize: options.pageSize ?? listPageSize,
|
|
33
|
+
maxRows: options.maxRows ?? EXPORT_ALL_MAX_ROWS,
|
|
34
|
+
signal,
|
|
35
|
+
onProgress
|
|
36
|
+
})
|
|
37
|
+
};
|
|
38
|
+
}, [
|
|
39
|
+
enableExport,
|
|
40
|
+
onExport,
|
|
41
|
+
exportAll,
|
|
42
|
+
exportFormats,
|
|
43
|
+
exportFilename,
|
|
44
|
+
module.name,
|
|
45
|
+
listQuery,
|
|
46
|
+
total,
|
|
47
|
+
query.queryFn,
|
|
48
|
+
listPageSize
|
|
49
|
+
]);
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
EXPORT_ALL_MAX_ROWS,
|
|
53
|
+
useListPageExport
|
|
54
|
+
};
|
package/dist/types/actions.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* These types define the configuration for automatic action column injection
|
|
6
6
|
* in DataTable components with a flexible, extensible architecture.
|
|
7
7
|
*/
|
|
8
|
+
import type { HTMLAttributes } from 'react';
|
|
8
9
|
import type { I18nText } from '../i18n/msg';
|
|
9
10
|
/**
|
|
10
11
|
* Button variant types for actions
|
|
@@ -33,6 +34,19 @@ export interface ConfirmDialogConfig<TData = any> {
|
|
|
33
34
|
* action as the second argument of `handler`/`onClick`: `(row, { inputs })`.
|
|
34
35
|
*/
|
|
35
36
|
inputs?: ConfirmDialogInput[];
|
|
37
|
+
/**
|
|
38
|
+
* Keep the confirm disabled while any input fails (`required`, `minLength`,
|
|
39
|
+
* `maxLength`, `min`/`max`, `validate`). Each failing field shows its message
|
|
40
|
+
* live (muted until the field is edited), so the user always sees why the
|
|
41
|
+
* confirm is off. Default: the confirm stays enabled and the messages show
|
|
42
|
+
* from the first attempt.
|
|
43
|
+
*/
|
|
44
|
+
disableUntilValid?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/** Choice of a `select` input: `value` reaches the action, `label` is shown */
|
|
47
|
+
export interface ConfirmDialogOption {
|
|
48
|
+
value: string;
|
|
49
|
+
label: I18nText;
|
|
36
50
|
}
|
|
37
51
|
/**
|
|
38
52
|
* A field of a confirmation dialog (`ConfirmDialogConfig.inputs`,
|
|
@@ -46,14 +60,39 @@ export interface ConfirmDialogInput {
|
|
|
46
60
|
type: 'text' | 'textarea' | 'select' | 'date';
|
|
47
61
|
/** Confirming is blocked while it is empty */
|
|
48
62
|
required?: boolean;
|
|
49
|
-
/** Choices of a `select
|
|
50
|
-
options?: string[];
|
|
63
|
+
/** Choices of a `select`: a string is both value and label */
|
|
64
|
+
options?: (string | ConfirmDialogOption)[];
|
|
51
65
|
defaultValue?: string;
|
|
66
|
+
/** Placeholder of a `text`/`textarea`/`date`, or the `select` prompt */
|
|
67
|
+
placeholder?: I18nText;
|
|
68
|
+
/** Help text under the field, announced with it */
|
|
69
|
+
description?: I18nText;
|
|
70
|
+
/** Visible rows of a `textarea` */
|
|
71
|
+
rows?: number;
|
|
72
|
+
/**
|
|
73
|
+
* Minimum length of the trimmed value: checked when the field is filled, and
|
|
74
|
+
* also when empty if `required`. While short, the field shows how many
|
|
75
|
+
* characters are missing, live, without a confirm attempt.
|
|
76
|
+
*/
|
|
77
|
+
minLength?: number;
|
|
78
|
+
/** Maximum length of the trimmed value; while over, the field shows the excess live */
|
|
79
|
+
maxLength?: number;
|
|
80
|
+
/** Earliest `date` (`YYYY-MM-DD`): set on the native input and validated */
|
|
81
|
+
min?: string;
|
|
82
|
+
/** Latest `date` (`YYYY-MM-DD`): set on the native input and validated */
|
|
83
|
+
max?: string;
|
|
84
|
+
/** Suggestions of a `text` input (a native `<datalist>`; any value is still accepted) */
|
|
85
|
+
suggestions?: string[];
|
|
86
|
+
/** Native `inputMode` of a `text`/`textarea`, e.g. `'decimal'` */
|
|
87
|
+
inputMode?: HTMLAttributes<HTMLInputElement>['inputMode'];
|
|
88
|
+
/** Native `autoComplete`, e.g. `'off'` for a typed confirmation word */
|
|
89
|
+
autoComplete?: string;
|
|
52
90
|
/**
|
|
53
91
|
* Custom rule beyond `required`: return a message to mark the field invalid
|
|
54
92
|
* and block the confirm, `undefined` when valid. Runs (pure, on every
|
|
55
|
-
* render) from the first confirm attempt on
|
|
56
|
-
* with all the values for cross-field rules.
|
|
93
|
+
* render) from the first confirm attempt on (live with `disableUntilValid`),
|
|
94
|
+
* also on empty optional fields, with all the values for cross-field rules.
|
|
95
|
+
* `minLength`, `required`, `maxLength` and `min`/`max` are checked first.
|
|
57
96
|
*/
|
|
58
97
|
validate?: (value: string, values: Record<string, string>) => I18nText | undefined;
|
|
59
98
|
}
|