drf-react-by-schema 0.8.11 → 0.9.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/dist/api.d.ts +4 -0
- package/dist/api.js +63 -27
- package/dist/components/DataGridBySchemaEditable.js +13 -1
- package/dist/components/GenericModelList.d.ts +8 -4
- package/dist/components/GenericModelList.js +7 -11
- package/dist/components/GenericRelatedModelList.d.ts +5 -6
- package/dist/components/GenericRelatedModelList.js +2 -2
- package/dist/context/APIWrapper.js +28 -1
- package/dist/context/APIWrapperContext.d.ts +8 -0
- package/dist/context/APIWrapperContext.js +2 -0
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ interface TargetApiParamsOptionalId {
|
|
|
15
15
|
data: Item;
|
|
16
16
|
id?: Id;
|
|
17
17
|
}
|
|
18
|
+
export declare const getRawData: ({ path, serverEndPoint, }: {
|
|
19
|
+
path: string;
|
|
20
|
+
serverEndPoint: serverEndPointType | null;
|
|
21
|
+
}) => Promise<any>;
|
|
18
22
|
/**
|
|
19
23
|
*
|
|
20
24
|
* @param options - params
|
package/dist/api.js
CHANGED
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getAllModels = exports.getGenericModel = exports.getGenericModelList = exports.signUp = exports.getSignUpOptions = exports.isLoggedIn = exports.setAuthToken = exports.hasJWT = exports.clearJWT = exports.loginByPayload = exports.getAutoComplete = exports.addExistingRelatedModel = exports.updateDataBySchema = exports.createOrUpdateData = exports.deleteData = exports.createData = exports.partialUpdateData = exports.updateData = void 0;
|
|
15
|
+
exports.getAllModels = exports.getGenericModel = exports.getGenericModelList = exports.signUp = exports.getSignUpOptions = exports.isLoggedIn = exports.setAuthToken = exports.hasJWT = exports.clearJWT = exports.loginByPayload = exports.getAutoComplete = exports.addExistingRelatedModel = exports.updateDataBySchema = exports.createOrUpdateData = exports.deleteData = exports.createData = exports.partialUpdateData = exports.updateData = exports.getRawData = void 0;
|
|
16
16
|
const axios_1 = __importDefault(require("axios"));
|
|
17
17
|
const moment_1 = __importDefault(require("moment"));
|
|
18
18
|
const utils_1 = require("./utils");
|
|
@@ -77,11 +77,45 @@ const getSchema = (path, serverEndPoint) => __awaiter(void 0, void 0, void 0, fu
|
|
|
77
77
|
delete modelOptions.actions;
|
|
78
78
|
return { schema: options.actions.POST, modelOptions };
|
|
79
79
|
});
|
|
80
|
-
const
|
|
80
|
+
const getRawData = ({ path, serverEndPoint, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
81
|
var _b;
|
|
82
82
|
if (!serverEndPoint) {
|
|
83
83
|
return false;
|
|
84
84
|
}
|
|
85
|
+
const url = `${serverEndPoint.api}/${path}`;
|
|
86
|
+
try {
|
|
87
|
+
const { data } = yield axios_1.default.get(url);
|
|
88
|
+
return data;
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
if (axios_1.default.isAxiosError(e)) {
|
|
92
|
+
const err = e;
|
|
93
|
+
if (((_b = err.response) === null || _b === void 0 ? void 0 : _b.status) === 401) {
|
|
94
|
+
const isRefreshed = yield refreshToken(serverEndPoint);
|
|
95
|
+
if (!isRefreshed) {
|
|
96
|
+
console.log('Token expirou! Deve-se fazer login de novo');
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const { data } = yield axios_1.default.get(url);
|
|
101
|
+
return data;
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
console.log(`Error fetching data from ${url} after token refresh`, e);
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
console.log(`Error fetching data from ${url}`, e);
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
exports.getRawData = getRawData;
|
|
114
|
+
const getData = ({ path, serverEndPoint, route = 'api', page, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
115
|
+
var _c;
|
|
116
|
+
if (!serverEndPoint) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
85
119
|
const url = `${serverEndPoint[route]}/${path}`;
|
|
86
120
|
try {
|
|
87
121
|
const { data } = yield axios_1.default.get(url);
|
|
@@ -90,7 +124,7 @@ const getData = ({ path, serverEndPoint, route = 'api', page, }) => __awaiter(vo
|
|
|
90
124
|
catch (e) {
|
|
91
125
|
if (axios_1.default.isAxiosError(e)) {
|
|
92
126
|
const err = e;
|
|
93
|
-
if (((
|
|
127
|
+
if (((_c = err.response) === null || _c === void 0 ? void 0 : _c.status) === 401) {
|
|
94
128
|
const isRefreshed = yield refreshToken(serverEndPoint);
|
|
95
129
|
if (!isRefreshed) {
|
|
96
130
|
console.log('Token expirou! Deve-se fazer login de novo');
|
|
@@ -116,7 +150,7 @@ const getData = ({ path, serverEndPoint, route = 'api', page, }) => __awaiter(vo
|
|
|
116
150
|
* @returns Id when succesfully updated, false otherwise
|
|
117
151
|
*/
|
|
118
152
|
const updateData = ({ path, serverEndPoint, data, id }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
119
|
-
var
|
|
153
|
+
var _d, _e, _f;
|
|
120
154
|
if (!serverEndPoint) {
|
|
121
155
|
return { errors: 'Não há definição de API (serverEndPoint!' };
|
|
122
156
|
}
|
|
@@ -127,7 +161,7 @@ const updateData = ({ path, serverEndPoint, data, id }) => __awaiter(void 0, voi
|
|
|
127
161
|
catch (e) {
|
|
128
162
|
if (axios_1.default.isAxiosError(e)) {
|
|
129
163
|
const err = e;
|
|
130
|
-
if (((
|
|
164
|
+
if (((_d = err.response) === null || _d === void 0 ? void 0 : _d.status) === 401) {
|
|
131
165
|
const isRefreshed = yield refreshToken(serverEndPoint);
|
|
132
166
|
if (!isRefreshed) {
|
|
133
167
|
console.log('Token expirou! Deve-se fazer login de novo');
|
|
@@ -142,15 +176,15 @@ const updateData = ({ path, serverEndPoint, data, id }) => __awaiter(void 0, voi
|
|
|
142
176
|
}
|
|
143
177
|
return id;
|
|
144
178
|
}
|
|
145
|
-
console.log(`Error updating data at ${url}`, data, (
|
|
146
|
-
return { errors: (
|
|
179
|
+
console.log(`Error updating data at ${url}`, data, (_e = err.response) === null || _e === void 0 ? void 0 : _e.data);
|
|
180
|
+
return { errors: (_f = err.response) === null || _f === void 0 ? void 0 : _f.data };
|
|
147
181
|
}
|
|
148
182
|
}
|
|
149
183
|
return id;
|
|
150
184
|
});
|
|
151
185
|
exports.updateData = updateData;
|
|
152
186
|
const partialUpdateData = ({ path, serverEndPoint, data, id }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
153
|
-
var
|
|
187
|
+
var _g, _h, _j, _k, _l;
|
|
154
188
|
if (!serverEndPoint) {
|
|
155
189
|
return { errors: 'Não há definição de API (serverEndPoint!' };
|
|
156
190
|
}
|
|
@@ -162,30 +196,30 @@ const partialUpdateData = ({ path, serverEndPoint, data, id }) => __awaiter(void
|
|
|
162
196
|
catch (e) {
|
|
163
197
|
if (axios_1.default.isAxiosError(e)) {
|
|
164
198
|
const err = e;
|
|
165
|
-
if (((
|
|
199
|
+
if (((_g = err.response) === null || _g === void 0 ? void 0 : _g.status) === 401) {
|
|
166
200
|
const isRefreshed = yield refreshToken(serverEndPoint);
|
|
167
201
|
if (!isRefreshed) {
|
|
168
202
|
console.log('Token expirou! Deve-se fazer login de novo');
|
|
169
|
-
return { errors: (
|
|
203
|
+
return { errors: (_h = err.response) === null || _h === void 0 ? void 0 : _h.data };
|
|
170
204
|
}
|
|
171
205
|
try {
|
|
172
206
|
yield axios_1.default.patch(url, data);
|
|
173
207
|
}
|
|
174
208
|
catch (e) {
|
|
175
209
|
console.log(`Error partial updating data at ${url}`, data, e);
|
|
176
|
-
return { errors: (
|
|
210
|
+
return { errors: (_j = err.response) === null || _j === void 0 ? void 0 : _j.data };
|
|
177
211
|
}
|
|
178
212
|
return id;
|
|
179
213
|
}
|
|
180
|
-
console.log(`Error partial updating data at ${url}`, data, (
|
|
181
|
-
return { errors: (
|
|
214
|
+
console.log(`Error partial updating data at ${url}`, data, (_k = err.response) === null || _k === void 0 ? void 0 : _k.data);
|
|
215
|
+
return { errors: (_l = err.response) === null || _l === void 0 ? void 0 : _l.data };
|
|
182
216
|
}
|
|
183
217
|
}
|
|
184
218
|
return id;
|
|
185
219
|
});
|
|
186
220
|
exports.partialUpdateData = partialUpdateData;
|
|
187
221
|
const createData = ({ path, serverEndPoint, data }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
188
|
-
var
|
|
222
|
+
var _m, _o, _p;
|
|
189
223
|
if (!serverEndPoint) {
|
|
190
224
|
return { errors: 'Não há definição de API (serverEndPoint!' };
|
|
191
225
|
}
|
|
@@ -197,7 +231,7 @@ const createData = ({ path, serverEndPoint, data }) => __awaiter(void 0, void 0,
|
|
|
197
231
|
catch (e) {
|
|
198
232
|
if (axios_1.default.isAxiosError(e)) {
|
|
199
233
|
const err = e;
|
|
200
|
-
if (((
|
|
234
|
+
if (((_m = err.response) === null || _m === void 0 ? void 0 : _m.status) === 401) {
|
|
201
235
|
const isRefreshed = yield refreshToken(serverEndPoint);
|
|
202
236
|
if (!isRefreshed) {
|
|
203
237
|
console.log('Token expirou! Deve-se fazer login de novo');
|
|
@@ -212,15 +246,15 @@ const createData = ({ path, serverEndPoint, data }) => __awaiter(void 0, void 0,
|
|
|
212
246
|
}
|
|
213
247
|
return ret;
|
|
214
248
|
}
|
|
215
|
-
console.log(`Error creating data at ${url}`, data, (
|
|
216
|
-
return { errors: (
|
|
249
|
+
console.log(`Error creating data at ${url}`, data, (_o = err.response) === null || _o === void 0 ? void 0 : _o.data);
|
|
250
|
+
return { errors: (_p = err.response) === null || _p === void 0 ? void 0 : _p.data };
|
|
217
251
|
}
|
|
218
252
|
}
|
|
219
253
|
return ret;
|
|
220
254
|
});
|
|
221
255
|
exports.createData = createData;
|
|
222
256
|
const deleteData = (path, serverEndPoint, id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
223
|
-
var
|
|
257
|
+
var _q;
|
|
224
258
|
if (!serverEndPoint) {
|
|
225
259
|
console.log('Não há definição de API (serverEndPoint!');
|
|
226
260
|
return false;
|
|
@@ -232,7 +266,7 @@ const deleteData = (path, serverEndPoint, id) => __awaiter(void 0, void 0, void
|
|
|
232
266
|
catch (e) {
|
|
233
267
|
if (axios_1.default.isAxiosError(e)) {
|
|
234
268
|
const err = e;
|
|
235
|
-
if (((
|
|
269
|
+
if (((_q = err.response) === null || _q === void 0 ? void 0 : _q.status) === 401) {
|
|
236
270
|
const isRefreshed = yield refreshToken(serverEndPoint);
|
|
237
271
|
if (!isRefreshed) {
|
|
238
272
|
console.log('Token expirou! Deve-se fazer login de novo');
|
|
@@ -336,12 +370,6 @@ const prepareDataBySchema = ({ data, schema }) => {
|
|
|
336
370
|
return dbData;
|
|
337
371
|
};
|
|
338
372
|
const updateDataBySchema = ({ model, modelObjectId, serverEndPoint, data, schema, path = null, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
339
|
-
/*console.log({
|
|
340
|
-
model,
|
|
341
|
-
modelObjectId,
|
|
342
|
-
data,
|
|
343
|
-
schema
|
|
344
|
-
});*/
|
|
345
373
|
const dbData = prepareDataBySchema({ data, schema });
|
|
346
374
|
if (!path) {
|
|
347
375
|
path = model;
|
|
@@ -353,6 +381,14 @@ const updateDataBySchema = ({ model, modelObjectId, serverEndPoint, data, schema
|
|
|
353
381
|
data: dbData,
|
|
354
382
|
id: modelObjectId,
|
|
355
383
|
});
|
|
384
|
+
/*console.log({
|
|
385
|
+
model,
|
|
386
|
+
modelObjectId,
|
|
387
|
+
data,
|
|
388
|
+
schema,
|
|
389
|
+
dbData,
|
|
390
|
+
response,
|
|
391
|
+
});*/
|
|
356
392
|
if (typeof response !== 'object' && parseInt(response)) {
|
|
357
393
|
return response;
|
|
358
394
|
}
|
|
@@ -495,7 +531,7 @@ const getSignUpOptions = (serverEndPoint) => __awaiter(void 0, void 0, void 0, f
|
|
|
495
531
|
});
|
|
496
532
|
exports.getSignUpOptions = getSignUpOptions;
|
|
497
533
|
const signUp = (data, serverEndPoint) => __awaiter(void 0, void 0, void 0, function* () {
|
|
498
|
-
var
|
|
534
|
+
var _r;
|
|
499
535
|
if (!serverEndPoint || !serverEndPoint.signUp) {
|
|
500
536
|
return false;
|
|
501
537
|
}
|
|
@@ -508,7 +544,7 @@ const signUp = (data, serverEndPoint) => __awaiter(void 0, void 0, void 0, funct
|
|
|
508
544
|
catch (e) {
|
|
509
545
|
if (axios_1.default.isAxiosError(e)) {
|
|
510
546
|
const err = e;
|
|
511
|
-
if (((
|
|
547
|
+
if (((_r = err.response) === null || _r === void 0 ? void 0 : _r.status) === 401) {
|
|
512
548
|
const isRefreshed = yield refreshToken(serverEndPoint);
|
|
513
549
|
if (!isRefreshed) {
|
|
514
550
|
console.log('Token expirou! Deve-se fazer login de novo');
|
|
@@ -75,7 +75,7 @@ const stringMask = require('string-mask');
|
|
|
75
75
|
const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
76
76
|
var { schema, data, rowCount = 0, columns, model, fieldKey, labelKey = 'nome', index, name = Math.floor(Math.random() * 1000000).toString(), indexField = 'nome', addExistingModel, indexFieldMinWidth = 350, indexFieldBasePath = '', stateToLink = {}, minWidth = 80, modelParent, modelParentId, customColumnOperations, customLinkDestination, LinkComponent, onProcessRow, onDataChange, onEditModel, isEditable = false, hasBulkSelect = false, sx = { mr: 2 }, isAutoHeight = false, defaultValues = {}, hideFooterPagination = false, setVisibleRows, paginationModel = undefined, setPaginationModel = undefined } = _a, other = __rest(_a, ["schema", "data", "rowCount", "columns", "model", "fieldKey", "labelKey", "index", "name", "indexField", "addExistingModel", "indexFieldMinWidth", "indexFieldBasePath", "stateToLink", "minWidth", "modelParent", "modelParentId", "customColumnOperations", "customLinkDestination", "LinkComponent", "onProcessRow", "onDataChange", "onEditModel", "isEditable", "hasBulkSelect", "sx", "isAutoHeight", "defaultValues", "hideFooterPagination", "setVisibleRows", "paginationModel", "setPaginationModel"]);
|
|
77
77
|
const { serverEndPoint } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
78
|
-
const apiContext =
|
|
78
|
+
const apiContext = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
79
79
|
const initialSnackBar = {
|
|
80
80
|
open: false,
|
|
81
81
|
msg: '',
|
|
@@ -513,8 +513,20 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
513
513
|
setDataGridLoading(false);
|
|
514
514
|
return newRow;
|
|
515
515
|
}
|
|
516
|
+
setDataGridLoading(false);
|
|
517
|
+
return false;
|
|
516
518
|
}
|
|
519
|
+
const response = yield apiContext.onEditModelDataGridSave({
|
|
520
|
+
model,
|
|
521
|
+
id: newRow.id,
|
|
522
|
+
newRow,
|
|
523
|
+
schema,
|
|
524
|
+
});
|
|
517
525
|
setDataGridLoading(false);
|
|
526
|
+
if (response) {
|
|
527
|
+
newRow.id = response;
|
|
528
|
+
return newRow;
|
|
529
|
+
}
|
|
518
530
|
return false;
|
|
519
531
|
});
|
|
520
532
|
const customPaddings = isAutoHeight
|
|
@@ -3,17 +3,21 @@ import { GridFilterModel } from '@mui/x-data-grid';
|
|
|
3
3
|
import { GridEnrichedBySchemaColDef } from '../utils';
|
|
4
4
|
import { SumRowsType } from '../api';
|
|
5
5
|
interface GenericModelListProps {
|
|
6
|
+
model: string;
|
|
6
7
|
columnFields: string[];
|
|
7
8
|
hiddenFields?: string[];
|
|
9
|
+
creatableFields?: string[];
|
|
8
10
|
minWidthFields?: Record<string, number>;
|
|
9
|
-
indexFieldBasePath: string;
|
|
10
11
|
indexField: string;
|
|
11
|
-
|
|
12
|
+
indexFieldBasePath: string;
|
|
13
|
+
addExistingModel?: string;
|
|
14
|
+
onProcessRow?: (p: any) => void;
|
|
12
15
|
customColumnOperations?: (column: GridEnrichedBySchemaColDef) => GridEnrichedBySchemaColDef;
|
|
13
16
|
customLinkDestination?: (p: any) => string;
|
|
17
|
+
isEditable?: boolean;
|
|
18
|
+
hasBulkSelect?: boolean;
|
|
14
19
|
sumRows?: SumRowsType;
|
|
15
20
|
isAutoHeight?: boolean;
|
|
16
|
-
model: string;
|
|
17
21
|
forceReload: boolean;
|
|
18
22
|
LinkComponent?: any | null;
|
|
19
23
|
hasHeader: boolean;
|
|
@@ -21,5 +25,5 @@ interface GenericModelListProps {
|
|
|
21
25
|
defaultFilter?: GridFilterModel;
|
|
22
26
|
queryParams?: string[];
|
|
23
27
|
}
|
|
24
|
-
declare const GenericModelList: ({ columnFields, hiddenFields, minWidthFields, indexFieldBasePath,
|
|
28
|
+
declare const GenericModelList: ({ model, columnFields, hiddenFields, creatableFields, minWidthFields, indexField, indexFieldBasePath, addExistingModel, onProcessRow, customColumnOperations, customLinkDestination, isEditable, hasBulkSelect, sumRows, isAutoHeight, forceReload, LinkComponent, hasHeader, paginationMode, defaultFilter, queryParams, }: GenericModelListProps) => JSX.Element;
|
|
25
29
|
export default GenericModelList;
|
|
@@ -48,15 +48,9 @@ const utils_1 = require("../utils");
|
|
|
48
48
|
const api_1 = require("../api");
|
|
49
49
|
const DRFReactBySchemaContext_1 = require("../context/DRFReactBySchemaContext");
|
|
50
50
|
const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
51
|
-
const GenericModelList = ({ columnFields, hiddenFields = [],
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
if (!apiContext) {
|
|
55
|
-
console.log('ERRO: É necessário haver o apiContext para gerar este componente!');
|
|
56
|
-
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
57
|
-
}
|
|
58
|
-
const { serverEndPoint, isInBatches, firstBatchLength } = context;
|
|
59
|
-
const { handleLoading } = apiContext;
|
|
51
|
+
const GenericModelList = ({ model, columnFields, hiddenFields = [], creatableFields, minWidthFields, indexField, indexFieldBasePath, addExistingModel, onProcessRow, customColumnOperations, customLinkDestination, isEditable, hasBulkSelect = false, sumRows, isAutoHeight = true, forceReload = false, LinkComponent = null, hasHeader = false, paginationMode = 'client', defaultFilter, queryParams, }) => {
|
|
52
|
+
const { serverEndPoint, isInBatches, firstBatchLength } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
53
|
+
const { onEditModel, handleLoading } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
60
54
|
const [data, setData] = (0, react_1.useState)(false);
|
|
61
55
|
const [visibleRows, setVisibleRows] = (0, react_1.useState)([]);
|
|
62
56
|
const [hideFooterPagination, setHideFooterPagination] = (0, react_1.useState)(false);
|
|
@@ -81,6 +75,7 @@ const GenericModelList = ({ columnFields, hiddenFields = [], minWidthFields, ind
|
|
|
81
75
|
serverEndPoint,
|
|
82
76
|
columnFields,
|
|
83
77
|
hiddenFields,
|
|
78
|
+
creatableFields,
|
|
84
79
|
isInBatches,
|
|
85
80
|
queryParams,
|
|
86
81
|
};
|
|
@@ -110,6 +105,7 @@ const GenericModelList = ({ columnFields, hiddenFields = [], minWidthFields, ind
|
|
|
110
105
|
serverEndPoint,
|
|
111
106
|
columnFields,
|
|
112
107
|
hiddenFields,
|
|
108
|
+
creatableFields,
|
|
113
109
|
page,
|
|
114
110
|
filter,
|
|
115
111
|
queryParams,
|
|
@@ -137,7 +133,7 @@ const GenericModelList = ({ columnFields, hiddenFields = [], minWidthFields, ind
|
|
|
137
133
|
loadObjectList();
|
|
138
134
|
}
|
|
139
135
|
}, [paginationModel]);
|
|
140
|
-
if (!
|
|
136
|
+
if (!serverEndPoint) {
|
|
141
137
|
console.error('Error: There is no endpoint defined in DRFReactBySchemaProvider!');
|
|
142
138
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
143
139
|
}
|
|
@@ -148,7 +144,7 @@ const GenericModelList = ({ columnFields, hiddenFields = [], minWidthFields, ind
|
|
|
148
144
|
react_1.default.createElement(LinkComponent, { to: `novo` },
|
|
149
145
|
react_1.default.createElement(Button_1.default, { variant: "contained", size: "medium", sx: { alignSelf: 'stretch' }, startIcon: react_1.default.createElement(AddCircleOutline_1.default, null) }, "Adicionar")))))),
|
|
150
146
|
react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.dataGridWithTabs },
|
|
151
|
-
react_1.default.createElement(DataGridBySchemaEditable_1.default, { data: data.data, columns: data.columns, schema: data.schema || {}, model: model, indexField: indexField, indexFieldBasePath: indexFieldBasePath, isEditable:
|
|
147
|
+
react_1.default.createElement(DataGridBySchemaEditable_1.default, { data: data.data, columns: data.columns, schema: data.schema || {}, model: model, indexField: indexField, indexFieldBasePath: indexFieldBasePath, addExistingModel: addExistingModel, isEditable: isEditable, hasBulkSelect: hasBulkSelect, onEditModel: onEditModel, isAutoHeight: isAutoHeight, customColumnOperations: finalCustomColumnOperations, setVisibleRows: setVisibleRows, hideFooterPagination: hideFooterPagination, customLinkDestination: customLinkDestination, onProcessRow: onProcessRow, onDataChange: (newData) => {
|
|
152
148
|
setData(Object.assign(Object.assign({}, data), { data: newData }));
|
|
153
149
|
}, LinkComponent: LinkComponent, paginationModel: paginationMode === 'server' ? paginationModel : undefined, setPaginationModel: paginationMode === 'server' ? setPaginationModel : undefined, rowCount: paginationMode === 'client'
|
|
154
150
|
? undefined
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { GridFilterModel } from '@mui/x-data-grid';
|
|
3
3
|
import { GridEnrichedBySchemaColDef, Id, Item } from '../utils';
|
|
4
4
|
import { SumRowsType } from '../api';
|
|
@@ -7,26 +7,25 @@ interface GenericRelatedModelListProps {
|
|
|
7
7
|
id: Id;
|
|
8
8
|
relatedModel: string;
|
|
9
9
|
columnFields: string[];
|
|
10
|
-
creatableFields: string[];
|
|
11
10
|
hiddenFields: string[];
|
|
11
|
+
creatableFields: string[];
|
|
12
12
|
usuaria?: Item | null;
|
|
13
13
|
minWidthFields?: Record<string, number>;
|
|
14
14
|
indexField?: string;
|
|
15
|
+
indexFieldBasePath?: string;
|
|
15
16
|
addExistingModel?: string;
|
|
16
17
|
label: string;
|
|
17
18
|
onProcessRow?: (p: any) => void;
|
|
18
|
-
sumRows?: SumRowsType;
|
|
19
19
|
customColumnOperations?: (column: GridEnrichedBySchemaColDef) => GridEnrichedBySchemaColDef;
|
|
20
20
|
isEditable?: boolean;
|
|
21
21
|
hasBulkSelect?: boolean;
|
|
22
|
+
sumRows?: SumRowsType;
|
|
22
23
|
isAutoHeight?: boolean;
|
|
23
24
|
isInBatches?: boolean;
|
|
24
|
-
indexFieldBasePath?: string;
|
|
25
25
|
noCardWrapper?: boolean;
|
|
26
|
-
LinkComponent?: React.ReactNode;
|
|
27
26
|
paginationMode: 'server' | 'client';
|
|
28
27
|
defaultFilter?: GridFilterModel;
|
|
29
28
|
queryParams?: string[];
|
|
30
29
|
}
|
|
31
|
-
export default function GenericRelatedModelList({
|
|
30
|
+
export default function GenericRelatedModelList({ model, id, relatedModel, columnFields, hiddenFields, creatableFields, usuaria, minWidthFields, indexField, indexFieldBasePath, addExistingModel, label, onProcessRow, customColumnOperations, isEditable, hasBulkSelect, sumRows, isAutoHeight, isInBatches, noCardWrapper, paginationMode, defaultFilter, queryParams, }: GenericRelatedModelListProps): JSX.Element;
|
|
32
31
|
export {};
|
|
@@ -48,7 +48,7 @@ const api_1 = require("../api");
|
|
|
48
48
|
const styles_1 = require("../styles");
|
|
49
49
|
const ContentTable = ({ data, relatedModel, model, id, indexField, indexFieldBasePath, addExistingModel, isEditable, onEditModel, finalCustomColumnOperations, setVisibleRows, isAutoHeight, hideFooterPagination, onProcessRow, setData, sumRows, visibleRows, paginationMode = 'client', paginationModel, setPaginationModel, hasBulkSelect, }) => (react_1.default.createElement(react_1.default.Fragment, null,
|
|
50
50
|
data.columns && (react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.dataGridFixedHeight },
|
|
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, hasBulkSelect: hasBulkSelect, onEditModel: onEditModel, customColumnOperations: finalCustomColumnOperations, setVisibleRows: setVisibleRows,
|
|
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, hasBulkSelect: hasBulkSelect, onEditModel: onEditModel, isAutoHeight: isAutoHeight, customColumnOperations: finalCustomColumnOperations, setVisibleRows: setVisibleRows, hideFooterPagination: hideFooterPagination, onProcessRow: onProcessRow, onDataChange: (newData) => {
|
|
52
52
|
setData(Object.assign(Object.assign({}, data), { data: newData }));
|
|
53
53
|
}, paginationModel: paginationMode === 'server' ? paginationModel : undefined, setPaginationModel: paginationMode === 'server' ? setPaginationModel : undefined, rowCount: paginationMode === 'client'
|
|
54
54
|
? undefined
|
|
@@ -56,7 +56,7 @@ const ContentTable = ({ data, relatedModel, model, id, indexField, indexFieldBas
|
|
|
56
56
|
? data.rowCount
|
|
57
57
|
: 0 }))),
|
|
58
58
|
react_1.default.createElement(DataTotals_1.default, { data: data.data, sumRows: sumRows, visibleRows: visibleRows })));
|
|
59
|
-
function GenericRelatedModelList({
|
|
59
|
+
function GenericRelatedModelList({ model, id, relatedModel, columnFields, hiddenFields, creatableFields, usuaria = null, minWidthFields, indexField, indexFieldBasePath, addExistingModel, label, onProcessRow, customColumnOperations, isEditable = true, hasBulkSelect = false, sumRows, isAutoHeight = false, isInBatches = true, noCardWrapper = false, paginationMode = 'client', defaultFilter, queryParams, }) {
|
|
60
60
|
const [data, setData] = (0, react_1.useState)(false);
|
|
61
61
|
const [visibleRows, setVisibleRows] = (0, react_1.useState)([]);
|
|
62
62
|
const [hideFooterPagination, setHideFooterPagination] = (0, react_1.useState)(false);
|
|
@@ -201,6 +201,28 @@ function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, childre
|
|
|
201
201
|
}
|
|
202
202
|
handleLoading(false);
|
|
203
203
|
});
|
|
204
|
+
const onEditModelDataGridSave = ({ model, newRow, schema, }) => __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
const response = yield (0, api_1.updateDataBySchema)({
|
|
206
|
+
model,
|
|
207
|
+
modelObjectId: newRow.id,
|
|
208
|
+
serverEndPoint,
|
|
209
|
+
data: newRow,
|
|
210
|
+
schema,
|
|
211
|
+
path: model,
|
|
212
|
+
});
|
|
213
|
+
if (response && !Object.prototype.hasOwnProperty.call(response, 'errors')) {
|
|
214
|
+
onTriggerSnackBar({
|
|
215
|
+
msg: 'Alterações salvas com sucesso!',
|
|
216
|
+
severity: 'info',
|
|
217
|
+
});
|
|
218
|
+
return response;
|
|
219
|
+
}
|
|
220
|
+
onTriggerSnackBar({
|
|
221
|
+
msg: 'Não foi possível salvar os dados. Confira os erros.',
|
|
222
|
+
severity: 'error',
|
|
223
|
+
});
|
|
224
|
+
return false;
|
|
225
|
+
});
|
|
204
226
|
const onEditModel = ({ fieldKey, index, model, id, labelKey, setValue, getValues, }) => {
|
|
205
227
|
setDialog({
|
|
206
228
|
open: true,
|
|
@@ -352,6 +374,9 @@ function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, childre
|
|
|
352
374
|
console.error('There must be a serverEndPoint properly configured for apiWrapper to work!');
|
|
353
375
|
return react_1.default.createElement(react_1.default.Fragment, null, children);
|
|
354
376
|
}
|
|
377
|
+
function localGetRawData(route) {
|
|
378
|
+
return (0, api_1.getRawData)({ path: route, serverEndPoint });
|
|
379
|
+
}
|
|
355
380
|
function localGetAutoComplete(model) {
|
|
356
381
|
return (0, api_1.getAutoComplete)({ model, serverEndPoint });
|
|
357
382
|
}
|
|
@@ -360,7 +385,7 @@ function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, childre
|
|
|
360
385
|
}
|
|
361
386
|
function localGetAllModels() {
|
|
362
387
|
return __awaiter(this, void 0, void 0, function* () {
|
|
363
|
-
return yield (0, api_1.getAllModels)(serverEndPoint);
|
|
388
|
+
return (yield (0, api_1.getAllModels)(serverEndPoint));
|
|
364
389
|
});
|
|
365
390
|
}
|
|
366
391
|
function localLoginByPayload(payload) {
|
|
@@ -388,12 +413,14 @@ function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, childre
|
|
|
388
413
|
pageFormState: [pageForm, setPageForm],
|
|
389
414
|
onEditModel,
|
|
390
415
|
onEditModelSave,
|
|
416
|
+
onEditModelDataGridSave,
|
|
391
417
|
onDeleteModel,
|
|
392
418
|
onEditRelatedModelSave,
|
|
393
419
|
onDeleteRelatedModel,
|
|
394
420
|
onTriggerSnackBar,
|
|
395
421
|
setDialog,
|
|
396
422
|
// api utils:
|
|
423
|
+
getRawData: localGetRawData,
|
|
397
424
|
getAutoComplete: localGetAutoComplete,
|
|
398
425
|
getGenericModelList: localGetGenericModelList,
|
|
399
426
|
getAllModels: localGetAllModels,
|
|
@@ -40,6 +40,12 @@ export interface OnEditRelatedModelType {
|
|
|
40
40
|
schema: SchemaType;
|
|
41
41
|
onlyAddExisting: boolean;
|
|
42
42
|
}
|
|
43
|
+
export interface onEditModelDataGridSaveType {
|
|
44
|
+
model: string;
|
|
45
|
+
id: Id;
|
|
46
|
+
newRow: Item;
|
|
47
|
+
schema: SchemaType;
|
|
48
|
+
}
|
|
43
49
|
export interface OnDeleteRelatedModelType {
|
|
44
50
|
model: string;
|
|
45
51
|
id: Id;
|
|
@@ -68,12 +74,14 @@ export interface APIWrapperContextType {
|
|
|
68
74
|
optionsACState: [OptionsACType | null, (x: Partial<OptionsACType>) => void];
|
|
69
75
|
pageFormState: [PageFormType | null, (x: Partial<PageFormType>) => void];
|
|
70
76
|
onEditModel: (p: OnEditModelType) => void;
|
|
77
|
+
onEditModelDataGridSave: (p: onEditModelDataGridSaveType) => Promise<false | Id>;
|
|
71
78
|
onEditModelSave: (p: Item) => Promise<false | undefined>;
|
|
72
79
|
onDeleteModel: (model: string, id: Id, onSuccess?: (e: React.BaseSyntheticEvent) => any) => void;
|
|
73
80
|
onEditRelatedModelSave: (p: OnEditRelatedModelType) => Promise<boolean | Id | ItemSchemaColumnsType>;
|
|
74
81
|
onDeleteRelatedModel: (p: OnDeleteRelatedModelType) => Promise<boolean>;
|
|
75
82
|
onTriggerSnackBar: (p: SnackBarType) => void;
|
|
76
83
|
setDialog: (x: Partial<DialogType>) => void;
|
|
84
|
+
getRawData: (route: string) => Promise<false | any>;
|
|
77
85
|
getAutoComplete: (model: string) => Promise<false | Item[]>;
|
|
78
86
|
getGenericModelList: (x: Omit<GetGenericModelListProps, 'serverEndPoint'>) => Promise<false | DataSchemaColumnsType>;
|
|
79
87
|
getAllModels: () => Promise<Item[]>;
|
|
@@ -23,6 +23,7 @@ exports.APIWrapperContext = react_1.default.createContext({
|
|
|
23
23
|
optionsACState: [null, () => undefined],
|
|
24
24
|
pageFormState: [null, () => undefined],
|
|
25
25
|
onEditModel: () => undefined,
|
|
26
|
+
onEditModelDataGridSave: () => __awaiter(void 0, void 0, void 0, function* () { return false; }),
|
|
26
27
|
onEditModelSave: () => __awaiter(void 0, void 0, void 0, function* () { return undefined; }),
|
|
27
28
|
onDeleteModel: () => undefined,
|
|
28
29
|
onEditRelatedModelSave: () => __awaiter(void 0, void 0, void 0, function* () { return false; }),
|
|
@@ -30,6 +31,7 @@ exports.APIWrapperContext = react_1.default.createContext({
|
|
|
30
31
|
onTriggerSnackBar: () => undefined,
|
|
31
32
|
setDialog: () => undefined,
|
|
32
33
|
// api utils:
|
|
34
|
+
getRawData: () => __awaiter(void 0, void 0, void 0, function* () { return undefined; }),
|
|
33
35
|
getAutoComplete: () => __awaiter(void 0, void 0, void 0, function* () { return []; }),
|
|
34
36
|
getGenericModelList: () => __awaiter(void 0, void 0, void 0, function* () { return false; }),
|
|
35
37
|
getAllModels: () => __awaiter(void 0, void 0, void 0, function* () { return []; }),
|
package/package.json
CHANGED