drf-react-by-schema 0.15.5 → 0.15.6
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.js +0 -1
- package/dist/components/forms/FieldBySchema.js +5 -5
- package/dist/components/forms/FormBySchema.js +15 -9
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts +1 -1
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.js +4 -1
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.js +7 -1
- package/dist/components/forms/inputs/FloatFieldBySchema.js +1 -1
- package/dist/components/forms/inputs/TextFieldBySchema.d.ts +1 -1
- package/dist/components/forms/inputs/TextFieldBySchema.js +7 -2
- package/dist/context/APIWrapperContext.d.ts +1 -1
- package/package.json +1 -1
|
@@ -26,9 +26,9 @@ function FieldBySchema(_a) {
|
|
|
26
26
|
var { name, schema, control, errors, multiline = false, setValue, getValues, 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
27
|
switch (schema[name].type) {
|
|
28
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)));
|
|
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, onValueChange: onValueChange }, other)));
|
|
30
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)));
|
|
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, onValueChange: onValueChange }, other)));
|
|
32
32
|
// case 'field':
|
|
33
33
|
// return (
|
|
34
34
|
// <AutocompleteFieldBySchema
|
|
@@ -45,9 +45,9 @@ function FieldBySchema(_a) {
|
|
|
45
45
|
case 'field':
|
|
46
46
|
const relatedEditable = schema[name].related_editable;
|
|
47
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 : undefined, multiple: multiple, sx: sx }, other)));
|
|
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 : undefined, multiple: multiple, sx: sx, onValueChange: onValueChange }, other)));
|
|
49
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 }));
|
|
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, onValueChange: onValueChange }));
|
|
51
51
|
case 'boolean':
|
|
52
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, onValueChange: onValueChange }, other)));
|
|
53
53
|
case 'decimal':
|
|
@@ -59,7 +59,7 @@ function FieldBySchema(_a) {
|
|
|
59
59
|
default:
|
|
60
60
|
const localMultiline = schema[name].model_multiline === true || multiline;
|
|
61
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)));
|
|
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', onValueChange: onValueChange }, other)));
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
exports.default = FieldBySchema;
|
|
@@ -98,17 +98,23 @@ function FormBySchema({ schema, control, errors, register, multiline = false, se
|
|
|
98
98
|
return { newFieldsLayout: [{ rows }], optionsACModels };
|
|
99
99
|
};
|
|
100
100
|
const populateOptionsAC = (optionsACModels) => __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
const promises = [];
|
|
102
|
+
const fieldsToLoad = [];
|
|
103
|
+
optionsACModels.map((field) => {
|
|
104
|
+
if (!optionsAC || !(field in optionsAC)) {
|
|
105
|
+
fieldsToLoad.push(field);
|
|
106
|
+
promises.push(isolatedGetAutoComplete
|
|
107
|
+
? isolatedGetAutoComplete(field)
|
|
108
|
+
: getAutoComplete(field));
|
|
109
|
+
}
|
|
110
|
+
});
|
|
101
111
|
const newOptionsAC = {};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
: yield getAutoComplete(model);
|
|
107
|
-
if (ret !== false) {
|
|
108
|
-
newOptionsAC[model] = ret;
|
|
109
|
-
}
|
|
112
|
+
const results = yield Promise.all(promises);
|
|
113
|
+
results.map((result, index) => {
|
|
114
|
+
if (result !== false) {
|
|
115
|
+
newOptionsAC[fieldsToLoad[index]] = result;
|
|
110
116
|
}
|
|
111
|
-
}
|
|
117
|
+
});
|
|
112
118
|
if (setOptionsAC) {
|
|
113
119
|
setOptionsAC(newOptionsAC);
|
|
114
120
|
return;
|
|
@@ -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,
|
|
3
|
+
export default function AutocompleteFieldBySchema({ fieldKey, index, name, schema, control, errors, optionIdKey, optionLabelKey, options, isSemaphoric, sx, onValueChange, ...other }: FieldBySchemaProps): React.JSX.Element;
|
|
@@ -55,7 +55,7 @@ const renderInput = (_a) => {
|
|
|
55
55
|
return (react_1.default.createElement(TextField_1.default, Object.assign({}, params, { label: label || schema[model].label, required: schema[model].required, margin: "normal", error: error, helperText: helperText, sx: sx })));
|
|
56
56
|
};
|
|
57
57
|
function AutocompleteFieldBySchema(_a) {
|
|
58
|
-
var { fieldKey, index, name, schema, control, errors, optionIdKey = 'id', optionLabelKey = 'label', options, isSemaphoric = false, sx = { mr: 2 },
|
|
58
|
+
var { fieldKey, index, name, schema, control, errors, optionIdKey = 'id', optionLabelKey = 'label', options, isSemaphoric = false, sx = { mr: 2 }, onValueChange } = _a, other = __rest(_a, ["fieldKey", "index", "name", "schema", "control", "errors", "optionIdKey", "optionLabelKey", "options", "isSemaphoric", "sx", "onValueChange"]);
|
|
59
59
|
const model = name;
|
|
60
60
|
const { theme } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
61
61
|
if (!options) {
|
|
@@ -70,6 +70,9 @@ function AutocompleteFieldBySchema(_a) {
|
|
|
70
70
|
return option[optionLabelKey];
|
|
71
71
|
}, onChange: (e, value) => {
|
|
72
72
|
field.onChange(value);
|
|
73
|
+
if (onValueChange) {
|
|
74
|
+
onValueChange(e);
|
|
75
|
+
}
|
|
73
76
|
}, fullWidth: true, renderInput: (params) => {
|
|
74
77
|
return renderInput(Object.assign(Object.assign({}, params), { control,
|
|
75
78
|
isSemaphoric,
|
|
@@ -49,7 +49,7 @@ const DialogActions_1 = __importDefault(require("../../DialogActions"));
|
|
|
49
49
|
const APIWrapperContext_1 = require("../../../context/APIWrapperContext");
|
|
50
50
|
const filter = (0, Autocomplete_1.createFilterOptions)();
|
|
51
51
|
const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, ref) => {
|
|
52
|
-
var { control, schema, errors, setValue, getValues, fieldKey, labelKey = 'nome', index, name = 'name', optionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, sx = { mr: 2 }, multiple = false, disabled = false } = _a, other = __rest(_a, ["control", "schema", "errors", "setValue", "getValues", "fieldKey", "labelKey", "index", "name", "optionsAC", "optionsModel", "getOptionLabel", "renderOption", "onEditModel", "sx", "multiple", "disabled"]);
|
|
52
|
+
var { control, schema, errors, setValue, getValues, fieldKey, labelKey = 'nome', index, name = 'name', optionsAC, optionsModel, getOptionLabel, renderOption, onEditModel, sx = { mr: 2 }, onValueChange, multiple = false, disabled = false } = _a, other = __rest(_a, ["control", "schema", "errors", "setValue", "getValues", "fieldKey", "labelKey", "index", "name", "optionsAC", "optionsModel", "getOptionLabel", "renderOption", "onEditModel", "sx", "onValueChange", "multiple", "disabled"]);
|
|
53
53
|
const { setDialog } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
54
54
|
const [options, setOptions] = (0, react_1.useState)(null);
|
|
55
55
|
const model = name;
|
|
@@ -132,6 +132,9 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, ref) =
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
field.onChange(multiple ? newValueAr : newValueAr[0]);
|
|
135
|
+
if (onValueChange) {
|
|
136
|
+
onValueChange(e);
|
|
137
|
+
}
|
|
135
138
|
}, renderInput: (params) => (react_1.default.createElement(TextField_1.default, Object.assign({}, params, { label: label, required: schema[model].required, margin: "normal", error: error, helperText: helperText, InputProps: Object.assign(Object.assign({}, params.InputProps), { endAdornment: (react_1.default.createElement(react_1.default.Fragment, null,
|
|
136
139
|
!multiple && field.value && (react_1.default.createElement(IconButton_1.default, { size: "small", onClick: () => {
|
|
137
140
|
if ((0, utils_1.isTmpId)(field.value.id)) {
|
|
@@ -209,6 +212,9 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, ref) =
|
|
|
209
212
|
}
|
|
210
213
|
return (react_1.default.createElement(react_hook_form_1.Controller, { control: control, name: name, render: ({ field }) => (react_1.default.createElement(Autocomplete_1.default, Object.assign({ key: name }, field, { id: name, options: options, disabled: schema[model].disabled === true || disabled === true, autoHighlight: true, isOptionEqualToValue: (option, value) => option.id === value.id, fullWidth: true, multiple: multiple, sx: sx, onChange: (e, value) => {
|
|
211
214
|
field.onChange(value);
|
|
215
|
+
if (onValueChange) {
|
|
216
|
+
onValueChange(e);
|
|
217
|
+
}
|
|
212
218
|
}, renderInput: (params) => (react_1.default.createElement(TextField_1.default, Object.assign({}, params, { label: label, required: schema[model].required, margin: "normal", error: error, helperText: helperText }, other))), getOptionLabel: getOptionLabel, renderOption: renderOption }))) }));
|
|
213
219
|
});
|
|
214
220
|
EditableAutocompleteFieldBySchema.displayName = 'EditableAutocompleteFieldBySchema';
|
|
@@ -49,7 +49,7 @@ function FloatFieldBySchema(_a) {
|
|
|
49
49
|
return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: (_a) => {
|
|
50
50
|
var _b = _a.field, { ref } = _b, field = __rest(_b, ["ref"]);
|
|
51
51
|
const moedaInputProps = Object.assign(Object.assign({}, field), { onChange: undefined });
|
|
52
|
-
return (react_1.default.createElement(react_number_format_1.NumericFormat, Object.assign({}, moedaInputProps, other, { label: label, required: schema[model].required, onValueChange: (values
|
|
52
|
+
return (react_1.default.createElement(react_number_format_1.NumericFormat, Object.assign({}, moedaInputProps, other, { label: label, required: schema[model].required, onValueChange: (values) => {
|
|
53
53
|
field.onChange(values.floatValue);
|
|
54
54
|
if (onValueChange) {
|
|
55
55
|
onValueChange(values.floatValue);
|
|
@@ -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): React.JSX.Element;
|
|
3
|
+
export default function TextFieldBySchema({ name, schema, control, errors, multiline, minRows, fieldKey, index, sx, isPassword, type, autocomplete, disabled, onValueChange, ...other }: FieldBySchemaProps): React.JSX.Element;
|
|
@@ -19,7 +19,7 @@ const react_hook_form_1 = require("react-hook-form");
|
|
|
19
19
|
const TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
20
20
|
const utils_1 = require("../../../utils");
|
|
21
21
|
function TextFieldBySchema(_a) {
|
|
22
|
-
var { name, schema, control, errors, multiline = false, minRows, fieldKey, index, sx = { mr: 2 }, isPassword = false, type, autocomplete, disabled } = _a, other = __rest(_a, ["name", "schema", "control", "errors", "multiline", "minRows", "fieldKey", "index", "sx", "isPassword", "type", "autocomplete", "disabled"]);
|
|
22
|
+
var { name, schema, control, errors, multiline = false, minRows, fieldKey, index, sx = { mr: 2 }, isPassword = false, type, autocomplete, disabled, onValueChange } = _a, other = __rest(_a, ["name", "schema", "control", "errors", "multiline", "minRows", "fieldKey", "index", "sx", "isPassword", "type", "autocomplete", "disabled", "onValueChange"]);
|
|
23
23
|
const model = name;
|
|
24
24
|
if (fieldKey && index && index >= 0) {
|
|
25
25
|
name = `${fieldKey}.${index}.${name}`;
|
|
@@ -39,6 +39,11 @@ function TextFieldBySchema(_a) {
|
|
|
39
39
|
error: errors && Boolean(errors[name]),
|
|
40
40
|
helperText: errors && errors[name] ? errors[name].message : schema[name].help_text || '',
|
|
41
41
|
};
|
|
42
|
-
return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: ({ field }) => (react_1.default.createElement(TextField_1.default, Object.assign({}, field, other, { id: name, key: name, label: schema[model].label, required: schema[model].required, disabled: schema[model].disabled === true || disabled,
|
|
42
|
+
return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: ({ field }) => (react_1.default.createElement(TextField_1.default, Object.assign({}, field, other, { id: name, key: name, label: schema[model].label, required: schema[model].required, disabled: schema[model].disabled === true || disabled, onChange: (e) => {
|
|
43
|
+
field.onChange(e.target.value);
|
|
44
|
+
if (onValueChange) {
|
|
45
|
+
onValueChange(e);
|
|
46
|
+
}
|
|
47
|
+
}, margin: "normal", fullWidth: true, multiline: multiline, error: error, helperText: helperText, sx: sx, type: type, autoComplete: autocomplete, minRows: minRows }))) }));
|
|
43
48
|
}
|
|
44
49
|
exports.default = TextFieldBySchema;
|
|
@@ -69,7 +69,7 @@ export interface APIWrapperContextType {
|
|
|
69
69
|
usuaria: Item | null;
|
|
70
70
|
updateUsuaria: () => void;
|
|
71
71
|
onSubmit: DRFReactBySchemaSubmitHandler;
|
|
72
|
-
loadSinglePageData: (p: LoadSinglePageDataProps) => Promise<
|
|
72
|
+
loadSinglePageData: (p: LoadSinglePageDataProps) => Promise<false | Item>;
|
|
73
73
|
handleLoading: (p: boolean) => void;
|
|
74
74
|
optionsACState: [OptionsAC | null, (x: Partial<OptionsAC>) => void];
|
|
75
75
|
pageFormState: [PageFormType | null, (x: Partial<PageFormType>) => void];
|
package/package.json
CHANGED