drf-react-by-schema 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +14 -16
- package/dist/api.js +89 -59
- package/dist/components/DataGridBySchemaEditable/FooterToolbar.d.ts +1 -1
- package/dist/components/DataGridBySchemaEditable/FooterToolbar.js +5 -11
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts +5 -5
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.js +33 -34
- package/dist/components/DataGridBySchemaEditable.d.ts +4 -1
- package/dist/components/DataGridBySchemaEditable.js +189 -133
- package/dist/components/GenericModelList.d.ts +3 -2
- package/dist/components/GenericModelList.js +68 -43
- package/dist/context/APIWrapper.js +9 -3
- package/dist/context/APIWrapperContext.d.ts +3 -7
- package/dist/utils.d.ts +16 -4
- package/dist/utils.js +7 -1
- package/package.json +3 -2
|
@@ -60,36 +60,36 @@ const filter = (0, Autocomplete_1.createFilterOptions)();
|
|
|
60
60
|
* }
|
|
61
61
|
* @returns {*} {JSX.Element}
|
|
62
62
|
*/
|
|
63
|
-
function SelectEditInputCell({ field, id, value, column, type, optionsAC, isIndexField, multiple = false, onEditModel, sx = {} }) {
|
|
63
|
+
function SelectEditInputCell({ field, id, value, column, type, optionsAC, isIndexField, multiple = false, onEditModel, sx = {}, }) {
|
|
64
64
|
// TODO: allow edit option label, as in formautocomplete!
|
|
65
65
|
const apiRef = (0, x_data_grid_1.useGridApiContext)();
|
|
66
|
+
console.log(column);
|
|
66
67
|
const handleChange = (newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
67
68
|
yield apiRef.current.setEditCellValue({ id, field, value: newValue });
|
|
68
69
|
apiRef.current.stopCellEditMode({ id, field });
|
|
69
70
|
});
|
|
70
|
-
const labelKey =
|
|
71
|
-
?
|
|
72
|
-
:
|
|
73
|
-
const valueKey =
|
|
74
|
-
?
|
|
75
|
-
:
|
|
71
|
+
const labelKey = ["field", "nested object"].includes(type) || isIndexField
|
|
72
|
+
? "label"
|
|
73
|
+
: "display_name";
|
|
74
|
+
const valueKey = ["field", "nested object"].includes(type) || isIndexField
|
|
75
|
+
? "id"
|
|
76
|
+
: "value";
|
|
76
77
|
let creatableProps = {};
|
|
77
78
|
// if (column.creatable || isIndexField) {
|
|
78
79
|
if (column.creatable) {
|
|
79
80
|
creatableProps = {
|
|
80
|
-
freesolo:
|
|
81
|
+
freesolo: "true",
|
|
81
82
|
filterOptions: (options, params) => {
|
|
82
83
|
const filtered = filter(options, params);
|
|
83
|
-
const inputValue =
|
|
84
|
-
? params.inputValue
|
|
85
|
-
: '';
|
|
84
|
+
const inputValue = params.inputValue ? params.inputValue : "";
|
|
86
85
|
const inputValueLower = inputValue.trim().toLowerCase();
|
|
87
86
|
// Suggest the creation of a new value
|
|
88
|
-
const isExisting = options.some(option => inputValueLower ===
|
|
89
|
-
|
|
87
|
+
const isExisting = options.some((option) => inputValueLower ===
|
|
88
|
+
option[labelKey].trim().toLowerCase());
|
|
89
|
+
if (inputValue !== "" && !isExisting) {
|
|
90
90
|
filtered.push({
|
|
91
91
|
inputValue,
|
|
92
|
-
[labelKey]: `Criar "${inputValue}"
|
|
92
|
+
[labelKey]: `Criar "${inputValue}"`,
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
return filtered;
|
|
@@ -97,7 +97,7 @@ function SelectEditInputCell({ field, id, value, column, type, optionsAC, isInde
|
|
|
97
97
|
handleHomeEndKeys: true,
|
|
98
98
|
getOptionLabel: (option) => {
|
|
99
99
|
// Value selected with enter, right from the input
|
|
100
|
-
if (typeof option ===
|
|
100
|
+
if (typeof option === "string") {
|
|
101
101
|
return option;
|
|
102
102
|
}
|
|
103
103
|
// Criar "xxx" option created dynamically
|
|
@@ -109,12 +109,13 @@ function SelectEditInputCell({ field, id, value, column, type, optionsAC, isInde
|
|
|
109
109
|
},
|
|
110
110
|
renderOption: (props, option) => {
|
|
111
111
|
return (react_1.default.createElement("li", Object.assign({ key: option[valueKey] }, props), option[labelKey]));
|
|
112
|
-
}
|
|
112
|
+
},
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
return (react_1.default.createElement(Autocomplete_1.default, Object.assign({ key: field, id: field, value: value, options: optionsAC.current && optionsAC.current[field]
|
|
116
|
+
? optionsAC.current[field]
|
|
117
|
+
: [], selectOnFocus: true, autoHighlight: true, multiple: multiple, isOptionEqualToValue: (option, value) => {
|
|
118
|
+
return option[labelKey] === value[labelKey];
|
|
118
119
|
}, getOptionLabel: (option) => {
|
|
119
120
|
return option[labelKey];
|
|
120
121
|
}, onChange: (e, value) => {
|
|
@@ -124,32 +125,30 @@ function SelectEditInputCell({ field, id, value, column, type, optionsAC, isInde
|
|
|
124
125
|
return;
|
|
125
126
|
}
|
|
126
127
|
let newValue = value;
|
|
127
|
-
if (typeof newValue ===
|
|
128
|
+
if (typeof newValue === "string") {
|
|
128
129
|
const tmpId = (0, utils_1.getTmpId)();
|
|
129
130
|
newValue = {
|
|
130
131
|
[valueKey]: tmpId,
|
|
131
|
-
[labelKey]: newValue
|
|
132
|
+
[labelKey]: newValue,
|
|
132
133
|
};
|
|
133
134
|
}
|
|
134
135
|
if (newValue && newValue.inputValue) {
|
|
135
136
|
const tmpId = (0, utils_1.getTmpId)();
|
|
136
137
|
newValue = {
|
|
137
138
|
[valueKey]: tmpId,
|
|
138
|
-
[labelKey]: newValue.inputValue
|
|
139
|
+
[labelKey]: newValue.inputValue,
|
|
139
140
|
};
|
|
140
141
|
}
|
|
141
142
|
handleChange(newValue);
|
|
142
|
-
}, fullWidth: true, renderInput: params => (react_1.default.createElement(react_1.default.Fragment, null, column.creatable
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
params.InputProps.endAdornment)) }) }))
|
|
153
|
-
: react_1.default.createElement(TextField_1.default, Object.assign({}, params, { sx: sx })))) }, creatableProps)));
|
|
143
|
+
}, fullWidth: true, renderInput: (params) => (react_1.default.createElement(react_1.default.Fragment, null, column.creatable ? (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,
|
|
144
|
+
!multiple && onEditModel && value && (react_1.default.createElement(IconButton_1.default, { size: "small", onClick: () => {
|
|
145
|
+
onEditModel({
|
|
146
|
+
model: field,
|
|
147
|
+
id: value[valueKey],
|
|
148
|
+
labelKey,
|
|
149
|
+
});
|
|
150
|
+
} },
|
|
151
|
+
react_1.default.createElement(Edit_1.default, null))),
|
|
152
|
+
params.InputProps.endAdornment)) }) }))) : (react_1.default.createElement(TextField_1.default, Object.assign({}, params, { sx: sx }))))) }, creatableProps)));
|
|
154
153
|
}
|
|
155
154
|
exports.SelectEditInputCell = SelectEditInputCell;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Item, SchemaType, Id, GridEnrichedBySchemaColDef } from '../utils';
|
|
2
|
+
import { Item, SchemaType, Id, GridEnrichedBySchemaColDef, PaginationModel } from '../utils';
|
|
3
3
|
import { SxProps } from '@mui/material';
|
|
4
4
|
import { OnEditModelType } from '../context/APIWrapperContext';
|
|
5
5
|
interface DataGridBySchemaEditableProps {
|
|
6
6
|
schema: SchemaType;
|
|
7
7
|
data: Item[];
|
|
8
|
+
rowCount?: number;
|
|
8
9
|
columns: GridEnrichedBySchemaColDef[];
|
|
9
10
|
model: string;
|
|
10
11
|
fieldKey?: string;
|
|
@@ -31,6 +32,8 @@ interface DataGridBySchemaEditableProps {
|
|
|
31
32
|
defaultValues?: Item;
|
|
32
33
|
hideFooterPagination?: boolean;
|
|
33
34
|
setVisibleRows?: (p: any) => void;
|
|
35
|
+
paginationModel?: PaginationModel;
|
|
36
|
+
setPaginationModel?: (x: PaginationModel) => void;
|
|
34
37
|
}
|
|
35
38
|
declare const DataGridBySchemaEditable: React.ForwardRefExoticComponent<DataGridBySchemaEditableProps & React.RefAttributes<unknown>>;
|
|
36
39
|
export default DataGridBySchemaEditable;
|