argous 1.2.172 → 1.2.173
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.
|
@@ -73,6 +73,10 @@ export interface UtilAutoCompleteProps extends Omit<AutocompleteProps<any, false
|
|
|
73
73
|
* Parametros utilizados no metodo de busca
|
|
74
74
|
*/
|
|
75
75
|
searchParams?: object,
|
|
76
|
+
/**
|
|
77
|
+
* Disponível para leitura apenas
|
|
78
|
+
*/
|
|
79
|
+
readOnly?: boolean,
|
|
76
80
|
/**
|
|
77
81
|
* Função para filtrar a lista de opções
|
|
78
82
|
*
|
|
@@ -147,9 +147,10 @@ var retornaType = function (type) {
|
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
149
|
var UtilAutoComplete = function (_a) {
|
|
150
|
-
var _b = _a.type, type = _b === void 0 ? '' : _b, label = _a.label, value = _a.value, _c = _a.textFieldProps, textFieldProps = _c === void 0 ? {} : _c, _d = _a.onChange, onChange = _d === void 0 ? function (e) { return e; } : _d, excluidos = _a.excluidos, idEmpresa = _a.idEmpresa, cdEstado = _a.cdEstado, cdUnimed = _a.cdUnimed, getOptionLabel = _a.getOptionLabel, _e = _a.pgCode, pgCode = _e === void 0 ? 'BuscasHelper' : _e, action = _a.action, busca = _a.busca, resposta = _a.resposta, searchParams = _a.searchParams, filterFunction = _a.filterFunction, forceUpdate = _a.forceUpdate, props = __rest(_a, ["type", "label", "value", "textFieldProps", "onChange", "excluidos", "idEmpresa", "cdEstado", "cdUnimed", "getOptionLabel", "pgCode", "action", "busca", "resposta", "searchParams", "filterFunction", "forceUpdate"]);
|
|
151
|
-
var _f = react_1.useState(
|
|
152
|
-
var _g = react_1.useState(
|
|
150
|
+
var _b = _a.type, type = _b === void 0 ? '' : _b, label = _a.label, value = _a.value, _c = _a.textFieldProps, textFieldProps = _c === void 0 ? {} : _c, _d = _a.onChange, onChange = _d === void 0 ? function (e) { return e; } : _d, excluidos = _a.excluidos, idEmpresa = _a.idEmpresa, cdEstado = _a.cdEstado, cdUnimed = _a.cdUnimed, getOptionLabel = _a.getOptionLabel, _e = _a.pgCode, pgCode = _e === void 0 ? 'BuscasHelper' : _e, action = _a.action, busca = _a.busca, resposta = _a.resposta, searchParams = _a.searchParams, filterFunction = _a.filterFunction, forceUpdate = _a.forceUpdate, readOnly = _a.readOnly, props = __rest(_a, ["type", "label", "value", "textFieldProps", "onChange", "excluidos", "idEmpresa", "cdEstado", "cdUnimed", "getOptionLabel", "pgCode", "action", "busca", "resposta", "searchParams", "filterFunction", "forceUpdate", "readOnly"]);
|
|
151
|
+
var _f = react_1.useState(false), open = _f[0], setOpen = _f[1];
|
|
152
|
+
var _g = react_1.useState([]), lista = _g[0], setLista = _g[1];
|
|
153
|
+
var _h = react_1.useState(''), inputValue = _h[0], setInputValue = _h[1];
|
|
153
154
|
var buscar = react_1.useCallback(function (valor) { return __awaiter(void 0, void 0, void 0, function () {
|
|
154
155
|
var res;
|
|
155
156
|
var _a;
|
|
@@ -167,12 +168,13 @@ var UtilAutoComplete = function (_a) {
|
|
|
167
168
|
react_1.useEffect(function () {
|
|
168
169
|
if (lodash_1.isString(value))
|
|
169
170
|
buscar(value);
|
|
171
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
170
172
|
}, []);
|
|
171
173
|
react_1.useEffect(function () {
|
|
172
174
|
// if (inputValue.length < 2) return;
|
|
173
175
|
buscar();
|
|
174
176
|
}, [inputValue, buscar]);
|
|
175
|
-
return (react_1.default.createElement(lab_1.Autocomplete, __assign({ options: lodash_1.isObject(value) ? lista.filter(function (v) { return filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]; }) : lista, getOptionSelected: function (o, v) { return o[0] === v; }, getOptionLabel: getOptionLabel ? (function (option) { return getOptionLabel(option, lista); }) : (function (option) { return retornaType(type).getLabel(option, lista); }), noOptionsText: inputValue.length < 2 ? 'Digite para pesquisar' : 'Não Encontrado', clearText: 'Limpar', openText: 'Abrir', onInputChange: function (e) { var _a; return setInputValue(((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.value) || ''); }, filterSelectedOptions: true, autoComplete: true, autoHighlight: true }, { value: value, onChange: onChange }, props, { renderInput: function (params) { return (react_1.default.createElement(core_1.TextField, __assign({ margin: 'dense', variant: 'outlined', label: label || retornaType(type).label }, params, textFieldProps, { InputProps: __assign(__assign({}, textFieldProps.InputProps), params.InputProps) }))); } })));
|
|
177
|
+
return (react_1.default.createElement(lab_1.Autocomplete, __assign({ open: open, onOpen: function () { return !readOnly && setOpen(true); }, onClose: function () { return setOpen(false); }, disableClearable: readOnly, options: lodash_1.isObject(value) ? lista.filter(function (v) { return filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]; }) : lista, getOptionSelected: function (o, v) { return o[0] === v; }, getOptionLabel: getOptionLabel ? (function (option) { return getOptionLabel(option, lista); }) : (function (option) { return retornaType(type).getLabel(option, lista); }), noOptionsText: inputValue.length < 2 ? 'Digite para pesquisar' : 'Não Encontrado', clearText: 'Limpar', openText: 'Abrir', onInputChange: function (e) { var _a; return setInputValue(((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.value) || ''); }, filterSelectedOptions: true, autoComplete: true, autoHighlight: true }, { value: value, onChange: onChange }, props, { renderInput: function (params) { return (react_1.default.createElement(core_1.TextField, __assign({ margin: 'dense', variant: 'outlined', label: label || retornaType(type).label }, params, textFieldProps, { InputProps: __assign(__assign({}, textFieldProps.InputProps), params.InputProps), inputProps: __assign(__assign(__assign({}, textFieldProps.inputProps), params.inputProps), { readOnly: readOnly }) }))); } })));
|
|
176
178
|
};
|
|
177
179
|
// UtilAutoComplete.propTypes = {
|
|
178
180
|
// type: PropTypes.oneOf(['beneficiarios', 'empresas', 'gruposUnimed', 'estados', 'cidades', 'unimeds', 'prestadores']).isRequired,
|
|
@@ -73,6 +73,10 @@ export interface UtilAutoCompleteProps extends Omit<AutocompleteProps<any, false
|
|
|
73
73
|
* Parametros utilizados no metodo de busca
|
|
74
74
|
*/
|
|
75
75
|
searchParams?: object,
|
|
76
|
+
/**
|
|
77
|
+
* Disponível para leitura apenas
|
|
78
|
+
*/
|
|
79
|
+
readOnly?: boolean,
|
|
76
80
|
/**
|
|
77
81
|
* Função para filtrar a lista de opções
|
|
78
82
|
*
|
|
@@ -69,17 +69,20 @@ const retornaType = type => {
|
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
-
const UtilAutoComplete = ({ type = '', label, value, textFieldProps = {}, onChange = e => e, excluidos, idEmpresa, cdEstado, cdUnimed, getOptionLabel, pgCode = 'BuscasHelper', action, busca, resposta, searchParams, filterFunction, forceUpdate, ...props }) => {
|
|
72
|
+
const UtilAutoComplete = ({ type = '', label, value, textFieldProps = {}, onChange = e => e, excluidos, idEmpresa, cdEstado, cdUnimed, getOptionLabel, pgCode = 'BuscasHelper', action, busca, resposta, searchParams, filterFunction, forceUpdate, readOnly, ...props }) => {
|
|
73
|
+
const [open, setOpen] = useState(false);
|
|
73
74
|
const [lista, setLista] = useState([]);
|
|
74
75
|
const [inputValue, setInputValue] = useState('');
|
|
75
76
|
|
|
76
77
|
const buscar = useCallback(async valor => {
|
|
77
78
|
const res = await serverAction(action || retornaType(type).action, { [busca || retornaType(type)?.busca || 'value']: valor || inputValue, excluidos, idEmpresa, cdEstado, cdUnimed, ...searchParams }, true, pgCode);
|
|
78
79
|
setLista(res[resposta || retornaType(type)?.res || 'result'] || []);
|
|
80
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
79
81
|
}, [inputValue, type, searchParams]);
|
|
80
82
|
|
|
81
83
|
useEffect(() => {
|
|
82
84
|
if (isString(value)) buscar(value);
|
|
85
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
83
86
|
}, []);
|
|
84
87
|
|
|
85
88
|
useEffect(() => {
|
|
@@ -89,6 +92,10 @@ const UtilAutoComplete = ({ type = '', label, value, textFieldProps = {}, onChan
|
|
|
89
92
|
|
|
90
93
|
return (
|
|
91
94
|
<Autocomplete
|
|
95
|
+
open={open}
|
|
96
|
+
onOpen={() => !readOnly && setOpen(true)}
|
|
97
|
+
onClose={() => setOpen(false)}
|
|
98
|
+
disableClearable={readOnly}
|
|
92
99
|
options={isObject(value) ? lista.filter(v => filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]) : lista}
|
|
93
100
|
getOptionSelected={(o, v) => o[0] === v}
|
|
94
101
|
getOptionLabel={getOptionLabel ? (option => getOptionLabel(option, lista)) : (option => retornaType(type).getLabel(option, lista)) }
|
|
@@ -109,6 +116,7 @@ const UtilAutoComplete = ({ type = '', label, value, textFieldProps = {}, onChan
|
|
|
109
116
|
{...params}
|
|
110
117
|
{...textFieldProps}
|
|
111
118
|
InputProps={{ ...textFieldProps.InputProps, ...params.InputProps }}
|
|
119
|
+
inputProps={{ ...textFieldProps.inputProps, ...params.inputProps, readOnly }}
|
|
112
120
|
/>
|
|
113
121
|
)}
|
|
114
122
|
/>
|