drf-react-by-schema 0.8.5 → 0.8.7
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
CHANGED
|
@@ -64,6 +64,7 @@ export interface GetGenericModelListProps {
|
|
|
64
64
|
loadedModelOptions?: modelOptionsType | boolean;
|
|
65
65
|
page?: number;
|
|
66
66
|
filter?: GridFilterModel;
|
|
67
|
+
queryParams?: string[];
|
|
67
68
|
sort?: GridSortModel;
|
|
68
69
|
sumRows?: SumRowsType;
|
|
69
70
|
}
|
|
@@ -77,7 +78,7 @@ interface SumRowsItem {
|
|
|
77
78
|
suffix?: string;
|
|
78
79
|
isCount?: boolean;
|
|
79
80
|
}
|
|
80
|
-
export declare const getGenericModelList: ({ model, serverEndPoint, id, relatedModel, relatedModelId, columnFields, hiddenFields, creatableFields, isInBatches, loadedSchema, loadedModelOptions, page, filter, sort, sumRows, }: GetGenericModelListProps) => Promise<false | DataSchemaColumnsType>;
|
|
81
|
+
export declare const getGenericModelList: ({ model, serverEndPoint, id, relatedModel, relatedModelId, columnFields, hiddenFields, creatableFields, isInBatches, loadedSchema, loadedModelOptions, page, filter, queryParams, sort, sumRows, }: GetGenericModelListProps) => Promise<false | DataSchemaColumnsType>;
|
|
81
82
|
export declare const getGenericModel: ({ model, serverEndPoint, id, relatedModel, relatedModelId, }: {
|
|
82
83
|
model: string;
|
|
83
84
|
serverEndPoint: serverEndPointType | null;
|
package/dist/api.js
CHANGED
|
@@ -529,7 +529,7 @@ const signUp = (data, serverEndPoint) => __awaiter(void 0, void 0, void 0, funct
|
|
|
529
529
|
}
|
|
530
530
|
});
|
|
531
531
|
exports.signUp = signUp;
|
|
532
|
-
const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = '', relatedModelId = '', columnFields, hiddenFields = ['id'], creatableFields = [], isInBatches = false, loadedSchema, loadedModelOptions, page, filter, sort, sumRows, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
532
|
+
const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = '', relatedModelId = '', columnFields, hiddenFields = ['id'], creatableFields = [], isInBatches = false, loadedSchema, loadedModelOptions, page, filter, queryParams = [], sort, sumRows, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
533
533
|
let path = `${model}/${id}`;
|
|
534
534
|
let schemaPath = `${model}/`;
|
|
535
535
|
let schema = loadedSchema;
|
|
@@ -542,7 +542,6 @@ const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = ''
|
|
|
542
542
|
}
|
|
543
543
|
schemaPath += `${id}/${relatedModel}/`;
|
|
544
544
|
}
|
|
545
|
-
const queryParams = [];
|
|
546
545
|
// SERVER-SIDE TOTALS (sumRows):
|
|
547
546
|
if (sumRows) {
|
|
548
547
|
const sumRowsParams = sumRows.rows.map((row) => row.field).join(',');
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { GridFilterModel } from '@mui/x-data-grid';
|
|
2
3
|
import { GridEnrichedBySchemaColDef, Id, Item } from '../utils';
|
|
3
4
|
import { SumRowsType } from '../api';
|
|
4
5
|
interface GenericRelatedModelListProps {
|
|
@@ -22,6 +23,8 @@ interface GenericRelatedModelListProps {
|
|
|
22
23
|
indexFieldBasePath?: string;
|
|
23
24
|
noCardWrapper?: boolean;
|
|
24
25
|
LinkComponent?: React.ReactNode;
|
|
26
|
+
paginationMode: 'server' | 'client';
|
|
27
|
+
defaultFilter?: GridFilterModel;
|
|
25
28
|
}
|
|
26
|
-
export default function GenericRelatedModelList({ id, model, relatedModel, columnFields, creatableFields, hiddenFields, usuaria, minWidthFields, indexField, addExistingModel, label, onProcessRow, sumRows, customColumnOperations, isEditable, isAutoHeight, isInBatches, indexFieldBasePath, noCardWrapper, }: GenericRelatedModelListProps): JSX.Element;
|
|
29
|
+
export default function GenericRelatedModelList({ id, model, relatedModel, columnFields, creatableFields, hiddenFields, usuaria, minWidthFields, indexField, addExistingModel, label, onProcessRow, sumRows, customColumnOperations, isEditable, isAutoHeight, isInBatches, indexFieldBasePath, noCardWrapper, paginationMode, defaultFilter, }: GenericRelatedModelListProps): JSX.Element;
|
|
27
30
|
export {};
|
|
@@ -43,18 +43,24 @@ const CardContent_1 = __importDefault(require("@mui/material/CardContent"));
|
|
|
43
43
|
const DataGridBySchemaEditable_1 = __importDefault(require("./DataGridBySchemaEditable"));
|
|
44
44
|
const DataTotals_1 = __importDefault(require("./DataTotals"));
|
|
45
45
|
const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
46
|
+
const utils_1 = require("../utils");
|
|
46
47
|
const api_1 = require("../api");
|
|
47
48
|
const styles_1 = require("../styles");
|
|
48
|
-
const ContentTable = ({ data, relatedModel, model, id, indexField, indexFieldBasePath, addExistingModel, isEditable, onEditModel, finalCustomColumnOperations, setVisibleRows, isAutoHeight, hideFooterPagination, onProcessRow, setData, sumRows, visibleRows, }) => (react_1.default.createElement(react_1.default.Fragment, null,
|
|
49
|
+
const ContentTable = ({ data, relatedModel, model, id, indexField, indexFieldBasePath, addExistingModel, isEditable, onEditModel, finalCustomColumnOperations, setVisibleRows, isAutoHeight, hideFooterPagination, onProcessRow, setData, sumRows, visibleRows, paginationMode = 'client', paginationModel, setPaginationModel, }) => (react_1.default.createElement(react_1.default.Fragment, null,
|
|
49
50
|
data.columns && (react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.dataGridFixedHeight },
|
|
50
51
|
react_1.default.createElement(DataGridBySchemaEditable_1.default, { data: data.data, columns: data.columns, schema: data.schema, model: relatedModel, modelParent: model, modelParentId: id, indexField: indexField, indexFieldBasePath: indexFieldBasePath, addExistingModel: addExistingModel, isEditable: isEditable, onEditModel: onEditModel, customColumnOperations: finalCustomColumnOperations, setVisibleRows: setVisibleRows, isAutoHeight: isAutoHeight, hideFooterPagination: hideFooterPagination, onProcessRow: onProcessRow, onDataChange: (newData) => {
|
|
51
52
|
setData(Object.assign(Object.assign({}, data), { data: newData }));
|
|
52
|
-
}
|
|
53
|
+
}, paginationModel: paginationMode === 'server' ? paginationModel : undefined, setPaginationModel: paginationMode === 'server' ? setPaginationModel : undefined, rowCount: paginationMode === 'client'
|
|
54
|
+
? undefined
|
|
55
|
+
: typeof data.rowCount !== undefined
|
|
56
|
+
? data.rowCount
|
|
57
|
+
: 0 }))),
|
|
53
58
|
react_1.default.createElement(DataTotals_1.default, { data: data.data, sumRows: sumRows, visibleRows: visibleRows })));
|
|
54
|
-
function GenericRelatedModelList({ id, model, relatedModel, columnFields, creatableFields, hiddenFields, usuaria = null, minWidthFields, indexField, addExistingModel, label, onProcessRow, sumRows, customColumnOperations, isEditable = true, isAutoHeight = false, isInBatches = true, indexFieldBasePath, noCardWrapper = false, }) {
|
|
59
|
+
function GenericRelatedModelList({ id, model, relatedModel, columnFields, creatableFields, hiddenFields, usuaria = null, minWidthFields, indexField, addExistingModel, label, onProcessRow, sumRows, customColumnOperations, isEditable = true, isAutoHeight = false, isInBatches = true, indexFieldBasePath, noCardWrapper = false, paginationMode = 'client', defaultFilter, }) {
|
|
55
60
|
const [data, setData] = (0, react_1.useState)(false);
|
|
56
61
|
const [visibleRows, setVisibleRows] = (0, react_1.useState)([]);
|
|
57
62
|
const [hideFooterPagination, setHideFooterPagination] = (0, react_1.useState)(false);
|
|
63
|
+
const [paginationModel, setPaginationModel] = (0, react_1.useState)(paginationMode === 'server' ? { page: 0, pageSize: 100 } : undefined);
|
|
58
64
|
const { onEditModel, onDeleteRelatedModel, serverEndPoint } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
59
65
|
const finalCustomColumnOperations = (column) => {
|
|
60
66
|
if (minWidthFields) {
|
|
@@ -68,40 +74,72 @@ function GenericRelatedModelList({ id, model, relatedModel, columnFields, creata
|
|
|
68
74
|
return column;
|
|
69
75
|
};
|
|
70
76
|
const loadObjectList = () => __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
77
|
+
switch (paginationMode) {
|
|
78
|
+
case 'client':
|
|
79
|
+
const loadParams = {
|
|
80
|
+
model,
|
|
81
|
+
id,
|
|
82
|
+
relatedModel,
|
|
83
|
+
indexFieldBasePath,
|
|
84
|
+
columnFields,
|
|
85
|
+
creatableFields,
|
|
86
|
+
hiddenFields,
|
|
87
|
+
usuaria,
|
|
88
|
+
isInBatches,
|
|
89
|
+
serverEndPoint,
|
|
90
|
+
};
|
|
91
|
+
const loadedData = yield (0, api_1.getGenericModelList)(loadParams);
|
|
92
|
+
if (loadedData && typeof loadedData !== 'boolean') {
|
|
93
|
+
setData(loadedData);
|
|
94
|
+
if (isInBatches && loadedData.data.length === 100) {
|
|
95
|
+
setHideFooterPagination(true);
|
|
96
|
+
(0, api_1.getGenericModelList)(Object.assign(Object.assign({}, loadParams), { loadedSchema: loadedData.schema })).then((lastBatchData) => {
|
|
97
|
+
if (lastBatchData) {
|
|
98
|
+
setData(Object.assign(Object.assign({}, loadedData), { data: [...loadedData.data, ...lastBatchData.data] }));
|
|
99
|
+
setHideFooterPagination(false);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
92
102
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
console.log('error retrieving data!');
|
|
106
|
+
break;
|
|
107
|
+
case 'server':
|
|
108
|
+
const page = paginationModel ? paginationModel.page : 0;
|
|
109
|
+
const filter = (0, utils_1.mergeFilterItems)(defaultFilter, paginationModel ? paginationModel.filter : undefined);
|
|
110
|
+
const sort = paginationModel ? paginationModel.sort : undefined;
|
|
111
|
+
const loadPaginatedParams = {
|
|
112
|
+
model,
|
|
113
|
+
id,
|
|
114
|
+
relatedModel,
|
|
115
|
+
columnFields,
|
|
116
|
+
hiddenFields,
|
|
117
|
+
page,
|
|
118
|
+
filter,
|
|
119
|
+
sort,
|
|
120
|
+
sumRows,
|
|
121
|
+
serverEndPoint,
|
|
122
|
+
};
|
|
123
|
+
const paginatedData = yield (0, api_1.getGenericModelList)(loadPaginatedParams);
|
|
124
|
+
if (paginatedData && typeof paginatedData !== 'boolean') {
|
|
125
|
+
setData(paginatedData);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
console.log('error retrieving data!');
|
|
129
|
+
break;
|
|
96
130
|
}
|
|
97
|
-
console.log('error retrieving data!');
|
|
98
131
|
});
|
|
99
132
|
(0, react_1.useEffect)(() => {
|
|
100
133
|
loadObjectList();
|
|
101
|
-
}, []);
|
|
102
|
-
|
|
134
|
+
}, [model, defaultFilter]);
|
|
135
|
+
(0, react_1.useEffect)(() => {
|
|
136
|
+
if (paginationMode === 'server') {
|
|
137
|
+
loadObjectList();
|
|
138
|
+
}
|
|
139
|
+
}, [paginationModel]);
|
|
140
|
+
return (react_1.default.createElement(react_1.default.Fragment, null, typeof data !== 'boolean' && data.columns && (react_1.default.createElement(react_1.default.Fragment, null, noCardWrapper ? (react_1.default.createElement(ContentTable, { data: data, model: model, relatedModel: relatedModel, id: id, indexField: indexField || '', indexFieldBasePath: indexFieldBasePath, addExistingModel: addExistingModel, isEditable: isEditable, onEditModel: onEditModel, onDeleteRelatedModel: onDeleteRelatedModel, finalCustomColumnOperations: finalCustomColumnOperations, setVisibleRows: setVisibleRows, isAutoHeight: isAutoHeight, hideFooterPagination: hideFooterPagination, onProcessRow: onProcessRow, setData: setData, sumRows: sumRows, visibleRows: visibleRows, paginationMode: paginationMode, paginationModel: paginationModel, setPaginationModel: setPaginationModel })) : (react_1.default.createElement(Card_1.default, { sx: styles_1.Layout.formCard },
|
|
103
141
|
react_1.default.createElement(CardHeader_1.default, { title: label }),
|
|
104
142
|
react_1.default.createElement(CardContent_1.default, null,
|
|
105
|
-
react_1.default.createElement(ContentTable, { data: data, model: model, relatedModel: relatedModel, id: id, indexField: indexField || '', indexFieldBasePath: indexFieldBasePath, addExistingModel: addExistingModel, isEditable: isEditable, onEditModel: onEditModel, onDeleteRelatedModel: onDeleteRelatedModel, finalCustomColumnOperations: finalCustomColumnOperations, setVisibleRows: setVisibleRows, isAutoHeight: isAutoHeight, hideFooterPagination: hideFooterPagination, onProcessRow: onProcessRow, setData: setData, sumRows: sumRows, visibleRows: visibleRows }))))))));
|
|
143
|
+
react_1.default.createElement(ContentTable, { data: data, model: model, relatedModel: relatedModel, id: id, indexField: indexField || '', indexFieldBasePath: indexFieldBasePath, addExistingModel: addExistingModel, isEditable: isEditable, onEditModel: onEditModel, onDeleteRelatedModel: onDeleteRelatedModel, finalCustomColumnOperations: finalCustomColumnOperations, setVisibleRows: setVisibleRows, isAutoHeight: isAutoHeight, hideFooterPagination: hideFooterPagination, onProcessRow: onProcessRow, setData: setData, sumRows: sumRows, visibleRows: visibleRows, paginationMode: paginationMode, paginationModel: paginationModel, setPaginationModel: setPaginationModel }))))))));
|
|
106
144
|
}
|
|
107
145
|
exports.default = GenericRelatedModelList;
|
package/package.json
CHANGED