drf-react-by-schema 0.6.5 → 0.7.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/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 -7
- package/dist/components/DialogActions.d.ts +3 -3
- package/dist/components/DialogActions.js +2 -4
- 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 +7 -10
- 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/styles/theme.js +77 -42
- 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
|
/**
|
|
@@ -74,9 +74,7 @@ const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
|
74
74
|
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, 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", "sx", "isAutoHeight", "defaultValues", "hideFooterPagination", "setVisibleRows", "paginationModel", "setPaginationModel"]);
|
|
77
|
-
const { serverEndPoint } = DRFReactBySchemaContext_1.
|
|
78
|
-
? react_1.default.useContext(DRFReactBySchemaContext_1.DRFReactBySchemaContext)
|
|
79
|
-
: { serverEndPoint: null };
|
|
77
|
+
const { serverEndPoint } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
80
78
|
const apiContext = react_1.default.useContext(APIWrapperContext_1.APIWrapperContext);
|
|
81
79
|
const initialSnackBar = {
|
|
82
80
|
open: false,
|
|
@@ -147,13 +145,13 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
147
145
|
const isInEditMode = ((_a = rowModesModel[id]) === null || _a === void 0 ? void 0 : _a.mode) === x_data_grid_1.GridRowModes.Edit;
|
|
148
146
|
if (isInEditMode) {
|
|
149
147
|
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" }),
|
|
148
|
+
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: false }),
|
|
149
|
+
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: false }),
|
|
152
150
|
];
|
|
153
151
|
}
|
|
154
152
|
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" }),
|
|
153
|
+
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: false }),
|
|
154
|
+
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: false }),
|
|
157
155
|
];
|
|
158
156
|
},
|
|
159
157
|
});
|
|
@@ -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
|
-
;
|
|
@@ -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 {};
|
|
@@ -0,0 +1,164 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
35
|
+
var t = {};
|
|
36
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
37
|
+
t[p] = s[p];
|
|
38
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
39
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
40
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
41
|
+
t[p[i]] = s[p[i]];
|
|
42
|
+
}
|
|
43
|
+
return t;
|
|
44
|
+
};
|
|
45
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
46
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
47
|
+
};
|
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
const react_1 = __importStar(require("react"));
|
|
50
|
+
const Box_1 = __importDefault(require("@mui/material/Box"));
|
|
51
|
+
const Card_1 = __importDefault(require("@mui/material/Card"));
|
|
52
|
+
const CardHeader_1 = __importDefault(require("@mui/material/CardHeader"));
|
|
53
|
+
const CardContent_1 = __importDefault(require("@mui/material/CardContent"));
|
|
54
|
+
const CircularProgress_1 = __importDefault(require("@mui/material/CircularProgress"));
|
|
55
|
+
const FieldBySchema_1 = __importDefault(require("./FieldBySchema"));
|
|
56
|
+
const styles_1 = require("../../styles");
|
|
57
|
+
const APIWrapperContext_1 = require("../../context/APIWrapperContext");
|
|
58
|
+
function FormBySchema(_a) {
|
|
59
|
+
var { schema, control, errors, register, multiline = false, setValue, getValues, fieldKey, labelKey = 'nome', index, optionsAC, setOptionsAC, forceReload, optionsModel, getOptionLabel, renderOption, onEditModel, sx = { mr: 0 }, options, isSemaphoric = false, label, onValueChange, decimalScale = 2, fieldsLayout: fieldsLayoutInitial, hiddenFields = [], isolatedGetAutoComplete } = _a, props = __rest(_a, ["schema", "control", "errors", "register", "multiline", "setValue", "getValues", "fieldKey", "labelKey", "index", "optionsAC", "setOptionsAC", "forceReload", "optionsModel", "getOptionLabel", "renderOption", "onEditModel", "sx", "options", "isSemaphoric", "label", "onValueChange", "decimalScale", "fieldsLayout", "hiddenFields", "isolatedGetAutoComplete"]);
|
|
60
|
+
const { getAutoComplete } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
61
|
+
const [fieldsLayout, setFieldsLayout] = (0, react_1.useState)([]);
|
|
62
|
+
const [localOptionsAC, setLocalOptionsAC] = (0, react_1.useState)(undefined);
|
|
63
|
+
const getColumns = () => {
|
|
64
|
+
const optionsACModels = [];
|
|
65
|
+
if (fieldsLayoutInitial && fieldsLayoutInitial.length > 0) {
|
|
66
|
+
for (const section of fieldsLayoutInitial) {
|
|
67
|
+
if (!section.rows) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
for (const row of section.rows) {
|
|
71
|
+
if (typeof row === 'string') {
|
|
72
|
+
const field = row;
|
|
73
|
+
if (['field', 'nested object'].includes(schema[field].type) &&
|
|
74
|
+
!optionsACModels.includes(field)) {
|
|
75
|
+
optionsACModels.push(field);
|
|
76
|
+
}
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
for (const field of row) {
|
|
80
|
+
if (['field', 'nested object'].includes(schema[field].type) &&
|
|
81
|
+
!optionsACModels.includes(field)) {
|
|
82
|
+
optionsACModels.push(field);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return { newFieldsLayout: fieldsLayoutInitial, optionsACModels };
|
|
88
|
+
}
|
|
89
|
+
const rows = [];
|
|
90
|
+
for (const [key, field] of Object.entries(schema)) {
|
|
91
|
+
if (['field', 'nested object'].includes(field.type)) {
|
|
92
|
+
rows.push(key);
|
|
93
|
+
if (!optionsACModels.includes(key)) {
|
|
94
|
+
optionsACModels.push(key);
|
|
95
|
+
}
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (!field.read_only) {
|
|
99
|
+
rows.push(key);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return { newFieldsLayout: [{ rows }], optionsACModels };
|
|
103
|
+
};
|
|
104
|
+
const populateOptionsAC = (optionsACModels) => __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
const newOptionsAC = {};
|
|
106
|
+
for (const model of optionsACModels) {
|
|
107
|
+
const ret = isolatedGetAutoComplete
|
|
108
|
+
? yield isolatedGetAutoComplete(model)
|
|
109
|
+
: yield getAutoComplete(model);
|
|
110
|
+
if (ret !== false) {
|
|
111
|
+
newOptionsAC[model] = ret;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (setOptionsAC) {
|
|
115
|
+
setOptionsAC(newOptionsAC);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
setLocalOptionsAC(newOptionsAC);
|
|
119
|
+
});
|
|
120
|
+
(0, react_1.useEffect)(() => {
|
|
121
|
+
const { newFieldsLayout, optionsACModels } = getColumns();
|
|
122
|
+
setFieldsLayout(newFieldsLayout);
|
|
123
|
+
populateOptionsAC(optionsACModels);
|
|
124
|
+
}, []);
|
|
125
|
+
(0, react_1.useEffect)(() => {
|
|
126
|
+
if (forceReload) {
|
|
127
|
+
const { newFieldsLayout, optionsACModels } = getColumns();
|
|
128
|
+
setFieldsLayout(newFieldsLayout);
|
|
129
|
+
populateOptionsAC(optionsACModels);
|
|
130
|
+
}
|
|
131
|
+
}, [forceReload]);
|
|
132
|
+
if (fieldsLayout.length === 0 ||
|
|
133
|
+
(setOptionsAC && !optionsAC) ||
|
|
134
|
+
(!setOptionsAC && !localOptionsAC)) {
|
|
135
|
+
return (react_1.default.createElement(Card_1.default, { sx: styles_1.Layout.formCard },
|
|
136
|
+
react_1.default.createElement(CardContent_1.default, null,
|
|
137
|
+
react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.loadingBoxWhite },
|
|
138
|
+
react_1.default.createElement(CircularProgress_1.default, null)))));
|
|
139
|
+
}
|
|
140
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
141
|
+
register &&
|
|
142
|
+
hiddenFields.map((hiddenField) => (react_1.default.createElement("input", Object.assign({ hidden: true }, register(hiddenField), { value: getValues ? getValues(hiddenField) : null, key: hiddenField })))),
|
|
143
|
+
fieldsLayout.map((section, sectionIndex) => {
|
|
144
|
+
return (react_1.default.createElement(Card_1.default, { sx: styles_1.Layout.formCard, key: `section_${sectionIndex}` },
|
|
145
|
+
section.title && react_1.default.createElement(CardHeader_1.default, { title: section.title }),
|
|
146
|
+
react_1.default.createElement(CardContent_1.default, null,
|
|
147
|
+
section.CustomElement && react_1.default.createElement(react_1.default.Fragment, null, section.CustomElement),
|
|
148
|
+
section.rows && (react_1.default.createElement(react_1.default.Fragment, null, section.rows.map((row, rowIndex) => {
|
|
149
|
+
if (typeof row === 'string') {
|
|
150
|
+
const field = row;
|
|
151
|
+
return (react_1.default.createElement(react_1.default.Fragment, { key: field },
|
|
152
|
+
react_1.default.createElement(FieldBySchema_1.default, Object.assign({ name: field, schema: schema, control: control, errors: errors, multiline: multiline, setValue: setValue, getValues: getValues, fieldKey: fieldKey, labelKey: labelKey, index: index, optionsAC: setOptionsAC
|
|
153
|
+
? optionsAC
|
|
154
|
+
: localOptionsAC, optionsModel: optionsModel, getOptionLabel: getOptionLabel, renderOption: renderOption, onEditModel: onEditModel, sx: sx, options: options, isSemaphoric: isSemaphoric, label: label, onValueChange: onValueChange, decimalScale: decimalScale }, props))));
|
|
155
|
+
}
|
|
156
|
+
return (react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.inLineForm, key: `row_${rowIndex}` },
|
|
157
|
+
react_1.default.createElement(react_1.default.Fragment, null, row.map((field, i, j) => (react_1.default.createElement(react_1.default.Fragment, { key: field },
|
|
158
|
+
react_1.default.createElement(FieldBySchema_1.default, Object.assign({ name: field, schema: schema, control: control, errors: errors, multiline: multiline, setValue: setValue, getValues: getValues, fieldKey: fieldKey, labelKey: labelKey, index: index, optionsAC: optionsAC, optionsModel: optionsModel, getOptionLabel: getOptionLabel, renderOption: renderOption, onEditModel: onEditModel, sx: {
|
|
159
|
+
mr: i + 1 === j.length ? 0 : 2,
|
|
160
|
+
}, options: options, isSemaphoric: isSemaphoric, label: label, onValueChange: onValueChange, decimalScale: decimalScale }, props))))))));
|
|
161
|
+
}))))));
|
|
162
|
+
})));
|
|
163
|
+
}
|
|
164
|
+
exports.default = FormBySchema;
|