drf-react-by-schema 0.5.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/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 -3
- package/dist/components/GenericModelList.js +0 -1
- package/dist/context/APIWrapperContext.d.ts +4 -4
- package/package.json +1 -1
|
@@ -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 => {
|
|
@@ -55,7 +55,6 @@ const GenericModelList = ({ columnFields, hiddenFields = [], minWidthFields, ind
|
|
|
55
55
|
}
|
|
56
56
|
const { serverEndPoint, isInBatches, firstBatchLength } = context;
|
|
57
57
|
const { handleLoading } = apiContext;
|
|
58
|
-
;
|
|
59
58
|
const [data, setData] = (0, react_1.useState)(false);
|
|
60
59
|
const [visibleRows, setVisibleRows] = (0, react_1.useState)([]);
|
|
61
60
|
const [hideFooterPagination, setHideFooterPagination] = (0, react_1.useState)(false);
|
|
@@ -19,13 +19,13 @@ export interface PageFormType {
|
|
|
19
19
|
validationSchema: Item | null;
|
|
20
20
|
}
|
|
21
21
|
export interface OnEditModelType {
|
|
22
|
-
fieldKey
|
|
23
|
-
index
|
|
22
|
+
fieldKey?: string;
|
|
23
|
+
index?: string;
|
|
24
24
|
model: string;
|
|
25
25
|
id: Id;
|
|
26
26
|
labelKey: string;
|
|
27
|
-
setValue
|
|
28
|
-
getValues
|
|
27
|
+
setValue?: (p: any) => void;
|
|
28
|
+
getValues?: (p: any) => any;
|
|
29
29
|
}
|
|
30
30
|
export interface OnEditRelatedModelType {
|
|
31
31
|
model: string;
|
package/package.json
CHANGED