drf-react-by-schema 0.6.4 → 0.7.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 +7 -13
- package/dist/api.js +77 -77
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts +1 -1
- package/dist/components/DataGridBySchemaEditable.js +5 -5
- package/dist/components/DialogActions.d.ts +3 -3
- package/dist/components/DialogActions.js +2 -4
- package/dist/components/GenericModelList.js +4 -0
- package/dist/components/forms/DialogFormBySchema.d.ts +14 -0
- package/dist/components/forms/DialogFormBySchema.js +61 -0
- package/dist/components/forms/FieldBySchema.d.ts +3 -0
- package/dist/components/forms/FieldBySchema.js +65 -0
- package/dist/components/forms/FormBySchema.d.ts +19 -0
- package/dist/components/forms/FormBySchema.js +164 -0
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts +3 -0
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.js +86 -0
- package/dist/components/forms/inputs/BooleanFieldBySchema.d.ts +3 -0
- package/dist/components/forms/inputs/BooleanFieldBySchema.js +41 -0
- package/dist/components/forms/inputs/DesktopDatePickerBySchema.d.ts +3 -0
- package/dist/components/forms/inputs/DesktopDatePickerBySchema.js +49 -0
- package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.d.ts +3 -0
- package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.js +41 -0
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts +4 -0
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.js +203 -0
- package/dist/components/forms/inputs/FloatFieldBySchema.d.ts +3 -0
- package/dist/components/forms/inputs/FloatFieldBySchema.js +60 -0
- package/dist/components/forms/inputs/TextFieldBySchema.d.ts +3 -0
- package/dist/components/forms/inputs/TextFieldBySchema.js +44 -0
- package/dist/context/APIWrapper.d.ts +5 -5
- package/dist/context/APIWrapper.js +135 -87
- package/dist/context/APIWrapperContext.d.ts +22 -9
- package/dist/context/APIWrapperContext.js +42 -9
- package/dist/context/DRFReactBySchemaContext.d.ts +4 -4
- package/dist/context/DRFReactBySchemaContext.js +5 -5
- package/dist/context/DRFReactBySchemaProvider.d.ts +1 -1
- package/dist/context/DRFReactBySchemaProvider.js +6 -9
- package/dist/context/Form.d.ts +1 -1
- package/dist/context/Form.js +13 -14
- package/dist/context/FormContext.js +0 -7
- package/dist/context/Overlays.js +11 -12
- package/dist/index.d.ts +16 -6
- package/dist/index.js +31 -7
- package/dist/styles/layout.d.ts +7 -0
- package/dist/styles/layout.js +2 -1
- package/dist/utils.d.ts +42 -4
- package/dist/utils.js +22 -18
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -43,21 +43,14 @@ export declare const getAutoComplete: ({ model, serverEndPoint, }: {
|
|
|
43
43
|
model: string;
|
|
44
44
|
serverEndPoint: serverEndPointType | null;
|
|
45
45
|
}) => Promise<false | Item[]>;
|
|
46
|
-
export declare const getJSONSchema: ({ model, serverEndPoint, id, }: {
|
|
47
|
-
model: string;
|
|
48
|
-
serverEndPoint: serverEndPointType | null;
|
|
49
|
-
id?: Id | undefined;
|
|
50
|
-
}) => Promise<any>;
|
|
51
|
-
export declare const createOrUpdateJSONSchema: ({ model, serverEndPoint, id, formData, }: {
|
|
52
|
-
model: string;
|
|
53
|
-
serverEndPoint: serverEndPointType | null;
|
|
54
|
-
id?: Id | undefined;
|
|
55
|
-
formData: Item;
|
|
56
|
-
}) => Promise<any>;
|
|
57
46
|
export declare const loginByPayload: (payload: Item, serverEndPoint: serverEndPointType | null) => Promise<boolean>;
|
|
47
|
+
export declare const clearJWT: () => boolean;
|
|
48
|
+
export declare const hasJWT: () => boolean;
|
|
58
49
|
export declare const setAuthToken: (token: string | null) => void;
|
|
59
50
|
export declare const isLoggedIn: (serverEndPoint: serverEndPointType | null) => Promise<false | Item[] | PaginatedResult>;
|
|
60
|
-
export
|
|
51
|
+
export declare const getSignUpOptions: (serverEndPoint: serverEndPointType | null) => Promise<false | SchemaType>;
|
|
52
|
+
export declare const signUp: (data: Item, serverEndPoint: serverEndPointType | null) => Promise<any>;
|
|
53
|
+
export interface GetGenericModelListProps {
|
|
61
54
|
model: string;
|
|
62
55
|
serverEndPoint: serverEndPointType | null;
|
|
63
56
|
id?: Id;
|
|
@@ -84,7 +77,7 @@ interface SumRowsItem {
|
|
|
84
77
|
suffix?: string;
|
|
85
78
|
isCount?: boolean;
|
|
86
79
|
}
|
|
87
|
-
export declare const getGenericModelList: ({ model, serverEndPoint, id, relatedModel, relatedModelId, columnFields, hiddenFields, creatableFields, isInBatches, loadedSchema, loadedModelOptions, page, filter, sort, sumRows, }:
|
|
80
|
+
export declare const getGenericModelList: ({ model, serverEndPoint, id, relatedModel, relatedModelId, columnFields, hiddenFields, creatableFields, isInBatches, loadedSchema, loadedModelOptions, page, filter, sort, sumRows, }: GetGenericModelListProps) => Promise<false | DataSchemaColumnsType>;
|
|
88
81
|
export declare const getGenericModel: ({ model, serverEndPoint, id, relatedModel, relatedModelId, }: {
|
|
89
82
|
model: string;
|
|
90
83
|
serverEndPoint: serverEndPointType | null;
|
|
@@ -92,4 +85,5 @@ export declare const getGenericModel: ({ model, serverEndPoint, id, relatedModel
|
|
|
92
85
|
relatedModel?: string | undefined;
|
|
93
86
|
relatedModelId?: string | undefined;
|
|
94
87
|
}) => Promise<false | ItemSchemaColumnsType>;
|
|
88
|
+
export declare const getAllModels: (serverEndPoint: serverEndPointType | null) => Promise<Item[] | PaginatedResult>;
|
|
95
89
|
export {};
|
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.getGenericModel = exports.getGenericModelList = exports.isLoggedIn = exports.setAuthToken = exports.
|
|
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;
|
|
16
16
|
const axios_1 = __importDefault(require("axios"));
|
|
17
17
|
const moment_1 = __importDefault(require("moment"));
|
|
18
18
|
const utils_1 = require("./utils");
|
|
@@ -395,80 +395,6 @@ const getAutoComplete = ({ model, serverEndPoint, }) => __awaiter(void 0, void 0
|
|
|
395
395
|
return data;
|
|
396
396
|
});
|
|
397
397
|
exports.getAutoComplete = getAutoComplete;
|
|
398
|
-
const getJSONSchema = ({ model, serverEndPoint, id = 'create', }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
399
|
-
var _q;
|
|
400
|
-
if (!serverEndPoint) {
|
|
401
|
-
console.log('Não há definição de API (serverEndPoint!');
|
|
402
|
-
return false;
|
|
403
|
-
}
|
|
404
|
-
const url = `${serverEndPoint.JSONSchema}/${model}/${id}/`;
|
|
405
|
-
try {
|
|
406
|
-
const { data } = yield axios_1.default.get(url);
|
|
407
|
-
return data;
|
|
408
|
-
}
|
|
409
|
-
catch (e) {
|
|
410
|
-
if (axios_1.default.isAxiosError(e)) {
|
|
411
|
-
const err = e;
|
|
412
|
-
if (((_q = err.response) === null || _q === void 0 ? void 0 : _q.status) === 401) {
|
|
413
|
-
const isRefreshed = yield refreshToken(serverEndPoint);
|
|
414
|
-
if (!isRefreshed) {
|
|
415
|
-
console.log('Token expirou! Deve-se fazer login de novo');
|
|
416
|
-
return false;
|
|
417
|
-
}
|
|
418
|
-
try {
|
|
419
|
-
const { data } = yield axios_1.default.get(url);
|
|
420
|
-
return data;
|
|
421
|
-
}
|
|
422
|
-
catch (e) {
|
|
423
|
-
console.log(`Error fetching JSONSchema data from ${url}`, e);
|
|
424
|
-
return false;
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
console.log(`Error fetching JSONSchema data from ${url}`, e);
|
|
428
|
-
return false;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
});
|
|
432
|
-
exports.getJSONSchema = getJSONSchema;
|
|
433
|
-
const createOrUpdateJSONSchema = ({ model, serverEndPoint, id = 'create', formData, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
434
|
-
var _r;
|
|
435
|
-
if (!serverEndPoint) {
|
|
436
|
-
return { errors: 'Não há definição de API (serverEndPoint!' };
|
|
437
|
-
}
|
|
438
|
-
let url = `${serverEndPoint.JSONSchema}/${model}/`;
|
|
439
|
-
if (id !== 'create') {
|
|
440
|
-
url += `${id}/`;
|
|
441
|
-
}
|
|
442
|
-
try {
|
|
443
|
-
const { data } = id === 'create' ? yield axios_1.default.post(url, formData) : yield axios_1.default.patch(url, formData);
|
|
444
|
-
return data;
|
|
445
|
-
}
|
|
446
|
-
catch (e) {
|
|
447
|
-
if (axios_1.default.isAxiosError(e)) {
|
|
448
|
-
const err = e;
|
|
449
|
-
if (((_r = err.response) === null || _r === void 0 ? void 0 : _r.status) === 401) {
|
|
450
|
-
const isRefreshed = yield refreshToken(serverEndPoint);
|
|
451
|
-
if (!isRefreshed) {
|
|
452
|
-
console.log('Token expirou! Deve-se fazer login de novo');
|
|
453
|
-
return { errors: 'Token expirou! Deve-se fazer login de novo!' };
|
|
454
|
-
}
|
|
455
|
-
try {
|
|
456
|
-
const { data } = id === 'create'
|
|
457
|
-
? yield axios_1.default.post(url, formData)
|
|
458
|
-
: yield axios_1.default.patch(url, formData);
|
|
459
|
-
return data;
|
|
460
|
-
}
|
|
461
|
-
catch (e) {
|
|
462
|
-
console.log(`Error partially updating or creating JSONSchema data from ${url}`, e);
|
|
463
|
-
return { errors: 'Erro ao salvar alterações em item!' };
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
console.log(`Error partially updating or creating JSONSchema data from ${url}`, e);
|
|
467
|
-
return { errors: 'Erro ao salvar alterações em item!' };
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
|
-
exports.createOrUpdateJSONSchema = createOrUpdateJSONSchema;
|
|
472
398
|
const loginByPayload = (payload, serverEndPoint) => __awaiter(void 0, void 0, void 0, function* () {
|
|
473
399
|
if (!serverEndPoint) {
|
|
474
400
|
console.log('Não há definição de API (serverEndPoint!');
|
|
@@ -492,6 +418,19 @@ const loginByPayload = (payload, serverEndPoint) => __awaiter(void 0, void 0, vo
|
|
|
492
418
|
}
|
|
493
419
|
});
|
|
494
420
|
exports.loginByPayload = loginByPayload;
|
|
421
|
+
const clearJWT = () => {
|
|
422
|
+
localStorage.removeItem('token');
|
|
423
|
+
return false;
|
|
424
|
+
};
|
|
425
|
+
exports.clearJWT = clearJWT;
|
|
426
|
+
const hasJWT = () => {
|
|
427
|
+
const token = localStorage.getItem('token');
|
|
428
|
+
if (token) {
|
|
429
|
+
return true;
|
|
430
|
+
}
|
|
431
|
+
return false;
|
|
432
|
+
};
|
|
433
|
+
exports.hasJWT = hasJWT;
|
|
495
434
|
const setAuthToken = (token) => {
|
|
496
435
|
if (token) {
|
|
497
436
|
localStorage.setItem('token', token);
|
|
@@ -540,6 +479,56 @@ const isLoggedIn = (serverEndPoint) => __awaiter(void 0, void 0, void 0, functio
|
|
|
540
479
|
return usuaria;
|
|
541
480
|
});
|
|
542
481
|
exports.isLoggedIn = isLoggedIn;
|
|
482
|
+
const getSignUpOptions = (serverEndPoint) => __awaiter(void 0, void 0, void 0, function* () {
|
|
483
|
+
if (!serverEndPoint || !serverEndPoint.signUp) {
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
486
|
+
const url = serverEndPoint.signUp;
|
|
487
|
+
try {
|
|
488
|
+
const { data } = yield axios_1.default.options(url);
|
|
489
|
+
return data.action.POST;
|
|
490
|
+
}
|
|
491
|
+
catch (e) {
|
|
492
|
+
console.log(`Error fetching options from ${url}`, e);
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
exports.getSignUpOptions = getSignUpOptions;
|
|
497
|
+
const signUp = (data, serverEndPoint) => __awaiter(void 0, void 0, void 0, function* () {
|
|
498
|
+
var _q, _r;
|
|
499
|
+
if (!serverEndPoint || !serverEndPoint.signUp) {
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
502
|
+
const url = serverEndPoint.signUp;
|
|
503
|
+
try {
|
|
504
|
+
const response = yield axios_1.default.post(url, data);
|
|
505
|
+
console.log(response);
|
|
506
|
+
return response;
|
|
507
|
+
}
|
|
508
|
+
catch (e) {
|
|
509
|
+
if (axios_1.default.isAxiosError(e)) {
|
|
510
|
+
const err = e;
|
|
511
|
+
if (((_q = err.response) === null || _q === void 0 ? void 0 : _q.status) === 401) {
|
|
512
|
+
const isRefreshed = yield refreshToken(serverEndPoint);
|
|
513
|
+
if (!isRefreshed) {
|
|
514
|
+
console.log('Token expirou! Deve-se fazer login de novo');
|
|
515
|
+
return false;
|
|
516
|
+
}
|
|
517
|
+
try {
|
|
518
|
+
const response = yield axios_1.default.post(url, data);
|
|
519
|
+
return response;
|
|
520
|
+
}
|
|
521
|
+
catch (e) {
|
|
522
|
+
console.log(`Error updating data at ${url}`, data, e);
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
console.log(`Error updating data at ${url}`, data, e.response);
|
|
527
|
+
return { errors: (_r = err.response) === null || _r === void 0 ? void 0 : _r.data };
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
exports.signUp = signUp;
|
|
543
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* () {
|
|
544
533
|
let path = `${model}/${id}`;
|
|
545
534
|
let schemaPath = model;
|
|
@@ -553,12 +542,14 @@ const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = ''
|
|
|
553
542
|
const queryParams = [];
|
|
554
543
|
// SERVER-SIDE TOTALS (sumRows):
|
|
555
544
|
if (sumRows) {
|
|
556
|
-
const sumRowsParams = sumRows.rows.map(row => row.field).join(',');
|
|
545
|
+
const sumRowsParams = sumRows.rows.map((row) => row.field).join(',');
|
|
557
546
|
queryParams.push(`sum_rows=${sumRowsParams}`);
|
|
558
547
|
}
|
|
559
548
|
// SERVER-SIDE FILTERING:
|
|
560
549
|
if (filter) {
|
|
561
|
-
if (filter.quickFilterValues &&
|
|
550
|
+
if (filter.quickFilterValues &&
|
|
551
|
+
filter.quickFilterValues.length > 0 &&
|
|
552
|
+
filter.quickFilterValues[0]) {
|
|
562
553
|
queryParams.push(`search=${filter.quickFilterValues[0]}`);
|
|
563
554
|
}
|
|
564
555
|
for (const item of filter.items) {
|
|
@@ -664,3 +655,12 @@ const getGenericModel = ({ model, serverEndPoint, id = '', relatedModel = '', re
|
|
|
664
655
|
return { schema, modelOptions, data };
|
|
665
656
|
});
|
|
666
657
|
exports.getGenericModel = getGenericModel;
|
|
658
|
+
const getAllModels = (serverEndPoint) => __awaiter(void 0, void 0, void 0, function* () {
|
|
659
|
+
if (!serverEndPoint) {
|
|
660
|
+
return [];
|
|
661
|
+
}
|
|
662
|
+
const path = 'endpoints';
|
|
663
|
+
const data = yield getData({ path, serverEndPoint });
|
|
664
|
+
return data || [];
|
|
665
|
+
});
|
|
666
|
+
exports.getAllModels = getAllModels;
|
|
@@ -11,7 +11,7 @@ interface SelectEditInputCellProps {
|
|
|
11
11
|
optionsAC: React.MutableRefObject<OptionsACType | null>;
|
|
12
12
|
isIndexField: boolean;
|
|
13
13
|
multiple?: boolean;
|
|
14
|
-
onEditModel?: (
|
|
14
|
+
onEditModel?: (x: OnEditModelType) => void;
|
|
15
15
|
sx?: SxProps;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
@@ -147,13 +147,13 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
147
147
|
const isInEditMode = ((_a = rowModesModel[id]) === null || _a === void 0 ? void 0 : _a.mode) === x_data_grid_1.GridRowModes.Edit;
|
|
148
148
|
if (isInEditMode) {
|
|
149
149
|
return [
|
|
150
|
-
react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { key: `save_${id}`, icon: react_1.default.createElement(Check_1.default, null), label: "Salvar", onClick: handleSaveClick(id), color: "success" }),
|
|
151
|
-
react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { key: `cancel_${id}`, icon: react_1.default.createElement(Undo_1.default, null), label: "Cancelar", onClick: handleCancelClick(id), color: "inherit" }),
|
|
150
|
+
react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { key: `save_${id}`, icon: react_1.default.createElement(Check_1.default, null), label: "Salvar", onClick: handleSaveClick(id), color: "success", onResize: () => null, onResizeCapture: () => null, showInMenu: true }),
|
|
151
|
+
react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { key: `cancel_${id}`, icon: react_1.default.createElement(Undo_1.default, null), label: "Cancelar", onClick: handleCancelClick(id), color: "inherit", onResize: () => null, onResizeCapture: () => null, showInMenu: true }),
|
|
152
152
|
];
|
|
153
153
|
}
|
|
154
154
|
return [
|
|
155
|
-
react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { key: `edit_${id}`, icon: react_1.default.createElement(Edit_1.default, null), label: "Edit", onClick: handleEditClick(id), color: "inherit" }),
|
|
156
|
-
react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { key: `remove_${id}`, icon: react_1.default.createElement(Clear_1.default, null), label: "Delete", onClick: handleDeleteClick(id), color: "error" }),
|
|
155
|
+
react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { key: `edit_${id}`, icon: react_1.default.createElement(Edit_1.default, null), label: "Edit", onClick: handleEditClick(id), color: "inherit", onResize: () => null, onResizeCapture: () => null, showInMenu: true }),
|
|
156
|
+
react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { key: `remove_${id}`, icon: react_1.default.createElement(Clear_1.default, null), label: "Delete", onClick: handleDeleteClick(id), color: "error", onResize: () => null, onResizeCapture: () => null, showInMenu: true }),
|
|
157
157
|
];
|
|
158
158
|
},
|
|
159
159
|
});
|
|
@@ -436,7 +436,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
436
436
|
updateOptionsAC().then(() => {
|
|
437
437
|
initColumns();
|
|
438
438
|
});
|
|
439
|
-
}, [rowModesModel]);
|
|
439
|
+
}, [rowModesModel, columns]);
|
|
440
440
|
const processRowUpdate = (newRow) => __awaiter(void 0, void 0, void 0, function* () {
|
|
441
441
|
if (!preparedColumns || !yupValidationSchema.current) {
|
|
442
442
|
return false;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DialogType } from '../context/APIWrapperContext';
|
|
3
3
|
interface DialogActionsProps {
|
|
4
|
-
setDialog:
|
|
5
|
-
handleSave
|
|
4
|
+
setDialog: (x: Partial<DialogType>) => void;
|
|
5
|
+
handleSave?: (e: React.SyntheticEvent) => Promise<boolean>;
|
|
6
6
|
btnCancel?: string;
|
|
7
7
|
btnConfirm?: string;
|
|
8
8
|
}
|
|
9
|
-
export default function DialogActions({ setDialog, handleSave, btnCancel, btnConfirm }: DialogActionsProps): JSX.Element;
|
|
9
|
+
export default function DialogActions({ setDialog, handleSave, btnCancel, btnConfirm, }: DialogActionsProps): JSX.Element;
|
|
10
10
|
export {};
|
|
@@ -5,13 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const react_1 = __importDefault(require("react"));
|
|
7
7
|
const Button_1 = __importDefault(require("@mui/material/Button"));
|
|
8
|
-
|
|
9
|
-
function DialogActions({ setDialog, handleSave, btnCancel = 'Cancelar', btnConfirm = 'Salvar' }) {
|
|
8
|
+
function DialogActions({ setDialog, handleSave, btnCancel = 'Cancelar', btnConfirm = 'Salvar', }) {
|
|
10
9
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
11
10
|
react_1.default.createElement(Button_1.default, { onClick: () => {
|
|
12
11
|
setDialog({ open: false });
|
|
13
12
|
} }, btnCancel),
|
|
14
|
-
react_1.default.createElement(Button_1.default, { onClick: handleSave }, btnConfirm)));
|
|
13
|
+
handleSave && react_1.default.createElement(Button_1.default, { onClick: handleSave }, btnConfirm)));
|
|
15
14
|
}
|
|
16
15
|
exports.default = DialogActions;
|
|
17
|
-
;
|
|
@@ -50,6 +50,10 @@ const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
|
50
50
|
const GenericModelList = ({ columnFields, hiddenFields = [], minWidthFields, indexFieldBasePath, indexField, customColumnOperations, customLinkDestination, sumRows, isAutoHeight = true, model, forceReload = false, LinkComponent = null, hasHeader = false, paginationMode = 'client', }) => {
|
|
51
51
|
const context = react_1.default.useContext(DRFReactBySchemaContext_1.DRFReactBySchemaContext);
|
|
52
52
|
const apiContext = react_1.default.useContext(APIWrapperContext_1.APIWrapperContext);
|
|
53
|
+
if (!apiContext) {
|
|
54
|
+
console.log('ERRO: É necessário haver o apiContext para gerar este componente!');
|
|
55
|
+
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
56
|
+
}
|
|
53
57
|
const { serverEndPoint, isInBatches, firstBatchLength } = context;
|
|
54
58
|
const { handleLoading } = apiContext;
|
|
55
59
|
const [data, setData] = (0, react_1.useState)(false);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { AnyObjectSchema } from 'yup';
|
|
3
|
+
import { Item, SchemaType } from '../../utils';
|
|
4
|
+
import { DialogType } from '../../context/APIWrapperContext';
|
|
5
|
+
interface DialogFormBySchemaProps {
|
|
6
|
+
schema: SchemaType;
|
|
7
|
+
validationSchema: AnyObjectSchema;
|
|
8
|
+
initialValues: Item;
|
|
9
|
+
onEditModelSave: (p: Item) => Promise<false | undefined>;
|
|
10
|
+
setDialog: (x: Partial<DialogType>) => void;
|
|
11
|
+
getAutoComplete: (model: string) => Promise<false | Item[]>;
|
|
12
|
+
}
|
|
13
|
+
export default function DialogFormBySchema({ schema, validationSchema, initialValues, onEditModelSave, setDialog, getAutoComplete, }: DialogFormBySchemaProps): JSX.Element;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const react_1 = __importStar(require("react"));
|
|
30
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
31
|
+
const yup_1 = require("@hookform/resolvers/yup");
|
|
32
|
+
const Box_1 = __importDefault(require("@mui/material/Box"));
|
|
33
|
+
const Button_1 = __importDefault(require("@mui/material/Button"));
|
|
34
|
+
const AdapterMoment_1 = require("@mui/x-date-pickers/AdapterMoment");
|
|
35
|
+
const LocalizationProvider_1 = require("@mui/x-date-pickers/LocalizationProvider");
|
|
36
|
+
const styles_1 = require("../../styles");
|
|
37
|
+
const FormBySchema_1 = __importDefault(require("./FormBySchema"));
|
|
38
|
+
function DialogFormBySchema({ schema, validationSchema, initialValues, onEditModelSave, setDialog, getAutoComplete, }) {
|
|
39
|
+
const { control, handleSubmit, reset, getValues, setValue, formState: { errors, isDirty }, } = (0, react_hook_form_1.useForm)({
|
|
40
|
+
mode: 'onBlur',
|
|
41
|
+
resolver: (0, yup_1.yupResolver)(validationSchema),
|
|
42
|
+
});
|
|
43
|
+
(0, react_1.useEffect)(() => {
|
|
44
|
+
reset(initialValues);
|
|
45
|
+
}, []);
|
|
46
|
+
if (!schema) {
|
|
47
|
+
return react_1.default.createElement(react_1.default.Fragment, null, "Houve um erro ao carregar este formul\u00E1rio!");
|
|
48
|
+
}
|
|
49
|
+
return (react_1.default.createElement(react_1.default.Fragment, null, initialValues && control && (react_1.default.createElement("form", { onSubmit: handleSubmit(onEditModelSave) },
|
|
50
|
+
react_1.default.createElement(LocalizationProvider_1.LocalizationProvider, { dateAdapter: AdapterMoment_1.AdapterMoment },
|
|
51
|
+
react_1.default.createElement(Box_1.default, null,
|
|
52
|
+
react_1.default.createElement(FormBySchema_1.default, { control: control, errors: errors, schema: schema, getValues: getValues, setValue: setValue, isolatedGetAutoComplete: getAutoComplete }))),
|
|
53
|
+
react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.flexRow },
|
|
54
|
+
react_1.default.createElement(Button_1.default, { variant: "contained", color: "primary", size: "small", sx: { ml: 1 }, onClick: () => {
|
|
55
|
+
setDialog({
|
|
56
|
+
open: false,
|
|
57
|
+
});
|
|
58
|
+
} }, "Cancelar"),
|
|
59
|
+
react_1.default.createElement(Button_1.default, { variant: "contained", name: "exitOnSave", disabled: !isDirty, type: "submit", color: "primary", size: "small" }, "Salvar"))))));
|
|
60
|
+
}
|
|
61
|
+
exports.default = DialogFormBySchema;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { FieldBySchemaProps } from '../../utils';
|
|
3
|
+
export default function FieldBySchema({ name, schema, control, errors, multiline, setValue, getValues, fieldKey, labelKey, index, optionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, sx, options, isSemaphoric, label, onValueChange, decimalScale, ...other }: FieldBySchemaProps): JSX.Element;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const react_1 = __importDefault(require("react"));
|
|
18
|
+
const DesktopDatePickerBySchema_1 = __importDefault(require("./inputs/DesktopDatePickerBySchema"));
|
|
19
|
+
const DesktopDateTimePickerBySchema_1 = __importDefault(require("./inputs/DesktopDateTimePickerBySchema"));
|
|
20
|
+
const EditableAutocompleteFieldBySchema_1 = __importDefault(require("./inputs/EditableAutocompleteFieldBySchema"));
|
|
21
|
+
const AutocompleteFieldBySchema_1 = __importDefault(require("./inputs/AutocompleteFieldBySchema"));
|
|
22
|
+
const BooleanFieldBySchema_1 = __importDefault(require("./inputs/BooleanFieldBySchema"));
|
|
23
|
+
const FloatFieldBySchema_1 = __importDefault(require("./inputs/FloatFieldBySchema"));
|
|
24
|
+
const TextFieldBySchema_1 = __importDefault(require("./inputs/TextFieldBySchema"));
|
|
25
|
+
function FieldBySchema(_a) {
|
|
26
|
+
var { name, schema, control, errors, multiline = false, setValue = null, getValues = null, fieldKey, labelKey = 'nome', index, optionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, sx, options, isSemaphoric = false, label, onValueChange, decimalScale = 2 } = _a, other = __rest(_a, ["name", "schema", "control", "errors", "multiline", "setValue", "getValues", "fieldKey", "labelKey", "index", "optionsAC", "optionsModel", "getOptionLabel", "renderOption", "onEditModel", "sx", "options", "isSemaphoric", "label", "onValueChange", "decimalScale"]);
|
|
27
|
+
switch (schema[name].type) {
|
|
28
|
+
case 'date':
|
|
29
|
+
return (react_1.default.createElement(DesktopDatePickerBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, multiline: multiline, fieldKey: fieldKey, index: index, sx: sx }, other)));
|
|
30
|
+
case 'datetime':
|
|
31
|
+
return (react_1.default.createElement(DesktopDateTimePickerBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, multiline: multiline, fieldKey: fieldKey, index: index, sx: sx }, other)));
|
|
32
|
+
// case 'field':
|
|
33
|
+
// return (
|
|
34
|
+
// <AutocompleteFieldBySchema
|
|
35
|
+
// name={name}
|
|
36
|
+
// control={control}
|
|
37
|
+
// schema={schema}
|
|
38
|
+
// errors={errors}
|
|
39
|
+
// options={optionsAC[name] || []}
|
|
40
|
+
// multiple
|
|
41
|
+
// sx={sx}
|
|
42
|
+
// />
|
|
43
|
+
// );
|
|
44
|
+
case 'nested object':
|
|
45
|
+
case 'field':
|
|
46
|
+
const relatedEditable = schema[name].related_editable;
|
|
47
|
+
const multiple = schema[name].many || false;
|
|
48
|
+
return (react_1.default.createElement(EditableAutocompleteFieldBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, setValue: setValue, getValues: getValues, fieldKey: fieldKey, labelKey: labelKey, index: index, optionsAC: optionsAC, optionsModel: optionsModel, getOptionLabel: getOptionLabel, renderOption: renderOption, onEditModel: relatedEditable ? onEditModel : null, multiple: multiple, sx: sx }, other)));
|
|
49
|
+
case 'choice':
|
|
50
|
+
return (react_1.default.createElement(AutocompleteFieldBySchema_1.default, { index: index, name: name, schema: schema, control: control, errors: errors, fieldKey: fieldKey, optionIdKey: "value", optionLabelKey: "display_name", options: options, isSemaphoric: isSemaphoric, label: label, sx: sx }));
|
|
51
|
+
case 'boolean':
|
|
52
|
+
return (react_1.default.createElement(BooleanFieldBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, fieldKey: fieldKey, index: index, sx: sx }, other)));
|
|
53
|
+
case 'decimal':
|
|
54
|
+
case 'float':
|
|
55
|
+
return (react_1.default.createElement(FloatFieldBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, multiline: multiline, fieldKey: fieldKey, index: index, onValueChange: onValueChange, decimalScale: decimalScale, label: label, sx: sx }, other)));
|
|
56
|
+
case 'number':
|
|
57
|
+
case 'integer':
|
|
58
|
+
case 'password':
|
|
59
|
+
default:
|
|
60
|
+
const localMultiline = schema[name].model_multiline === true;
|
|
61
|
+
const minRows = localMultiline ? 3 : 0;
|
|
62
|
+
return (react_1.default.createElement(TextFieldBySchema_1.default, Object.assign({ name: name, schema: schema, control: control, errors: errors, multiline: localMultiline, minRows: minRows, fieldKey: fieldKey, index: index, sx: sx, isPassword: schema[name].type === 'password' }, other)));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.default = FieldBySchema;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { UseFormRegister } from 'react-hook-form';
|
|
3
|
+
import { FieldBySchemaProps, Item } from '../../utils';
|
|
4
|
+
import { OptionsACType } from '../../context/APIWrapperContext';
|
|
5
|
+
interface FieldLayout {
|
|
6
|
+
title?: string;
|
|
7
|
+
rows?: (string | string[])[];
|
|
8
|
+
CustomElement?: React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
interface FormBySchemaProps extends Omit<FieldBySchemaProps, 'name'> {
|
|
11
|
+
fieldsLayout?: FieldLayout[];
|
|
12
|
+
hiddenFields?: string[];
|
|
13
|
+
register?: UseFormRegister<Item>;
|
|
14
|
+
setOptionsAC?: (x: OptionsACType) => void;
|
|
15
|
+
forceReload?: boolean;
|
|
16
|
+
isolatedGetAutoComplete?: (model: string) => Promise<false | Item[]>;
|
|
17
|
+
}
|
|
18
|
+
export default function FormBySchema({ schema, control, errors, register, multiline, setValue, getValues, fieldKey, labelKey, index, optionsAC, setOptionsAC, forceReload, optionsModel, getOptionLabel, renderOption, onEditModel, sx, options, isSemaphoric, label, onValueChange, decimalScale, fieldsLayout: fieldsLayoutInitial, hiddenFields, isolatedGetAutoComplete, ...props }: FormBySchemaProps): JSX.Element;
|
|
19
|
+
export {};
|