drf-react-by-schema 0.6.1 → 0.6.2
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/dist/api.d.ts +13 -1
- package/dist/api.js +18 -7
- package/dist/components/DataGridBySchemaEditable.js +4 -0
- package/dist/components/DataTotals.d.ts +1 -5
- package/dist/components/DataTotalsServer.d.ts +8 -0
- package/dist/components/DataTotalsServer.js +18 -0
- package/dist/components/GenericModelList.d.ts +1 -1
- package/dist/components/GenericModelList.js +5 -1
- package/dist/utils.d.ts +3 -1
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { serverEndPointType } from './context/DRFReactBySchemaContext';
|
|
2
2
|
import { Item, SchemaType, modelOptionsType, DataSchemaColumnsType, ItemSchemaColumnsType, PaginatedResult } from './utils';
|
|
3
3
|
import { GridFilterModel } from '@mui/x-data-grid';
|
|
4
|
+
import { AlertColor } from '@mui/material/Alert';
|
|
4
5
|
type Id = string | number | null;
|
|
5
6
|
interface TargetApiParams {
|
|
6
7
|
path: string;
|
|
@@ -70,8 +71,19 @@ export interface getGenericModelListProps {
|
|
|
70
71
|
loadedModelOptions?: modelOptionsType | boolean;
|
|
71
72
|
page?: number;
|
|
72
73
|
filter?: GridFilterModel;
|
|
74
|
+
sumRows?: SumRowsType;
|
|
73
75
|
}
|
|
74
|
-
export
|
|
76
|
+
export interface SumRowsType {
|
|
77
|
+
rows: SumRowsItem[];
|
|
78
|
+
severity?: AlertColor;
|
|
79
|
+
}
|
|
80
|
+
interface SumRowsItem {
|
|
81
|
+
field: string;
|
|
82
|
+
prefix?: string;
|
|
83
|
+
suffix?: string;
|
|
84
|
+
isCount?: boolean;
|
|
85
|
+
}
|
|
86
|
+
export declare const getGenericModelList: ({ model, serverEndPoint, id, relatedModel, relatedModelId, columnFields, hiddenFields, creatableFields, isInBatches, loadedSchema, loadedModelOptions, page, filter, sumRows, }: getGenericModelListProps) => Promise<false | DataSchemaColumnsType>;
|
|
75
87
|
export declare const getGenericModel: ({ model, serverEndPoint, id, relatedModel, relatedModelId, }: {
|
|
76
88
|
model: string;
|
|
77
89
|
serverEndPoint: serverEndPointType | null;
|
package/dist/api.js
CHANGED
|
@@ -540,7 +540,7 @@ const isLoggedIn = (serverEndPoint) => __awaiter(void 0, void 0, void 0, functio
|
|
|
540
540
|
return usuaria;
|
|
541
541
|
});
|
|
542
542
|
exports.isLoggedIn = isLoggedIn;
|
|
543
|
-
const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = '', relatedModelId = '', columnFields, hiddenFields = ['id'], creatableFields = [], isInBatches = false, loadedSchema, loadedModelOptions, page, filter, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
543
|
+
const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = '', relatedModelId = '', columnFields, hiddenFields = ['id'], creatableFields = [], isInBatches = false, loadedSchema, loadedModelOptions, page, filter, sumRows, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
544
544
|
let path = `${model}/${id}`;
|
|
545
545
|
let schemaPath = model;
|
|
546
546
|
let schema = loadedSchema;
|
|
@@ -550,11 +550,12 @@ const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = ''
|
|
|
550
550
|
path += `/${relatedModel}/${relatedModelId}`;
|
|
551
551
|
schemaPath += `/${id}/${relatedModel}`;
|
|
552
552
|
}
|
|
553
|
-
if (page || filter) {
|
|
553
|
+
if (page || filter || sumRows) {
|
|
554
554
|
path += '?';
|
|
555
555
|
}
|
|
556
|
-
if (
|
|
557
|
-
|
|
556
|
+
if (sumRows) {
|
|
557
|
+
const sumRowsParams = sumRows.rows.map(row => row.field).join(',');
|
|
558
|
+
path += `sum_rows=${sumRowsParams}`;
|
|
558
559
|
}
|
|
559
560
|
if (filter) {
|
|
560
561
|
const filtersArr = [];
|
|
@@ -570,11 +571,17 @@ const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = ''
|
|
|
570
571
|
: `columnField=${item.columnField}&operatorValue=${item.operatorValue}`;
|
|
571
572
|
filtersArr.push(queryParam);
|
|
572
573
|
}
|
|
573
|
-
if (
|
|
574
|
+
if (sumRows) {
|
|
574
575
|
path += '&';
|
|
575
576
|
}
|
|
576
577
|
path += filtersArr.join('&');
|
|
577
578
|
}
|
|
579
|
+
if (page) {
|
|
580
|
+
if (sumRows || filter) {
|
|
581
|
+
path += '&';
|
|
582
|
+
}
|
|
583
|
+
path += `page=${page + 1}`;
|
|
584
|
+
}
|
|
578
585
|
// Only get schema and columns if not in batches or in first batch:
|
|
579
586
|
if (!schema) {
|
|
580
587
|
const options = yield getSchema(schemaPath, serverEndPoint);
|
|
@@ -589,6 +596,7 @@ const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = ''
|
|
|
589
596
|
}
|
|
590
597
|
}
|
|
591
598
|
let rowCount = 0;
|
|
599
|
+
let sumRowsTotals = null;
|
|
592
600
|
let data = [];
|
|
593
601
|
if (!id || (id && !relatedModelId)) {
|
|
594
602
|
if (isInBatches) {
|
|
@@ -601,6 +609,9 @@ const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = ''
|
|
|
601
609
|
const dataRaw = 'results' in ret ? ret.results : ret;
|
|
602
610
|
if ('results' in ret) {
|
|
603
611
|
rowCount = ret.count;
|
|
612
|
+
if (sumRows) {
|
|
613
|
+
sumRowsTotals = ret.sum_rows;
|
|
614
|
+
}
|
|
604
615
|
}
|
|
605
616
|
data = dataRaw.map((row) => {
|
|
606
617
|
const newRow = {};
|
|
@@ -624,10 +635,10 @@ const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = ''
|
|
|
624
635
|
}
|
|
625
636
|
if (loadedSchema) {
|
|
626
637
|
// DEBUG console.log({ path, data });
|
|
627
|
-
return { data, rowCount };
|
|
638
|
+
return { data, rowCount, sumRowsTotals };
|
|
628
639
|
}
|
|
629
640
|
// DEBUG console.log({ path, data, columns, schema });
|
|
630
|
-
return { data, columns, schema, modelOptions, rowCount };
|
|
641
|
+
return { data, columns, schema, modelOptions, rowCount, sumRowsTotals };
|
|
631
642
|
});
|
|
632
643
|
exports.getGenericModelList = getGenericModelList;
|
|
633
644
|
const getGenericModel = ({ model, serverEndPoint, id = '', relatedModel = '', relatedModelId = '', }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -578,6 +578,10 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
578
578
|
setPreparedColumns,
|
|
579
579
|
showQuickFilter: true,
|
|
580
580
|
quickFilterProps: { debounceMs: 500 },
|
|
581
|
+
getRowsToExport: (e) => {
|
|
582
|
+
console.log(e);
|
|
583
|
+
return [];
|
|
584
|
+
},
|
|
581
585
|
},
|
|
582
586
|
footer: {
|
|
583
587
|
name,
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { AlertColor } from '@mui/material/Alert';
|
|
3
2
|
import { GridRowId } from '@mui/x-data-grid';
|
|
4
3
|
import { Item } from '../utils';
|
|
5
|
-
|
|
6
|
-
rows: Item[];
|
|
7
|
-
severity?: AlertColor;
|
|
8
|
-
}
|
|
4
|
+
import { SumRowsType } from '../api';
|
|
9
5
|
interface DataTotalsProps {
|
|
10
6
|
data?: Item[];
|
|
11
7
|
sumRows?: SumRowsType;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { SumRowsType } from '../api';
|
|
3
|
+
interface DataTotalsServerProps {
|
|
4
|
+
sumRows?: SumRowsType;
|
|
5
|
+
totals?: null | Record<string, number>;
|
|
6
|
+
}
|
|
7
|
+
declare const DataTotalsServer: ({ sumRows, totals }: DataTotalsServerProps) => JSX.Element;
|
|
8
|
+
export default DataTotalsServer;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
const Alert_1 = __importDefault(require("@mui/material/Alert"));
|
|
8
|
+
const List_1 = __importDefault(require("@mui/material/List"));
|
|
9
|
+
const ListItem_1 = __importDefault(require("@mui/material/ListItem"));
|
|
10
|
+
const react_number_format_1 = require("react-number-format");
|
|
11
|
+
;
|
|
12
|
+
const DataTotalsServer = ({ sumRows, totals }) => {
|
|
13
|
+
return (react_1.default.createElement(react_1.default.Fragment, null, sumRows && sumRows.rows.length > 0 &&
|
|
14
|
+
react_1.default.createElement(Alert_1.default, { severity: sumRows.severity || 'info' },
|
|
15
|
+
react_1.default.createElement(List_1.default, { dense: true }, sumRows.rows.map(row => (react_1.default.createElement(ListItem_1.default, { key: `sumRows_${row.field}` },
|
|
16
|
+
react_1.default.createElement(react_number_format_1.NumericFormat, { value: totals ? totals[`${row.field}_total`] : 0, thousandSeparator: '.', decimalSeparator: ',', displayType: 'text', decimalScale: row.isCount ? 0 : 2, fixedDecimalScale: true, prefix: row.prefix, suffix: row.suffix }))))))));
|
|
17
|
+
};
|
|
18
|
+
exports.default = DataTotalsServer;
|
|
@@ -42,6 +42,7 @@ const Button_1 = __importDefault(require("@mui/material/Button"));
|
|
|
42
42
|
const AddCircleOutline_1 = __importDefault(require("@mui/icons-material/AddCircleOutline"));
|
|
43
43
|
const DataGridBySchemaEditable_1 = __importDefault(require("./DataGridBySchemaEditable"));
|
|
44
44
|
const DataTotals_1 = __importDefault(require("./DataTotals"));
|
|
45
|
+
const DataTotalsServer_1 = __importDefault(require("./DataTotalsServer"));
|
|
45
46
|
const styles_1 = require("../styles");
|
|
46
47
|
const api_1 = require("../api");
|
|
47
48
|
const DRFReactBySchemaContext_1 = require("../context/DRFReactBySchemaContext");
|
|
@@ -102,6 +103,7 @@ const GenericModelList = ({ columnFields, hiddenFields = [], minWidthFields, ind
|
|
|
102
103
|
hiddenFields,
|
|
103
104
|
page: paginationModel ? paginationModel.page : 0,
|
|
104
105
|
filter: paginationModel ? paginationModel.filter : undefined,
|
|
106
|
+
sumRows,
|
|
105
107
|
};
|
|
106
108
|
const paginatedData = yield (0, api_1.getGenericModelList)(loadPaginatedParams);
|
|
107
109
|
if (paginatedData && typeof paginatedData !== 'boolean') {
|
|
@@ -142,6 +144,8 @@ const GenericModelList = ({ columnFields, hiddenFields = [], minWidthFields, ind
|
|
|
142
144
|
: typeof data.rowCount !== undefined
|
|
143
145
|
? data.rowCount
|
|
144
146
|
: 0 })),
|
|
145
|
-
|
|
147
|
+
paginationMode === 'client'
|
|
148
|
+
? react_1.default.createElement(DataTotals_1.default, { data: data.data, sumRows: sumRows, visibleRows: visibleRows })
|
|
149
|
+
: react_1.default.createElement(DataTotalsServer_1.default, { sumRows: sumRows, totals: data.sumRowsTotals })))));
|
|
146
150
|
};
|
|
147
151
|
exports.default = GenericModelList;
|
package/dist/utils.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export type PaginatedResult = {
|
|
|
5
5
|
count: number;
|
|
6
6
|
next: number;
|
|
7
7
|
previous: number;
|
|
8
|
+
sum_rows: null | Record<string, number>;
|
|
8
9
|
results: Item[];
|
|
9
10
|
};
|
|
10
11
|
export interface PaginationModel {
|
|
@@ -54,9 +55,10 @@ interface GridActionsBySchemaColDef extends GridActionsColDef {
|
|
|
54
55
|
export type GridEnrichedBySchemaColDef = GridBySchemaColDef | GridActionsBySchemaColDef;
|
|
55
56
|
export interface DataSchemaColumnsType {
|
|
56
57
|
data: Item[];
|
|
57
|
-
rowCount?: number;
|
|
58
58
|
schema: SchemaType;
|
|
59
59
|
modelOptions: modelOptionsType;
|
|
60
|
+
rowCount?: number;
|
|
61
|
+
sumRowsTotals?: null | Record<string, number>;
|
|
60
62
|
columns?: GridEnrichedBySchemaColDef[];
|
|
61
63
|
}
|
|
62
64
|
export interface ItemSchemaColumnsType {
|
package/package.json
CHANGED