drf-react-by-schema 0.15.2 → 0.15.3
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 +16 -22
- package/dist/api.js +253 -144
- package/dist/components/DataGridBySchemaEditable/ConfirmDialog.d.ts +1 -1
- package/dist/components/DataGridBySchemaEditable/CustomToolbar.d.ts +2 -11
- package/dist/components/DataGridBySchemaEditable/CustomToolbar.js +3 -12
- package/dist/components/DataGridBySchemaEditable/FooterToolbar.d.ts +2 -2
- package/dist/components/DataGridBySchemaEditable/GridDateInput.d.ts +2 -2
- package/dist/components/DataGridBySchemaEditable/GridDecimalInput.d.ts +2 -2
- package/dist/components/DataGridBySchemaEditable/GridPatternInput.d.ts +3 -3
- package/dist/components/DataGridBySchemaEditable/GridPatternInput.js +2 -2
- package/dist/components/DataGridBySchemaEditable/InputInterval.d.ts +4 -4
- package/dist/components/DataGridBySchemaEditable/utils.d.ts +2 -2
- package/dist/components/DataGridBySchemaEditable.d.ts +8 -7
- package/dist/components/DataGridBySchemaEditable.js +128 -108
- package/dist/components/DataTotals.d.ts +2 -2
- package/dist/components/DataTotals.js +9 -10
- package/dist/components/DataTotalsServer.d.ts +2 -2
- package/dist/components/DialogActions.d.ts +1 -1
- package/dist/components/FormButtons.d.ts +1 -1
- package/dist/components/GenericModelList.d.ts +8 -8
- package/dist/components/GenericModelList.js +3 -3
- package/dist/components/GenericRelatedModelList.d.ts +6 -6
- package/dist/components/GenericRelatedModelList.js +4 -4
- package/dist/components/details/DetailBySchema.d.ts +2 -2
- package/dist/components/details/DetailFieldBySchema.d.ts +2 -2
- package/dist/components/forms/DialogFormBySchema.d.ts +3 -3
- package/dist/components/forms/FieldBySchema.d.ts +2 -2
- package/dist/components/forms/FormBySchema.d.ts +2 -2
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts +2 -2
- package/dist/components/forms/inputs/BooleanFieldBySchema.d.ts +2 -2
- package/dist/components/forms/inputs/DesktopDatePickerBySchema.d.ts +2 -2
- package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.d.ts +2 -2
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts +2 -1
- package/dist/components/forms/inputs/FloatFieldBySchema.d.ts +2 -2
- package/dist/components/forms/inputs/TextFieldBySchema.d.ts +2 -2
- package/dist/context/APIWrapper.d.ts +1 -1
- package/dist/context/APIWrapper.js +95 -50
- package/dist/context/APIWrapperContext.d.ts +10 -14
- package/dist/context/APIWrapperContext.js +1 -1
- package/dist/context/DRFReactBySchemaProvider.d.ts +1 -1
- package/dist/context/Form.d.ts +1 -1
- package/dist/context/FormContext.d.ts +0 -1
- package/dist/context/Overlays.d.ts +1 -1
- package/dist/styles/layout.d.ts +1 -1
- package/dist/styles/theme.d.ts +1 -1
- package/dist/utils.d.ts +37 -14
- package/package.json +7 -6
- package/dist/components/DialogJSONSchemaForm.d.ts +0 -13
- package/dist/components/DialogJSONSchemaForm.js +0 -20
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { GridRowId } from '@mui/x-data-grid';
|
|
3
3
|
import { Item } from '../utils';
|
|
4
4
|
import { SumRowsType } from '../api';
|
|
@@ -7,5 +7,5 @@ interface DataTotalsProps {
|
|
|
7
7
|
sumRows?: SumRowsType;
|
|
8
8
|
visibleRows: GridRowId[];
|
|
9
9
|
}
|
|
10
|
-
declare const DataTotals: ({ data, sumRows, visibleRows }: DataTotalsProps) => JSX.Element;
|
|
10
|
+
declare const DataTotals: ({ data, sumRows, visibleRows }: DataTotalsProps) => React.JSX.Element;
|
|
11
11
|
export default DataTotals;
|
|
@@ -8,16 +8,15 @@ const Alert_1 = __importDefault(require("@mui/material/Alert"));
|
|
|
8
8
|
const List_1 = __importDefault(require("@mui/material/List"));
|
|
9
9
|
const ListItem_1 = __importDefault(require("@mui/material/ListItem"));
|
|
10
10
|
const react_number_format_1 = require("react-number-format");
|
|
11
|
-
;
|
|
12
11
|
const DataTotals = ({ data, sumRows, visibleRows }) => {
|
|
13
|
-
return (react_1.default.createElement(react_1.default.Fragment, null, data && sumRows && sumRows.rows.length > 0 &&
|
|
14
|
-
react_1.default.createElement(
|
|
15
|
-
react_1.default.createElement(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
return (react_1.default.createElement(react_1.default.Fragment, null, data && sumRows && sumRows.rows.length > 0 && (react_1.default.createElement(Alert_1.default, { severity: sumRows.severity || 'info' },
|
|
13
|
+
react_1.default.createElement(List_1.default, { dense: true }, sumRows.rows.map((row) => (react_1.default.createElement(ListItem_1.default, { key: `sumRows_${row.field}` },
|
|
14
|
+
react_1.default.createElement(react_number_format_1.NumericFormat, { value: data.reduce((total, item) => {
|
|
15
|
+
if (parseFloat(item[row.field]) &&
|
|
16
|
+
visibleRows.includes(`${item.id}`)) {
|
|
17
|
+
return total + parseFloat(item[row.field]);
|
|
18
|
+
}
|
|
19
|
+
return total;
|
|
20
|
+
}, 0), thousandSeparator: ".", decimalSeparator: ",", displayType: 'text', decimalScale: row.isCount ? 0 : 2, fixedDecimalScale: true, prefix: row.prefix, suffix: row.suffix })))))))));
|
|
22
21
|
};
|
|
23
22
|
exports.default = DataTotals;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { SumRowsType } from '../api';
|
|
3
3
|
interface DataTotalsServerProps {
|
|
4
4
|
sumRows?: SumRowsType;
|
|
5
5
|
totals?: null | Record<string, number>;
|
|
6
6
|
}
|
|
7
|
-
declare const DataTotalsServer: ({ sumRows, totals }: DataTotalsServerProps) => JSX.Element;
|
|
7
|
+
declare const DataTotalsServer: ({ sumRows, totals }: DataTotalsServerProps) => React.JSX.Element;
|
|
8
8
|
export default DataTotalsServer;
|
|
@@ -6,5 +6,5 @@ interface DialogActionsProps {
|
|
|
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): React.JSX.Element;
|
|
10
10
|
export {};
|
|
@@ -17,5 +17,5 @@ interface FormButtonsProps {
|
|
|
17
17
|
saveAndContinue?: boolean;
|
|
18
18
|
sx?: any;
|
|
19
19
|
}
|
|
20
|
-
export default function FormButtons({ model, objId, title, formDisabled, cancelBtn, cancelBtnLabel, deleteBtnLabel, saveAndCreateNewBtnLabel, saveAndContinueBtnLabel, saveBtnLabel, onSuccess, bottom, borderBottom, saveAndContinue, sx }: FormButtonsProps): JSX.Element;
|
|
20
|
+
export default function FormButtons({ model, objId, title, formDisabled, cancelBtn, cancelBtnLabel, deleteBtnLabel, saveAndCreateNewBtnLabel, saveAndContinueBtnLabel, saveBtnLabel, onSuccess, bottom, borderBottom, saveAndContinue, sx }: FormButtonsProps): React.JSX.Element;
|
|
21
21
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { GridFilterModel } from '@mui/x-data-grid';
|
|
3
|
-
import { GridEnrichedBySchemaColDef, ActionType, Item, OnSelectActions } from '../utils';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { GridFilterModel, GridRenderCellParams } from '@mui/x-data-grid';
|
|
3
|
+
import { GridEnrichedBySchemaColDef, ActionType, Item, OnSelectActions, OptionsAC } from '../utils';
|
|
4
4
|
import { SumRowsType } from '../api';
|
|
5
5
|
interface GenericModelListProps {
|
|
6
6
|
model: string;
|
|
@@ -13,9 +13,9 @@ interface GenericModelListProps {
|
|
|
13
13
|
indexFieldBasePath: string;
|
|
14
14
|
indexFieldViewBasePath?: string;
|
|
15
15
|
addExistingModel?: string;
|
|
16
|
-
onProcessRow?: (p:
|
|
17
|
-
customColumnOperations?: (column: GridEnrichedBySchemaColDef) => GridEnrichedBySchemaColDef
|
|
18
|
-
customLinkDestination?: (p:
|
|
16
|
+
onProcessRow?: (p: Item) => void;
|
|
17
|
+
customColumnOperations?: (column: GridEnrichedBySchemaColDef) => GridEnrichedBySchemaColDef | Promise<GridEnrichedBySchemaColDef>;
|
|
18
|
+
customLinkDestination?: (p: GridRenderCellParams) => string;
|
|
19
19
|
isEditable?: boolean;
|
|
20
20
|
hasBulkSelect?: boolean;
|
|
21
21
|
onSelectActions?: OnSelectActions[];
|
|
@@ -31,8 +31,8 @@ interface GenericModelListProps {
|
|
|
31
31
|
hideToolbarComponent?: boolean;
|
|
32
32
|
tableAutoHeight?: boolean;
|
|
33
33
|
actions?: Partial<ActionType>[];
|
|
34
|
-
optionsAC?:
|
|
34
|
+
optionsAC?: OptionsAC;
|
|
35
35
|
disableScreenLoading?: boolean;
|
|
36
36
|
}
|
|
37
|
-
declare const GenericModelList: ({ model, columnFields, hiddenFields, creatableFields, disabledFields, minWidthFields, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, onProcessRow, customColumnOperations, customLinkDestination, isEditable, hasBulkSelect, onSelectActions, sumRows, isAutoHeight, forceReload, LinkComponent, hasHeader, paginationMode, defaultFilter, queryParams, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions, optionsAC, disableScreenLoading, }: GenericModelListProps) => JSX.Element;
|
|
37
|
+
declare const GenericModelList: ({ model, columnFields, hiddenFields, creatableFields, disabledFields, minWidthFields, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, onProcessRow, customColumnOperations, customLinkDestination, isEditable, hasBulkSelect, onSelectActions, sumRows, isAutoHeight, forceReload, LinkComponent, hasHeader, paginationMode, defaultFilter, queryParams, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions, optionsAC, disableScreenLoading, }: GenericModelListProps) => React.JSX.Element;
|
|
38
38
|
export default GenericModelList;
|
|
@@ -58,17 +58,17 @@ const GenericModelList = ({ model, columnFields, hiddenFields = [], creatableFie
|
|
|
58
58
|
const [visibleRows, setVisibleRows] = (0, react_1.useState)([]);
|
|
59
59
|
const [hideFooterPagination, setHideFooterPagination] = (0, react_1.useState)(false);
|
|
60
60
|
const [paginationModel, setPaginationModel] = (0, react_1.useState)(paginationMode === 'server' ? { page: 0, pageSize: 100 } : undefined);
|
|
61
|
-
const finalCustomColumnOperations = (column) => {
|
|
61
|
+
const finalCustomColumnOperations = (column) => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
62
|
if (minWidthFields) {
|
|
63
63
|
if (Object.prototype.hasOwnProperty.call(minWidthFields, column.field)) {
|
|
64
64
|
column.minWidth = minWidthFields[column.field];
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
if (customColumnOperations) {
|
|
68
|
-
return customColumnOperations(column);
|
|
68
|
+
return yield customColumnOperations(column);
|
|
69
69
|
}
|
|
70
70
|
return column;
|
|
71
|
-
};
|
|
71
|
+
});
|
|
72
72
|
const loadObjectList = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
73
|
if (!disableScreenLoading) {
|
|
74
74
|
setLoading(true);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { GridFilterModel } from '@mui/x-data-grid';
|
|
3
|
-
import { ActionType, GridEnrichedBySchemaColDef, Id, Item, OnSelectActions } from '../utils';
|
|
3
|
+
import { ActionType, GridEnrichedBySchemaColDef, Id, Item, OnSelectActions, OptionsAC } from '../utils';
|
|
4
4
|
import { SumRowsType } from '../api';
|
|
5
5
|
interface GenericRelatedModelListProps {
|
|
6
6
|
model: string;
|
|
@@ -17,8 +17,8 @@ interface GenericRelatedModelListProps {
|
|
|
17
17
|
indexFieldViewBasePath?: string;
|
|
18
18
|
addExistingModel?: string;
|
|
19
19
|
label: string;
|
|
20
|
-
onProcessRow?: (p:
|
|
21
|
-
customColumnOperations?: (column: GridEnrichedBySchemaColDef) => GridEnrichedBySchemaColDef
|
|
20
|
+
onProcessRow?: (p: Item) => void;
|
|
21
|
+
customColumnOperations?: (column: GridEnrichedBySchemaColDef) => GridEnrichedBySchemaColDef | Promise<GridEnrichedBySchemaColDef>;
|
|
22
22
|
isEditable?: boolean;
|
|
23
23
|
hasBulkSelect?: boolean;
|
|
24
24
|
onSelectActions?: OnSelectActions[];
|
|
@@ -33,7 +33,7 @@ interface GenericRelatedModelListProps {
|
|
|
33
33
|
hideToolbarComponent?: boolean;
|
|
34
34
|
tableAutoHeight?: boolean;
|
|
35
35
|
actions?: Partial<ActionType>[];
|
|
36
|
-
optionsAC?:
|
|
36
|
+
optionsAC?: OptionsAC;
|
|
37
37
|
}
|
|
38
|
-
export default function GenericRelatedModelList({ model, id, relatedModel, columnFields, hiddenFields, creatableFields, disabledFields, usuaria, minWidthFields, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, label, onProcessRow, customColumnOperations, isEditable, hasBulkSelect, onSelectActions, sumRows, isAutoHeight, isInBatches, noCardWrapper, paginationMode, defaultFilter, queryParams, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions, optionsAC, }: GenericRelatedModelListProps): JSX.Element;
|
|
38
|
+
export default function GenericRelatedModelList({ model, id, relatedModel, columnFields, hiddenFields, creatableFields, disabledFields, usuaria, minWidthFields, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, label, onProcessRow, customColumnOperations, isEditable, hasBulkSelect, onSelectActions, sumRows, isAutoHeight, isInBatches, noCardWrapper, paginationMode, defaultFilter, queryParams, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions, optionsAC, }: GenericRelatedModelListProps): React.JSX.Element;
|
|
39
39
|
export {};
|
|
@@ -57,7 +57,7 @@ const ContentTable = ({ data, relatedModel, model, loading, id, indexField, inde
|
|
|
57
57
|
? undefined
|
|
58
58
|
: typeof data.rowCount !== undefined
|
|
59
59
|
? data.rowCount
|
|
60
|
-
: 0 }))) : (react_1.default.createElement(Backdrop_1.default, { invisible: true, sx: { color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1 }, open: loading },
|
|
60
|
+
: 0 }))) : (react_1.default.createElement(Backdrop_1.default, { invisible: true, sx: { color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1 }, open: loading || false },
|
|
61
61
|
react_1.default.createElement(CircularProgress_1.default, null))),
|
|
62
62
|
paginationMode === 'client' ? (react_1.default.createElement(DataTotals_1.default, { data: data.data, sumRows: sumRows, visibleRows: visibleRows })) : (react_1.default.createElement(DataTotalsServer_1.default, { sumRows: sumRows, totals: data.sumRowsTotals }))));
|
|
63
63
|
function GenericRelatedModelList({ model, id, relatedModel, columnFields, hiddenFields, creatableFields, disabledFields, usuaria = null, minWidthFields, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, label, onProcessRow, customColumnOperations, isEditable = true, hasBulkSelect = false, onSelectActions, sumRows, isAutoHeight = false, isInBatches = true, noCardWrapper = false, paginationMode = 'client', defaultFilter, queryParams, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions, optionsAC, }) {
|
|
@@ -67,17 +67,17 @@ function GenericRelatedModelList({ model, id, relatedModel, columnFields, hidden
|
|
|
67
67
|
const [hideFooterPagination, setHideFooterPagination] = (0, react_1.useState)(false);
|
|
68
68
|
const [paginationModel, setPaginationModel] = (0, react_1.useState)(paginationMode === 'server' ? { page: 0, pageSize: 100 } : undefined);
|
|
69
69
|
const { onEditModel, onDeleteRelatedModel, serverEndPoint } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
70
|
-
const finalCustomColumnOperations = (column) => {
|
|
70
|
+
const finalCustomColumnOperations = (column) => __awaiter(this, void 0, void 0, function* () {
|
|
71
71
|
if (minWidthFields) {
|
|
72
72
|
if (Object.prototype.hasOwnProperty.call(minWidthFields, column.field)) {
|
|
73
73
|
column.minWidth = minWidthFields[column.field];
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
if (customColumnOperations) {
|
|
77
|
-
return customColumnOperations(column);
|
|
77
|
+
return yield customColumnOperations(column);
|
|
78
78
|
}
|
|
79
79
|
return column;
|
|
80
|
-
};
|
|
80
|
+
});
|
|
81
81
|
const loadObjectList = () => __awaiter(this, void 0, void 0, function* () {
|
|
82
82
|
setLoading(true);
|
|
83
83
|
switch (paginationMode) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { DetailBySchemaProps } from '../../utils';
|
|
3
|
-
export default function DetailBySchema({ values, schema, editLink, editLabel, labelKey, decimalScale, fieldsLayout: fieldsLayoutInitial, fieldsProps, sxRow, sxRowMultiple, sxField, sxLabel, sxValue, sxValueList, sxValueListItem, sxValueListItemText, }: DetailBySchemaProps): JSX.Element;
|
|
3
|
+
export default function DetailBySchema({ values, schema, editLink, editLabel, labelKey, decimalScale, fieldsLayout: fieldsLayoutInitial, fieldsProps, sxRow, sxRowMultiple, sxField, sxLabel, sxValue, sxValueList, sxValueListItem, sxValueListItemText, }: DetailBySchemaProps): React.JSX.Element;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { DetailFieldBySchemaProps } from '../../utils';
|
|
3
|
-
export default function DetailFieldBySchema({ name, value, schema, labelKey, optionIdKey, optionLabelKey, sxField, sxLabel, sxValue, sxValueList, sxValueListItem, sxValueListItemText, }: DetailFieldBySchemaProps): JSX.Element;
|
|
3
|
+
export default function DetailFieldBySchema({ name, value, schema, labelKey, optionIdKey, optionLabelKey, sxField, sxLabel, sxValue, sxValueList, sxValueListItem, sxValueListItemText, }: DetailFieldBySchemaProps): React.JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { AnyObjectSchema } from 'yup';
|
|
3
3
|
import { Item, SchemaType } from '../../utils';
|
|
4
4
|
import { DialogType } from '../../context/APIWrapperContext';
|
|
@@ -6,9 +6,9 @@ interface DialogFormBySchemaProps {
|
|
|
6
6
|
schema: SchemaType;
|
|
7
7
|
validationSchema: AnyObjectSchema;
|
|
8
8
|
initialValues: Item;
|
|
9
|
-
onEditModelSave: (p: Item) => Promise<
|
|
9
|
+
onEditModelSave: (p: Item) => Promise<boolean>;
|
|
10
10
|
setDialog: (x: Partial<DialogType>) => void;
|
|
11
11
|
getAutoComplete: (model: string) => Promise<false | Item[]>;
|
|
12
12
|
}
|
|
13
|
-
export default function DialogFormBySchema({ schema, validationSchema, initialValues, onEditModelSave, setDialog, getAutoComplete, }: DialogFormBySchemaProps): JSX.Element;
|
|
13
|
+
export default function DialogFormBySchema({ schema, validationSchema, initialValues, onEditModelSave, setDialog, getAutoComplete, }: DialogFormBySchemaProps): React.JSX.Element;
|
|
14
14
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
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;
|
|
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): React.JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { UseFormRegister } from 'react-hook-form';
|
|
3
3
|
import { CommonFieldProps, FieldBySchemaProps, FormFieldLayout, Item } from '../../utils';
|
|
4
4
|
import { OptionsACType } from '../../context/APIWrapperContext';
|
|
@@ -11,5 +11,5 @@ interface FormBySchemaProps extends Omit<FieldBySchemaProps, 'name'> {
|
|
|
11
11
|
isolatedGetAutoComplete?: (model: string) => Promise<false | Item[]>;
|
|
12
12
|
fieldsProps?: Record<string, CommonFieldProps>;
|
|
13
13
|
}
|
|
14
|
-
export default function FormBySchema({ schema, control, errors, register, multiline, setValue, getValues, fieldKey, labelKey, index, optionsAC, setOptionsAC, forceReload, optionsModel, getOptionLabel, renderOption, onEditModel, options, isSemaphoric, label, decimalScale, fieldsLayout: fieldsLayoutInitial, fieldsProps, hiddenFields, isolatedGetAutoComplete, }: FormBySchemaProps): JSX.Element;
|
|
14
|
+
export default function FormBySchema({ schema, control, errors, register, multiline, setValue, getValues, fieldKey, labelKey, index, optionsAC, setOptionsAC, forceReload, optionsModel, getOptionLabel, renderOption, onEditModel, options, isSemaphoric, label, decimalScale, fieldsLayout: fieldsLayoutInitial, fieldsProps, hiddenFields, isolatedGetAutoComplete, }: FormBySchemaProps): React.JSX.Element;
|
|
15
15
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { FieldBySchemaProps } from '../../../utils';
|
|
3
|
-
export default function AutocompleteFieldBySchema({ fieldKey, index, name, schema, control, errors, optionIdKey, optionLabelKey, options, isSemaphoric, sx, label, ...other }: FieldBySchemaProps): JSX.Element;
|
|
3
|
+
export default function AutocompleteFieldBySchema({ fieldKey, index, name, schema, control, errors, optionIdKey, optionLabelKey, options, isSemaphoric, sx, label, ...other }: FieldBySchemaProps): React.JSX.Element;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { FieldBySchemaProps } from '../../../utils';
|
|
3
|
-
export default function BooleanFieldBySchema({ name, schema, control, fieldKey, index, sx, onValueChange, ...other }: FieldBySchemaProps): JSX.Element;
|
|
3
|
+
export default function BooleanFieldBySchema({ name, schema, control, fieldKey, index, sx, onValueChange, ...other }: FieldBySchemaProps): React.JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import 'dayjs/locale/pt-br';
|
|
3
3
|
import { FieldBySchemaProps } from '../../../utils';
|
|
4
|
-
export default function DesktopDatePickerBySchema({ name, schema, control, errors, fieldKey, index, sx, ...other }: FieldBySchemaProps): JSX.Element;
|
|
4
|
+
export default function DesktopDatePickerBySchema({ name, schema, control, errors, fieldKey, index, sx, ...other }: FieldBySchemaProps): React.JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import 'dayjs/locale/pt-br';
|
|
3
3
|
import { FieldBySchemaProps } from '../../../utils';
|
|
4
|
-
export default function DesktopDateTimePickerBySchema({ name, schema, control, errors, fieldKey, index, sx, ...other }: FieldBySchemaProps): JSX.Element;
|
|
4
|
+
export default function DesktopDateTimePickerBySchema({ name, schema, control, errors, fieldKey, index, sx, ...other }: FieldBySchemaProps): React.JSX.Element;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import Autocomplete from '@mui/material/Autocomplete';
|
|
2
3
|
import { FieldBySchemaProps } from '../../../utils';
|
|
3
|
-
declare const EditableAutocompleteFieldBySchema: React.ForwardRefExoticComponent<FieldBySchemaProps & React.RefAttributes<
|
|
4
|
+
declare const EditableAutocompleteFieldBySchema: React.ForwardRefExoticComponent<FieldBySchemaProps & React.RefAttributes<typeof Autocomplete>>;
|
|
4
5
|
export default EditableAutocompleteFieldBySchema;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { FieldBySchemaProps } from '../../../utils';
|
|
3
|
-
export default function FloatFieldBySchema({ fieldKey, index, name, control, schema, errors, onValueChange, decimalScale, label, ...other }: Omit<FieldBySchemaProps, 'type'>): JSX.Element;
|
|
3
|
+
export default function FloatFieldBySchema({ fieldKey, index, name, control, schema, errors, onValueChange, decimalScale, label, ...other }: Omit<FieldBySchemaProps, 'type'>): React.JSX.Element;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { FieldBySchemaProps } from '../../../utils';
|
|
3
|
-
export default function TextFieldBySchema({ name, schema, control, errors, multiline, minRows, fieldKey, index, sx, isPassword, type, autocomplete, disabled, ...other }: FieldBySchemaProps): JSX.Element;
|
|
3
|
+
export default function TextFieldBySchema({ name, schema, control, errors, multiline, minRows, fieldKey, index, sx, isPassword, type, autocomplete, disabled, ...other }: FieldBySchemaProps): React.JSX.Element;
|
|
@@ -6,6 +6,6 @@ interface APIWrapperProps {
|
|
|
6
6
|
setDialog: (x: Partial<DialogType>) => void;
|
|
7
7
|
children: React.ReactNode;
|
|
8
8
|
}
|
|
9
|
-
declare function APIWrapper({ handleLoading, setSnackBar, setDialog, children }: APIWrapperProps): JSX.Element;
|
|
9
|
+
declare function APIWrapper({ handleLoading, setSnackBar, setDialog, children }: APIWrapperProps): React.JSX.Element;
|
|
10
10
|
declare const _default: React.MemoExoticComponent<typeof APIWrapper>;
|
|
11
11
|
export default _default;
|
|
@@ -53,16 +53,16 @@ const DRFReactBySchemaContext_1 = require("./DRFReactBySchemaContext");
|
|
|
53
53
|
const api_1 = require("../api");
|
|
54
54
|
const APIWrapperContext_1 = require("./APIWrapperContext");
|
|
55
55
|
const DialogFormBySchema_1 = __importDefault(require("../components/forms/DialogFormBySchema"));
|
|
56
|
+
const initialPageForm = {
|
|
57
|
+
id: '',
|
|
58
|
+
schema: null,
|
|
59
|
+
initialValues: null,
|
|
60
|
+
validationSchema: null,
|
|
61
|
+
};
|
|
56
62
|
function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
57
63
|
const { serverEndPoint } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
58
64
|
const [usuaria, setUsuaria] = (0, react_1.useState)(null);
|
|
59
65
|
const [optionsAC, setOptionsAC] = (0, react_1.useReducer)((utils_1.reducer), null);
|
|
60
|
-
const initialPageForm = {
|
|
61
|
-
id: '',
|
|
62
|
-
schema: null,
|
|
63
|
-
initialValues: null,
|
|
64
|
-
validationSchema: null,
|
|
65
|
-
};
|
|
66
66
|
const [pageForm, setPageForm] = (0, react_1.useReducer)((utils_1.reducer), initialPageForm);
|
|
67
67
|
const editModel = (0, react_1.useRef)({});
|
|
68
68
|
const updateUsuaria = () => {
|
|
@@ -108,7 +108,7 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
108
108
|
object.data[field] = value;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
const values = populateInitialValues(Object.assign({
|
|
111
|
+
const values = populateInitialValues(Object.assign({ id: objId, extraValidators }, object));
|
|
112
112
|
return values;
|
|
113
113
|
});
|
|
114
114
|
const onSubmit = (model, id, data) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -125,7 +125,7 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
125
125
|
schema: pageForm.schema,
|
|
126
126
|
});
|
|
127
127
|
handleLoading(false);
|
|
128
|
-
if (
|
|
128
|
+
if ('isAxiosError' in response) {
|
|
129
129
|
onTriggerSnackBar({
|
|
130
130
|
msg: 'Houve um problema ao salvar seus dados! Por favor, entre em contato',
|
|
131
131
|
severity: 'error',
|
|
@@ -140,19 +140,24 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
140
140
|
onTriggerSnackBar({
|
|
141
141
|
msg: id ? 'Dados atualizados com sucesso!' : 'Criado com sucesso!',
|
|
142
142
|
});
|
|
143
|
-
return response;
|
|
143
|
+
return response.id;
|
|
144
144
|
});
|
|
145
|
-
const populateOptionsAC = (optionsACModels) => {
|
|
145
|
+
const populateOptionsAC = (optionsACModels) => __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
const promises = [];
|
|
146
147
|
for (const model of optionsACModels) {
|
|
147
|
-
localGetAutoComplete(model)
|
|
148
|
-
if (options !== false) {
|
|
149
|
-
setOptionsAC({ [model]: options });
|
|
150
|
-
}
|
|
151
|
-
});
|
|
148
|
+
promises.push(localGetAutoComplete(model));
|
|
152
149
|
}
|
|
153
|
-
|
|
150
|
+
const results = yield Promise.all(promises);
|
|
151
|
+
const newOptionsAC = {};
|
|
152
|
+
results.map((result, index) => {
|
|
153
|
+
if (result !== false) {
|
|
154
|
+
newOptionsAC[optionsACModels[index]] = result;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
setOptionsAC(newOptionsAC);
|
|
158
|
+
});
|
|
154
159
|
const populateInitialValues = (_a) => {
|
|
155
|
-
var {
|
|
160
|
+
var { id, extraValidators } = _a, object = __rest(_a, ["id", "extraValidators"]);
|
|
156
161
|
const values = (0, utils_1.populateValues)(object);
|
|
157
162
|
const yupSchema = (0, utils_1.buildGenericYupValidationSchema)(Object.assign(Object.assign({}, object), { data: values, extraValidators }));
|
|
158
163
|
setPageForm({
|
|
@@ -177,14 +182,14 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
177
182
|
data,
|
|
178
183
|
schema,
|
|
179
184
|
});
|
|
180
|
-
if (
|
|
185
|
+
if ('isAxiosError' in response) {
|
|
181
186
|
onTriggerSnackBar({
|
|
182
|
-
msg: 'Houve um problema ao salvar seus dados
|
|
187
|
+
msg: 'Houve um problema ao salvar seus dados.',
|
|
183
188
|
severity: 'error',
|
|
184
189
|
});
|
|
185
190
|
console.log({
|
|
186
191
|
msg: 'Error saving model',
|
|
187
|
-
|
|
192
|
+
response,
|
|
188
193
|
data,
|
|
189
194
|
});
|
|
190
195
|
return false;
|
|
@@ -205,6 +210,7 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
205
210
|
populateOptionsAC([model]);
|
|
206
211
|
}
|
|
207
212
|
handleLoading(false);
|
|
213
|
+
return true;
|
|
208
214
|
});
|
|
209
215
|
const onEditModelDataGridSave = ({ model, newRow, schema, }) => __awaiter(this, void 0, void 0, function* () {
|
|
210
216
|
const response = yield (0, api_1.updateDataBySchema)({
|
|
@@ -215,18 +221,23 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
215
221
|
schema,
|
|
216
222
|
path: model,
|
|
217
223
|
});
|
|
218
|
-
if (
|
|
224
|
+
if ('isAxiosError' in response) {
|
|
219
225
|
onTriggerSnackBar({
|
|
220
|
-
msg: '
|
|
221
|
-
severity: '
|
|
226
|
+
msg: 'Não foi possível salvar os dados. Confira os erros.',
|
|
227
|
+
severity: 'error',
|
|
222
228
|
});
|
|
223
|
-
|
|
229
|
+
console.log({
|
|
230
|
+
msg: 'Error saving model',
|
|
231
|
+
response,
|
|
232
|
+
data: newRow,
|
|
233
|
+
});
|
|
234
|
+
return false;
|
|
224
235
|
}
|
|
225
236
|
onTriggerSnackBar({
|
|
226
|
-
msg: '
|
|
227
|
-
severity: '
|
|
237
|
+
msg: 'Alterações salvas com sucesso!',
|
|
238
|
+
severity: 'info',
|
|
228
239
|
});
|
|
229
|
-
return
|
|
240
|
+
return response;
|
|
230
241
|
});
|
|
231
242
|
const onEditModel = ({ fieldKey, index, model, id, labelKey, setValue, getValues, }) => {
|
|
232
243
|
setDialog({
|
|
@@ -274,7 +285,7 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
274
285
|
title: 'Apagar',
|
|
275
286
|
Body: 'Tem certeza de que deseja apagar este item?',
|
|
276
287
|
Actions: (react_1.default.createElement(DialogActions_1.default, { setDialog: setDialog, handleSave: (e) => {
|
|
277
|
-
return onDeleteModelSave(model, id, onSuccess);
|
|
288
|
+
return onDeleteModelSave(model, id, onSuccess ? onSuccess(e) : undefined);
|
|
278
289
|
}, btnConfirm: "Sim, apagar" })),
|
|
279
290
|
});
|
|
280
291
|
};
|
|
@@ -282,7 +293,7 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
282
293
|
setDialog({ open: false });
|
|
283
294
|
handleLoading(true);
|
|
284
295
|
const ret = yield (0, api_1.deleteData)(model, serverEndPoint, id);
|
|
285
|
-
if (ret
|
|
296
|
+
if (ret === true) {
|
|
286
297
|
onTriggerSnackBar({
|
|
287
298
|
msg: 'Apagado com com sucesso!',
|
|
288
299
|
severity: 'info',
|
|
@@ -299,7 +310,7 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
299
310
|
});
|
|
300
311
|
return false;
|
|
301
312
|
});
|
|
302
|
-
const onEditRelatedModelSave = ({ model, id, relatedModel,
|
|
313
|
+
const onEditRelatedModelSave = ({ model, id, relatedModel, newRow, schema, onlyAddExisting, }) => __awaiter(this, void 0, void 0, function* () {
|
|
303
314
|
const updateUrl = `${model}/${id}/${relatedModel}`;
|
|
304
315
|
if (onlyAddExisting) {
|
|
305
316
|
const response = yield (0, api_1.addExistingRelatedModel)({
|
|
@@ -313,7 +324,7 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
313
324
|
},
|
|
314
325
|
},
|
|
315
326
|
});
|
|
316
|
-
if (
|
|
327
|
+
if ('isAxiosError' in response) {
|
|
317
328
|
console.log(response);
|
|
318
329
|
onTriggerSnackBar({
|
|
319
330
|
msg: 'Houve um problema ao salvar a alteração! Por favor, entre em contato.',
|
|
@@ -346,34 +357,42 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
346
357
|
schema,
|
|
347
358
|
path: updateUrl,
|
|
348
359
|
});
|
|
349
|
-
if (
|
|
360
|
+
if ('isAxiosError' in response) {
|
|
350
361
|
onTriggerSnackBar({
|
|
351
|
-
msg: '
|
|
352
|
-
severity: '
|
|
362
|
+
msg: 'Não foi possível salvar os dados. Confira os erros.',
|
|
363
|
+
severity: 'error',
|
|
353
364
|
});
|
|
354
|
-
|
|
365
|
+
console.log({
|
|
366
|
+
error: response,
|
|
367
|
+
data: newRow,
|
|
368
|
+
});
|
|
369
|
+
return false;
|
|
355
370
|
}
|
|
356
371
|
onTriggerSnackBar({
|
|
357
|
-
msg: '
|
|
358
|
-
severity: '
|
|
372
|
+
msg: 'Alterações salvas com sucesso!',
|
|
373
|
+
severity: 'info',
|
|
359
374
|
});
|
|
360
|
-
return
|
|
375
|
+
return response;
|
|
361
376
|
});
|
|
362
377
|
const onDeleteRelatedModel = ({ model, id, relatedModel, relatedModelId, }) => __awaiter(this, void 0, void 0, function* () {
|
|
363
378
|
const deleteUrl = `${model}/${id}/${relatedModel}`;
|
|
364
379
|
const response = yield (0, api_1.deleteData)(deleteUrl, serverEndPoint, relatedModelId);
|
|
365
|
-
if (response) {
|
|
380
|
+
if (response !== true) {
|
|
366
381
|
onTriggerSnackBar({
|
|
367
|
-
msg: '
|
|
368
|
-
severity: '
|
|
382
|
+
msg: 'Houve um problema ao remover o item! Por favor, entre em contato.',
|
|
383
|
+
severity: 'error',
|
|
369
384
|
});
|
|
370
|
-
|
|
385
|
+
console.log({
|
|
386
|
+
error: response,
|
|
387
|
+
id,
|
|
388
|
+
});
|
|
389
|
+
return false;
|
|
371
390
|
}
|
|
372
391
|
onTriggerSnackBar({
|
|
373
|
-
msg: '
|
|
374
|
-
severity: '
|
|
392
|
+
msg: 'Alterações salvas com sucesso!',
|
|
393
|
+
severity: 'info',
|
|
375
394
|
});
|
|
376
|
-
return
|
|
395
|
+
return response;
|
|
377
396
|
});
|
|
378
397
|
if (!serverEndPoint) {
|
|
379
398
|
console.error('There must be a serverEndPoint properly configured for apiWrapper to work!');
|
|
@@ -390,26 +409,52 @@ function APIWrapper({ handleLoading, setSnackBar, setDialog, children }) {
|
|
|
390
409
|
}
|
|
391
410
|
function localGetAllModels() {
|
|
392
411
|
return __awaiter(this, void 0, void 0, function* () {
|
|
393
|
-
|
|
412
|
+
const response = yield (0, api_1.getAllModels)(serverEndPoint);
|
|
413
|
+
if ('isAxiosError' in response) {
|
|
414
|
+
return [];
|
|
415
|
+
}
|
|
416
|
+
return response;
|
|
394
417
|
});
|
|
395
418
|
}
|
|
396
419
|
function localLoginByPayload(payload) {
|
|
397
420
|
return __awaiter(this, void 0, void 0, function* () {
|
|
398
|
-
|
|
421
|
+
const response = yield (0, api_1.loginByPayload)(payload, serverEndPoint);
|
|
422
|
+
if (typeof response !== 'boolean') {
|
|
423
|
+
console.log({
|
|
424
|
+
error: response,
|
|
425
|
+
payload,
|
|
426
|
+
});
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
return response;
|
|
399
430
|
});
|
|
400
431
|
}
|
|
401
432
|
function localSignUp(data) {
|
|
402
433
|
return __awaiter(this, void 0, void 0, function* () {
|
|
403
|
-
|
|
434
|
+
const response = yield (0, api_1.signUp)(data, serverEndPoint);
|
|
435
|
+
if ('isAxiosError' in response) {
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
return response;
|
|
404
439
|
});
|
|
405
440
|
}
|
|
406
441
|
function localGetSignupOptions() {
|
|
407
442
|
return __awaiter(this, void 0, void 0, function* () {
|
|
408
|
-
|
|
443
|
+
const response = yield (0, api_1.getSignUpOptions)(serverEndPoint);
|
|
444
|
+
if ('isAxiosError' in response) {
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
return response;
|
|
409
448
|
});
|
|
410
449
|
}
|
|
411
450
|
function localUpdateModel(params) {
|
|
412
|
-
return (0,
|
|
451
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
452
|
+
const response = yield (0, api_1.updateData)(Object.assign(Object.assign({}, params), { serverEndPoint }));
|
|
453
|
+
if ('isAxiosError' in response) {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
return response;
|
|
457
|
+
});
|
|
413
458
|
}
|
|
414
459
|
return (react_1.default.createElement(APIWrapperContext_1.APIWrapperContext.Provider, { value: {
|
|
415
460
|
usuaria,
|