drf-react-by-schema 0.4.0 → 0.5.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 +3 -2
- package/dist/api.js +16 -8
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts +3 -2
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.js +15 -2
- package/dist/components/DataGridBySchemaEditable.d.ts +2 -0
- package/dist/components/DataGridBySchemaEditable.js +3 -6
- package/dist/components/GenericModelList.d.ts +4 -3
- package/dist/components/GenericModelList.js +13 -4
- package/dist/context/APIWrapper.js +7 -2
- package/dist/context/APIWrapperContext.d.ts +8 -4
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +1 -1
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { serverEndPointType } from './context/DRFReactBySchemaContext';
|
|
2
|
-
import { Item, SchemaType, DataSchemaColumnsType, ItemSchemaColumnsType } from './utils';
|
|
2
|
+
import { Item, SchemaType, modelOptionsType, DataSchemaColumnsType, ItemSchemaColumnsType } from './utils';
|
|
3
3
|
type Id = string | number | null;
|
|
4
4
|
/**
|
|
5
5
|
* Interface for CRUD on API
|
|
@@ -71,8 +71,9 @@ export interface getGenericModelListProps {
|
|
|
71
71
|
creatableFields?: string[];
|
|
72
72
|
isInBatches?: boolean;
|
|
73
73
|
loadedSchema?: SchemaType | boolean;
|
|
74
|
+
loadedModelOptions?: modelOptionsType | boolean;
|
|
74
75
|
}
|
|
75
|
-
export declare const getGenericModelList: ({ model, serverEndPoint, id, relatedModel, relatedModelId, columnFields, hiddenFields, creatableFields, isInBatches, loadedSchema }: getGenericModelListProps) => Promise<false | DataSchemaColumnsType>;
|
|
76
|
+
export declare const getGenericModelList: ({ model, serverEndPoint, id, relatedModel, relatedModelId, columnFields, hiddenFields, creatableFields, isInBatches, loadedSchema, loadedModelOptions, }: getGenericModelListProps) => Promise<false | DataSchemaColumnsType>;
|
|
76
77
|
export declare const getGenericModel: ({ model, serverEndPoint, id, relatedModel, relatedModelId }: {
|
|
77
78
|
model: string;
|
|
78
79
|
serverEndPoint: serverEndPointType | null;
|
package/dist/api.js
CHANGED
|
@@ -73,7 +73,11 @@ const getSchema = (path, serverEndPoint) => __awaiter(void 0, void 0, void 0, fu
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
|
|
76
|
+
const modelOptions = Object.assign({}, options);
|
|
77
|
+
delete modelOptions.renders;
|
|
78
|
+
delete modelOptions.parses;
|
|
79
|
+
delete modelOptions.actions;
|
|
80
|
+
return { schema: options.actions.POST, modelOptions };
|
|
77
81
|
});
|
|
78
82
|
const getData = (path, serverEndPoint, route = 'api') => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
83
|
var _b;
|
|
@@ -532,10 +536,11 @@ const isLoggedIn = (serverEndPoint) => __awaiter(void 0, void 0, void 0, functio
|
|
|
532
536
|
});
|
|
533
537
|
exports.isLoggedIn = isLoggedIn;
|
|
534
538
|
;
|
|
535
|
-
const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = '', relatedModelId = '', columnFields, hiddenFields = ['id'], creatableFields = [], isInBatches = false, loadedSchema }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
539
|
+
const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = '', relatedModelId = '', columnFields, hiddenFields = ['id'], creatableFields = [], isInBatches = false, loadedSchema, loadedModelOptions, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
536
540
|
let path = `${model}/${id}`;
|
|
537
541
|
let schemaPath = model;
|
|
538
542
|
let schema = loadedSchema;
|
|
543
|
+
let modelOptions = loadedModelOptions;
|
|
539
544
|
let columns;
|
|
540
545
|
if (!(0, utils_1.isTmpId)(id) && relatedModel) {
|
|
541
546
|
path += `/${relatedModel}/${relatedModelId}`;
|
|
@@ -543,10 +548,12 @@ const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = ''
|
|
|
543
548
|
}
|
|
544
549
|
// Only get schema and columns if not in batches or in first batch:
|
|
545
550
|
if (!schema) {
|
|
546
|
-
|
|
547
|
-
if (!
|
|
551
|
+
const options = yield getSchema(schemaPath, serverEndPoint);
|
|
552
|
+
if (!options) {
|
|
548
553
|
return false;
|
|
549
554
|
}
|
|
555
|
+
schema = options.schema;
|
|
556
|
+
modelOptions = options.modelOptions;
|
|
550
557
|
columns = getDataGridColumns(schema, columnFields, hiddenFields, creatableFields);
|
|
551
558
|
if (!columns) {
|
|
552
559
|
return false;
|
|
@@ -590,7 +597,7 @@ const getGenericModelList = ({ model, serverEndPoint, id = '', relatedModel = ''
|
|
|
590
597
|
return { data };
|
|
591
598
|
}
|
|
592
599
|
// DEBUG console.log({ path, data, columns, schema });
|
|
593
|
-
return { data, columns, schema };
|
|
600
|
+
return { data, columns, schema, modelOptions };
|
|
594
601
|
});
|
|
595
602
|
exports.getGenericModelList = getGenericModelList;
|
|
596
603
|
const getGenericModel = ({ model, serverEndPoint, id = '', relatedModel = '', relatedModelId = '' }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -600,14 +607,15 @@ const getGenericModel = ({ model, serverEndPoint, id = '', relatedModel = '', re
|
|
|
600
607
|
path += `/${relatedModel}/${relatedModelId}`;
|
|
601
608
|
schemaPath += `/${id}/${relatedModel}`;
|
|
602
609
|
}
|
|
603
|
-
const
|
|
604
|
-
if (!
|
|
610
|
+
const options = yield getSchema(schemaPath, serverEndPoint);
|
|
611
|
+
if (!options) {
|
|
605
612
|
return false;
|
|
606
613
|
}
|
|
614
|
+
const { schema, modelOptions } = options;
|
|
607
615
|
const data = (!id || (id && relatedModel && !relatedModelId))
|
|
608
616
|
? {}
|
|
609
617
|
: yield getData(path, serverEndPoint);
|
|
610
618
|
// console.log({ schema, data }); // DEBUG
|
|
611
|
-
return { schema, data };
|
|
619
|
+
return { schema, modelOptions, data };
|
|
612
620
|
});
|
|
613
621
|
exports.getGenericModel = getGenericModel;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { SxProps } from '@mui/material';
|
|
3
3
|
import { GridEnrichedBySchemaColDef } from '../../utils';
|
|
4
|
-
import { OptionsACType } from '../../context/APIWrapperContext';
|
|
4
|
+
import { OptionsACType, OnEditModelType } from '../../context/APIWrapperContext';
|
|
5
5
|
interface SelectEditInputCellProps {
|
|
6
6
|
field: string;
|
|
7
7
|
id: number | string;
|
|
@@ -11,6 +11,7 @@ interface SelectEditInputCellProps {
|
|
|
11
11
|
optionsAC: React.MutableRefObject<OptionsACType | null>;
|
|
12
12
|
isIndexField: boolean;
|
|
13
13
|
multiple?: boolean;
|
|
14
|
+
onEditModel?: (p: OnEditModelType) => void;
|
|
14
15
|
sx?: SxProps;
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
@@ -29,5 +30,5 @@ interface SelectEditInputCellProps {
|
|
|
29
30
|
* }
|
|
30
31
|
* @returns {*} {JSX.Element}
|
|
31
32
|
*/
|
|
32
|
-
export declare function SelectEditInputCell({ field, id, value, column, type, optionsAC, isIndexField, multiple, sx }: SelectEditInputCellProps): JSX.Element;
|
|
33
|
+
export declare function SelectEditInputCell({ field, id, value, column, type, optionsAC, isIndexField, multiple, onEditModel, sx }: SelectEditInputCellProps): JSX.Element;
|
|
33
34
|
export {};
|
|
@@ -39,6 +39,8 @@ exports.SelectEditInputCell = void 0;
|
|
|
39
39
|
const react_1 = __importDefault(require("react"));
|
|
40
40
|
const x_data_grid_1 = require("@mui/x-data-grid");
|
|
41
41
|
const TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
42
|
+
const IconButton_1 = __importDefault(require("@mui/material/IconButton"));
|
|
43
|
+
const Edit_1 = __importDefault(require("@mui/icons-material/Edit"));
|
|
42
44
|
const Autocomplete_1 = __importStar(require("@mui/material/Autocomplete"));
|
|
43
45
|
const utils_1 = require("../../utils");
|
|
44
46
|
const filter = (0, Autocomplete_1.createFilterOptions)();
|
|
@@ -58,7 +60,7 @@ const filter = (0, Autocomplete_1.createFilterOptions)();
|
|
|
58
60
|
* }
|
|
59
61
|
* @returns {*} {JSX.Element}
|
|
60
62
|
*/
|
|
61
|
-
function SelectEditInputCell({ field, id, value, column, type, optionsAC, isIndexField, multiple = false, sx = {} }) {
|
|
63
|
+
function SelectEditInputCell({ field, id, value, column, type, optionsAC, isIndexField, multiple = false, onEditModel, sx = {} }) {
|
|
62
64
|
// TODO: allow edit option label, as in formautocomplete!
|
|
63
65
|
const apiRef = (0, x_data_grid_1.useGridApiContext)();
|
|
64
66
|
const handleChange = (newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -135,6 +137,17 @@ function SelectEditInputCell({ field, id, value, column, type, optionsAC, isInde
|
|
|
135
137
|
};
|
|
136
138
|
}
|
|
137
139
|
handleChange(newValue);
|
|
138
|
-
}, fullWidth: true, renderInput: params => (react_1.default.createElement(
|
|
140
|
+
}, fullWidth: true, renderInput: params => (react_1.default.createElement(react_1.default.Fragment, null, column.creatable
|
|
141
|
+
? react_1.default.createElement(TextField_1.default, Object.assign({}, params, { margin: "normal", InputProps: Object.assign(Object.assign({}, params.InputProps), { endAdornment: (react_1.default.createElement(react_1.default.Fragment, null,
|
|
142
|
+
!multiple && onEditModel && value && (react_1.default.createElement(IconButton_1.default, { size: "small", onClick: () => {
|
|
143
|
+
onEditModel({
|
|
144
|
+
model: field,
|
|
145
|
+
id: value[valueKey],
|
|
146
|
+
labelKey,
|
|
147
|
+
});
|
|
148
|
+
} },
|
|
149
|
+
react_1.default.createElement(Edit_1.default, null))),
|
|
150
|
+
params.InputProps.endAdornment)) }) }))
|
|
151
|
+
: react_1.default.createElement(TextField_1.default, Object.assign({}, params, { sx: sx })))) }, creatableProps)));
|
|
139
152
|
}
|
|
140
153
|
exports.SelectEditInputCell = SelectEditInputCell;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Item, SchemaType, Id, GridEnrichedBySchemaColDef } from '../utils';
|
|
3
3
|
import { SxProps } from '@mui/material';
|
|
4
|
+
import { OnEditModelType } from '../context/APIWrapperContext';
|
|
4
5
|
interface DataGridBySchemaEditableProps {
|
|
5
6
|
schema: SchemaType;
|
|
6
7
|
data: Item[];
|
|
@@ -23,6 +24,7 @@ interface DataGridBySchemaEditableProps {
|
|
|
23
24
|
LinkComponent?: any;
|
|
24
25
|
onProcessRow?: (p: any) => void;
|
|
25
26
|
onDataChange?: (p: any) => void;
|
|
27
|
+
onEditModel?: (p: OnEditModelType) => void;
|
|
26
28
|
isEditable?: boolean;
|
|
27
29
|
sx?: SxProps;
|
|
28
30
|
isAutoHeight?: boolean;
|
|
@@ -73,7 +73,7 @@ const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
|
73
73
|
const stringMask = require('string-mask');
|
|
74
74
|
;
|
|
75
75
|
const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
76
|
-
var { schema, data, 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, isEditable = false, sx = { mr: 2 }, isAutoHeight = false, defaultValues = {}, hideFooterPagination = false, setVisibleRows } = _a, other = __rest(_a, ["schema", "data", "columns", "model", "fieldKey", "labelKey", "index", "name", "indexField", "addExistingModel", "indexFieldMinWidth", "indexFieldBasePath", "stateToLink", "minWidth", "modelParent", "modelParentId", "customColumnOperations", "customLinkDestination", "LinkComponent", "onProcessRow", "onDataChange", "isEditable", "sx", "isAutoHeight", "defaultValues", "hideFooterPagination", "setVisibleRows"]);
|
|
76
|
+
var { schema, data, 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 } = _a, other = __rest(_a, ["schema", "data", "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"]);
|
|
77
77
|
const { serverEndPoint } = DRFReactBySchemaContext_1.DRFReactBySchemaContext
|
|
78
78
|
? react_1.default.useContext(DRFReactBySchemaContext_1.DRFReactBySchemaContext)
|
|
79
79
|
: { serverEndPoint: null };
|
|
@@ -185,7 +185,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
185
185
|
column.sortComparator = (v1, v2, param1, param2) => {
|
|
186
186
|
return (0, x_data_grid_1.gridStringOrNumberComparator)(v1.label, v2.label, param1, param2);
|
|
187
187
|
};
|
|
188
|
-
column.renderEditCell = (params) => react_1.default.createElement(SelectEditInputCell_1.SelectEditInputCell, Object.assign({}, params, { column: column, type: schema[col.field].type, optionsAC: optionsAC, isIndexField: isIndexField }));
|
|
188
|
+
column.renderEditCell = (params) => react_1.default.createElement(SelectEditInputCell_1.SelectEditInputCell, Object.assign({}, params, { column: column, type: schema[col.field].type, optionsAC: optionsAC, isIndexField: isIndexField, onEditModel: onEditModel }));
|
|
189
189
|
break;
|
|
190
190
|
}
|
|
191
191
|
column.valueGetter = params => {
|
|
@@ -202,7 +202,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
202
202
|
: params.value.map(val => val.label).join(', ');
|
|
203
203
|
};
|
|
204
204
|
column.filterable = false;
|
|
205
|
-
column.renderEditCell = (params) => react_1.default.createElement(SelectEditInputCell_1.SelectEditInputCell, Object.assign({}, params, { column: column, type: schema[col.field].type, optionsAC: optionsAC, isIndexField: isIndexField, multiple:
|
|
205
|
+
column.renderEditCell = (params) => react_1.default.createElement(SelectEditInputCell_1.SelectEditInputCell, Object.assign({}, params, { column: column, type: schema[col.field].type, optionsAC: optionsAC, isIndexField: isIndexField, multiple: schema[col.field].many || false }));
|
|
206
206
|
break;
|
|
207
207
|
}
|
|
208
208
|
column.valueGetter = params => {
|
|
@@ -415,9 +415,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
415
415
|
setDataGridLoading(true);
|
|
416
416
|
const indexCol = preparedColumns.find(col => col.field === indexField);
|
|
417
417
|
processingRow.current = newRow.id;
|
|
418
|
-
console.log('antes');
|
|
419
418
|
yield yupValidationSchema.current.validate(newRow);
|
|
420
|
-
console.log('depois');
|
|
421
419
|
const onlyAddExisting = (indexField &&
|
|
422
420
|
(0, utils_1.isTmpId)(newRow.id) &&
|
|
423
421
|
(newRow[indexField] && !(0, utils_1.isTmpId)(newRow[indexField].id)) &&
|
|
@@ -443,7 +441,6 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
443
441
|
newRow[indexField] = newRow[indexField].label;
|
|
444
442
|
}
|
|
445
443
|
}
|
|
446
|
-
console.log({ modelParent, modelParentId, apiContext });
|
|
447
444
|
if (modelParent && modelParentId && apiContext) {
|
|
448
445
|
const response = yield apiContext.onEditRelatedModelSave({
|
|
449
446
|
model: modelParent,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { SumRowsType } from './DataTotals';
|
|
3
3
|
import { GridEnrichedBySchemaColDef } from '../utils';
|
|
4
4
|
interface GenericModelListProps {
|
|
@@ -13,7 +13,8 @@ interface GenericModelListProps {
|
|
|
13
13
|
isAutoHeight?: boolean;
|
|
14
14
|
model: string;
|
|
15
15
|
forceReload: boolean;
|
|
16
|
-
LinkComponent?:
|
|
16
|
+
LinkComponent?: JSX.Element | null;
|
|
17
|
+
hasHeader: boolean;
|
|
17
18
|
}
|
|
18
|
-
declare const GenericModelList: ({ columnFields, hiddenFields, minWidthFields, indexFieldBasePath, indexField, customColumnOperations, customLinkDestination, sumRows, isAutoHeight, model, forceReload, LinkComponent }: GenericModelListProps) => JSX.Element;
|
|
19
|
+
declare const GenericModelList: ({ columnFields, hiddenFields, minWidthFields, indexFieldBasePath, indexField, customColumnOperations, customLinkDestination, sumRows, isAutoHeight, model, forceReload, LinkComponent, hasHeader, }: GenericModelListProps) => JSX.Element;
|
|
19
20
|
export default GenericModelList;
|
|
@@ -37,13 +37,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
39
|
const Box_1 = __importDefault(require("@mui/material/Box"));
|
|
40
|
+
const Typography_1 = __importDefault(require("@mui/material/Typography"));
|
|
41
|
+
const Button_1 = __importDefault(require("@mui/material/Button"));
|
|
42
|
+
const AddCircleOutline_1 = __importDefault(require("@mui/icons-material/AddCircleOutline"));
|
|
40
43
|
const DataGridBySchemaEditable_1 = __importDefault(require("./DataGridBySchemaEditable"));
|
|
41
44
|
const DataTotals_1 = __importDefault(require("./DataTotals"));
|
|
42
45
|
const styles_1 = require("../styles");
|
|
43
46
|
const api_1 = require("../api");
|
|
44
47
|
const DRFReactBySchemaContext_1 = require("../context/DRFReactBySchemaContext");
|
|
45
48
|
const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
46
|
-
const GenericModelList = ({ columnFields, hiddenFields = [], minWidthFields, indexFieldBasePath, indexField, customColumnOperations, customLinkDestination, sumRows, isAutoHeight = true, model, forceReload = false, LinkComponent = null }) => {
|
|
49
|
+
const GenericModelList = ({ columnFields, hiddenFields = [], minWidthFields, indexFieldBasePath, indexField, customColumnOperations, customLinkDestination, sumRows, isAutoHeight = true, model, forceReload = false, LinkComponent = null, hasHeader = false, }) => {
|
|
47
50
|
const context = react_1.default.useContext(DRFReactBySchemaContext_1.DRFReactBySchemaContext);
|
|
48
51
|
const apiContext = react_1.default.useContext(APIWrapperContext_1.APIWrapperContext);
|
|
49
52
|
if (!context.serverEndPoint || !apiContext) {
|
|
@@ -52,7 +55,6 @@ const GenericModelList = ({ columnFields, hiddenFields = [], minWidthFields, ind
|
|
|
52
55
|
}
|
|
53
56
|
const { serverEndPoint, isInBatches, firstBatchLength } = context;
|
|
54
57
|
const { handleLoading } = apiContext;
|
|
55
|
-
;
|
|
56
58
|
const [data, setData] = (0, react_1.useState)(false);
|
|
57
59
|
const [visibleRows, setVisibleRows] = (0, react_1.useState)([]);
|
|
58
60
|
const [hideFooterPagination, setHideFooterPagination] = (0, react_1.useState)(false);
|
|
@@ -82,7 +84,7 @@ const GenericModelList = ({ columnFields, hiddenFields = [], minWidthFields, ind
|
|
|
82
84
|
handleLoading(false);
|
|
83
85
|
if (isInBatches && loadedData.data.length === firstBatchLength) {
|
|
84
86
|
setHideFooterPagination(true);
|
|
85
|
-
(0, api_1.getGenericModelList)(Object.assign(Object.assign({}, loadParams), { loadedSchema: loadedData.schema })).then(lastBatchData => {
|
|
87
|
+
(0, api_1.getGenericModelList)(Object.assign(Object.assign({}, loadParams), { loadedSchema: loadedData.schema, loadedModelOptions: loadedData.modelOptions })).then(lastBatchData => {
|
|
86
88
|
if (lastBatchData && typeof lastBatchData !== 'boolean') {
|
|
87
89
|
setData(Object.assign(Object.assign({}, loadedData), { data: [
|
|
88
90
|
...loadedData.data,
|
|
@@ -101,9 +103,16 @@ const GenericModelList = ({ columnFields, hiddenFields = [], minWidthFields, ind
|
|
|
101
103
|
}
|
|
102
104
|
(0, react_1.useEffect)(() => {
|
|
103
105
|
loadObjectList();
|
|
104
|
-
}, []);
|
|
106
|
+
}, [model]);
|
|
105
107
|
return (react_1.default.createElement(react_1.default.Fragment, null, typeof data !== 'boolean' && data.columns &&
|
|
106
108
|
react_1.default.createElement(react_1.default.Fragment, null,
|
|
109
|
+
hasHeader &&
|
|
110
|
+
react_1.default.createElement(Box_1.default, { sx: Object.assign(Object.assign({}, styles_1.Layout.flexRowGrow), { mb: 2 }) },
|
|
111
|
+
react_1.default.createElement(Typography_1.default, { variant: "h5" }, data.modelOptions.verbose_name_plural || data.modelOptions.name),
|
|
112
|
+
LinkComponent &&
|
|
113
|
+
react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.flexRow },
|
|
114
|
+
react_1.default.createElement(LinkComponent, { to: `novo` },
|
|
115
|
+
react_1.default.createElement(Button_1.default, { variant: "contained", size: "medium", sx: { alignSelf: 'stretch' }, startIcon: react_1.default.createElement(AddCircleOutline_1.default, null) }, "Adicionar")))),
|
|
107
116
|
react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.dataGridWithTabs },
|
|
108
117
|
react_1.default.createElement(DataGridBySchemaEditable_1.default, { data: data.data, columns: data.columns, schema: data.schema || {}, model: model, indexField: indexField, indexFieldBasePath: indexFieldBasePath, isEditable: false, isAutoHeight: isAutoHeight, hideFooterPagination: hideFooterPagination, customColumnOperations: finalCustomColumnOperations, customLinkDestination: customLinkDestination, setVisibleRows: setVisibleRows, onDataChange: newData => {
|
|
109
118
|
setData(Object.assign(Object.assign({}, data), { data: newData }));
|
|
@@ -108,7 +108,7 @@ function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, childre
|
|
|
108
108
|
const values = populateInitialValues(Object.assign({ model, id: objId, extraValidators }, object));
|
|
109
109
|
return values;
|
|
110
110
|
});
|
|
111
|
-
const onSubmit = (model, id, data
|
|
111
|
+
const onSubmit = (model, id, data) => __awaiter(this, void 0, void 0, function* () {
|
|
112
112
|
setLoading(true);
|
|
113
113
|
const response = yield (0, api_1.updateDataBySchema)({
|
|
114
114
|
model,
|
|
@@ -153,6 +153,7 @@ function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, childre
|
|
|
153
153
|
model,
|
|
154
154
|
id,
|
|
155
155
|
schema: object.schema,
|
|
156
|
+
modelOptions: object.modelOptions,
|
|
156
157
|
initialValues: values,
|
|
157
158
|
validationSchema: yupSchema
|
|
158
159
|
});
|
|
@@ -335,7 +336,11 @@ function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, childre
|
|
|
335
336
|
onEditRelatedModelSave,
|
|
336
337
|
onDeleteRelatedModel,
|
|
337
338
|
onTriggerSnackBar,
|
|
338
|
-
setDialog
|
|
339
|
+
setDialog,
|
|
340
|
+
// Remove after integrating new "onEditModel" to package:
|
|
341
|
+
serverEndPoint,
|
|
342
|
+
editModel,
|
|
343
|
+
populateOptionsAC,
|
|
339
344
|
} }, children));
|
|
340
345
|
}
|
|
341
346
|
exports.default = react_1.default.memo(APIWrapper);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { FieldValues, SubmitHandler } from 'react-hook-form';
|
|
3
3
|
import { ItemSchemaColumnsType, Id, Item, SchemaType } from '../utils';
|
|
4
|
+
import { serverEndPointType } from './DRFReactBySchemaContext';
|
|
4
5
|
export interface LoadSinglePageDataProps {
|
|
5
6
|
model: string;
|
|
6
7
|
objId?: Id;
|
|
@@ -18,13 +19,13 @@ export interface PageFormType {
|
|
|
18
19
|
validationSchema: Item | null;
|
|
19
20
|
}
|
|
20
21
|
export interface OnEditModelType {
|
|
21
|
-
fieldKey
|
|
22
|
-
index
|
|
22
|
+
fieldKey?: string;
|
|
23
|
+
index?: string;
|
|
23
24
|
model: string;
|
|
24
25
|
id: Id;
|
|
25
26
|
labelKey: string;
|
|
26
|
-
setValue
|
|
27
|
-
getValues
|
|
27
|
+
setValue?: (p: any) => void;
|
|
28
|
+
getValues?: (p: any) => any;
|
|
28
29
|
}
|
|
29
30
|
export interface OnEditRelatedModelType {
|
|
30
31
|
model: string;
|
|
@@ -71,5 +72,8 @@ export interface APIWrapperContextType {
|
|
|
71
72
|
onDeleteRelatedModel: (p: OnDeleteRelatedModelType) => Promise<boolean>;
|
|
72
73
|
onTriggerSnackBar: (p: SnackBarType) => void;
|
|
73
74
|
setDialog: React.Dispatch<React.SetStateAction<DialogType>>;
|
|
75
|
+
serverEndPoint: serverEndPointType;
|
|
76
|
+
editModel: React.MutableRefObject<Item>;
|
|
77
|
+
populateOptionsAC: (optionsACModels: string[]) => void;
|
|
74
78
|
}
|
|
75
79
|
export declare const APIWrapperContext: React.Context<APIWrapperContextType | null>;
|
package/dist/utils.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { GridActionsColDef, GridColDef } from '@mui/x-data-grid';
|
|
|
2
2
|
export type Id = string | number;
|
|
3
3
|
export type Item = Record<string, any>;
|
|
4
4
|
export type SchemaType = Record<string, Field>;
|
|
5
|
+
export type modelOptionsType = Record<string, string>;
|
|
5
6
|
export interface Choice {
|
|
6
7
|
value: string | number;
|
|
7
8
|
display_name: string;
|
|
@@ -34,11 +35,13 @@ export type GridEnrichedBySchemaColDef = GridBySchemaColDef | GridActionsBySchem
|
|
|
34
35
|
export interface DataSchemaColumnsType {
|
|
35
36
|
data: Item[];
|
|
36
37
|
schema: SchemaType;
|
|
38
|
+
modelOptions: modelOptionsType;
|
|
37
39
|
columns?: GridEnrichedBySchemaColDef[];
|
|
38
40
|
}
|
|
39
41
|
export interface ItemSchemaColumnsType {
|
|
40
42
|
data: Item;
|
|
41
43
|
schema: SchemaType;
|
|
44
|
+
modelOptions: modelOptionsType;
|
|
42
45
|
columns?: GridEnrichedBySchemaColDef[];
|
|
43
46
|
}
|
|
44
47
|
export declare const emptyByType: any;
|
package/dist/utils.js
CHANGED
package/package.json
CHANGED