argous 1.2.139 → 1.2.143
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.
|
@@ -80,6 +80,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
80
80
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
81
81
|
};
|
|
82
82
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
83
|
+
exports.CustomTooltip = void 0;
|
|
83
84
|
var api_1 = require("../../utils/api");
|
|
84
85
|
var core_1 = require("@material-ui/core");
|
|
85
86
|
var lab_1 = require("@material-ui/lab");
|
|
@@ -169,81 +170,27 @@ var useStyles = core_1.makeStyles(function (theme) { return ({
|
|
|
169
170
|
}
|
|
170
171
|
}
|
|
171
172
|
}); });
|
|
172
|
-
|
|
173
|
+
exports.CustomTooltip = core_1.withStyles(function (theme) { return ({
|
|
173
174
|
tooltip: theme.palette.type === 'light' ? {
|
|
174
175
|
fontSize: 15,
|
|
175
176
|
fontWeight: 400,
|
|
176
|
-
color: '
|
|
177
|
+
color: '#FFF',
|
|
177
178
|
backgroundColor: '#333333e3',
|
|
178
179
|
} : {
|
|
179
180
|
fontSize: 15,
|
|
180
181
|
fontWeight: 400,
|
|
181
|
-
color: '
|
|
182
|
+
color: '#000',
|
|
182
183
|
backgroundColor: '#fbfbfbd1',
|
|
183
184
|
},
|
|
184
185
|
arrow: {
|
|
185
186
|
color: theme.palette.type === 'light' ? '#333333e3' : '#fbfbfbd1'
|
|
186
187
|
}
|
|
187
188
|
}); })(core_1.Tooltip);
|
|
188
|
-
var AutoCompleteFavorites = function (_a) {
|
|
189
|
-
var action = _a.action, busca = _a.busca, resposta = _a.resposta, label = _a.label, value = _a.value, pgCode = _a.pgCode, favoritePage = _a.favoritePage, groupName = _a.groupName, groupHeaderColor = _a.groupHeaderColor, groupTitleColor = _a.groupTitleColor, loadingColor = _a.loadingColor, filterFunction = _a.filterFunction, getOptionLabel = _a.getOptionLabel, _b = _a.onChange, onChange = _b === void 0 ? function (e) { return e; } : _b, _c = _a.textFieldProps, textFieldProps = _c === void 0 ? {} : _c, searchParams = _a.searchParams, props = __rest(_a, ["action", "busca", "resposta", "label", "value", "pgCode", "favoritePage", "groupName", "groupHeaderColor", "groupTitleColor", "loadingColor", "filterFunction", "getOptionLabel", "onChange", "textFieldProps", "searchParams"]);
|
|
190
|
-
var _d = react_1.useState({
|
|
191
|
-
lista: [],
|
|
192
|
-
slide: true,
|
|
193
|
-
direction: '',
|
|
194
|
-
favoritosLength: '',
|
|
195
|
-
pageNumber: favoritePage ? 1 : '',
|
|
196
|
-
}), dados = _d[0], setDados = _d[1];
|
|
197
|
-
var _e = react_1.useState(false), loading = _e[0], setLoading = _e[1];
|
|
198
|
-
var _f = react_1.useState(''), inputValue = _f[0], setInputValue = _f[1];
|
|
199
|
-
var buscar = react_1.useCallback(function (valor) { return __awaiter(void 0, void 0, void 0, function () {
|
|
200
|
-
var res;
|
|
201
|
-
var _a;
|
|
202
|
-
var _b;
|
|
203
|
-
return __generator(this, function (_c) {
|
|
204
|
-
switch (_c.label) {
|
|
205
|
-
case 0:
|
|
206
|
-
setLoading(true);
|
|
207
|
-
return [4 /*yield*/, api_1.serverAction(action, __assign((_a = {}, _a[busca] = valor || inputValue, _a), searchParams), true, pgCode)];
|
|
208
|
-
case 1:
|
|
209
|
-
res = _c.sent();
|
|
210
|
-
if (((_b = res[resposta || 'result']) === null || _b === void 0 ? void 0 : _b.length) > 1)
|
|
211
|
-
carimbaLista(res[resposta || 'result']);
|
|
212
|
-
else if (res[resposta || 'result'])
|
|
213
|
-
setDados({ lista: res[resposta || 'result'] || [] });
|
|
214
|
-
else
|
|
215
|
-
api_1.setError('Erro ao tentar buscar dados.');
|
|
216
|
-
setLoading(false);
|
|
217
|
-
return [2 /*return*/];
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
}); }, [inputValue, searchParams]);
|
|
221
|
-
function carimbaLista(lista) {
|
|
222
|
-
var completo = [];
|
|
223
|
-
lista.map(function (arr, index) {
|
|
224
|
-
index === 0 && favoritePage && setDados(function (v) { return (__assign(__assign({}, v), { favoritosLength: arr.length })); });
|
|
225
|
-
return arr.map(function (itemArr) { return itemArr.length < 3 && itemArr.push(groupName[index]); });
|
|
226
|
-
});
|
|
227
|
-
lista.forEach(function (v) {
|
|
228
|
-
for (var _i = 0, _a = v.values(); _i < _a.length; _i++) {
|
|
229
|
-
var item = _a[_i];
|
|
230
|
-
completo.push(item);
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
setDados(function (v) { return (__assign(__assign({}, v), { lista: completo })); });
|
|
234
|
-
}
|
|
235
|
-
react_1.useEffect(function () { return buscar(); }, [inputValue, buscar]);
|
|
236
|
-
react_1.useEffect(function () { return lodash_1.isString(value) && buscar(value); }, []);
|
|
237
|
-
return (react_1.default.createElement(lab_1.Autocomplete, __assign({ autoComplete: true, autoHighlight: true, openText: 'Abrir', clearText: 'Limpar', filterSelectedOptions: true, 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) || ''); }, options: lodash_1.isObject(value) ? dados === null || dados === void 0 ? void 0 : dados.lista.filter(function (v) { return filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]; }) : dados === null || dados === void 0 ? void 0 : dados.lista, getOptionLabel: getOptionLabel && (function (option) { return getOptionLabel(option, dados === null || dados === void 0 ? void 0 : dados.lista); }), getOptionSelected: function (o, v) { return o[0] === v; }, renderInput: function (params) { return (react_1.default.createElement(core_1.TextField, __assign({ margin: 'dense', variant: 'outlined', label: label }, params, textFieldProps, { InputProps: __assign(__assign(__assign({}, textFieldProps.InputProps), params.InputProps), { endAdornment: (react_1.default.createElement(react_1.default.Fragment, null,
|
|
238
|
-
params.InputProps.endAdornment,
|
|
239
|
-
react_1.default.createElement(core_1.Fade, { in: loading },
|
|
240
|
-
react_1.default.createElement(core_1.CircularProgress, { disableShrink: true, color: loadingColor || 'inherit', size: 20 })))) }) }))); } }, props, { value: value, onChange: onChange }, { ListboxComponent: ListboxFavorites, ListboxProps: { dados: dados, setDados: setDados, favoritePage: favoritePage, groupHeaderColor: groupHeaderColor, groupTitleColor: groupTitleColor } })));
|
|
241
|
-
};
|
|
242
|
-
exports.default = AutoCompleteFavorites;
|
|
243
189
|
var ListboxFavorites = react_1.forwardRef(function (props, ref) {
|
|
244
190
|
var classes = useStyles();
|
|
245
191
|
var children = props.children, favoritePage = props.favoritePage, dados = props.dados, setDados = props.setDados, groupHeaderColor = props.groupHeaderColor, groupTitleColor = props.groupTitleColor;
|
|
246
192
|
var pageNumber = dados.pageNumber, favoritosLength = dados.favoritosLength, direction = dados.direction, slide = dados.slide;
|
|
193
|
+
console.log('Listbox', children);
|
|
247
194
|
function retornaInicio() {
|
|
248
195
|
switch (pageNumber) {
|
|
249
196
|
case 1:
|
|
@@ -274,11 +221,11 @@ var ListboxFavorites = react_1.forwardRef(function (props, ref) {
|
|
|
274
221
|
function retornaEstrutura(sectionIndex, item) {
|
|
275
222
|
if (sectionIndex === 0 && favoritePage && favoritosLength > 7) {
|
|
276
223
|
return (react_1.default.createElement(core_1.Slide, { in: slide, direction: direction },
|
|
277
|
-
react_1.default.createElement(CustomTooltip, { title: item.props.children, arrow: true, enterDelay: '1000', enterNextDelay: '1000', placement: 'top-end', TransitionComponent: core_1.Fade, TransitionProps: { timeout: { enter: 100, exit: 500 } } },
|
|
224
|
+
react_1.default.createElement(exports.CustomTooltip, { title: item.props.children, arrow: true, enterDelay: '1000', enterNextDelay: '1000', placement: 'top-end', TransitionComponent: core_1.Fade, TransitionProps: { timeout: { enter: 100, exit: 500 } } },
|
|
278
225
|
react_1.default.createElement(core_1.ListItem, __assign({}, item.props, { key: item.key, className: classes.listItem }),
|
|
279
226
|
react_1.default.createElement(core_1.ListItemText, { primary: item.props.children, className: classes.listItemText })))));
|
|
280
227
|
}
|
|
281
|
-
return (react_1.default.createElement(CustomTooltip, { title: item.props.children, arrow: true, enterDelay: '1000', enterNextDelay: '1000', placement: 'top-end', TransitionComponent: core_1.Fade, TransitionProps: { timeout: { enter: 100, exit: 500 } } },
|
|
228
|
+
return (react_1.default.createElement(exports.CustomTooltip, { title: item.props.children, arrow: true, enterDelay: '1000', enterNextDelay: '1000', placement: 'top-end', TransitionComponent: core_1.Fade, TransitionProps: { timeout: { enter: 100, exit: 500 } } },
|
|
282
229
|
react_1.default.createElement(core_1.ListItem, __assign({}, item.props, { key: item.key, className: classes.listItem }),
|
|
283
230
|
react_1.default.createElement(core_1.ListItemText, { primary: item.props.children, className: classes.listItemText }))));
|
|
284
231
|
}
|
|
@@ -327,3 +274,77 @@ var ListboxFavorites = react_1.forwardRef(function (props, ref) {
|
|
|
327
274
|
retornaArray(sectionIndex, section).map(function (item, itemIndex) { return retornaEstrutura(sectionIndex, item); })));
|
|
328
275
|
});
|
|
329
276
|
});
|
|
277
|
+
var AutoCompleteFavorites = function (_a) {
|
|
278
|
+
var action = _a.action, busca = _a.busca, resposta = _a.resposta, label = _a.label, value = _a.value, pgCode = _a.pgCode, favoritePage = _a.favoritePage, groupName = _a.groupName, groupHeaderColor = _a.groupHeaderColor, groupTitleColor = _a.groupTitleColor, loadingColor = _a.loadingColor, filterFunction = _a.filterFunction, getOptionLabel = _a.getOptionLabel, _b = _a.onChange, onChange = _b === void 0 ? function (e) { return e; } : _b, _c = _a.textFieldProps, textFieldProps = _c === void 0 ? {} : _c, searchParams = _a.searchParams, props = __rest(_a, ["action", "busca", "resposta", "label", "value", "pgCode", "favoritePage", "groupName", "groupHeaderColor", "groupTitleColor", "loadingColor", "filterFunction", "getOptionLabel", "onChange", "textFieldProps", "searchParams"]);
|
|
279
|
+
var _d = react_1.useState({
|
|
280
|
+
lista: [],
|
|
281
|
+
slide: true,
|
|
282
|
+
direction: '',
|
|
283
|
+
favoritosLength: '',
|
|
284
|
+
pageNumber: favoritePage ? 1 : '',
|
|
285
|
+
}), dados = _d[0], setDados = _d[1];
|
|
286
|
+
var _e = react_1.useState(false), loading = _e[0], setLoading = _e[1];
|
|
287
|
+
var _f = react_1.useState(''), inputValue = _f[0], setInputValue = _f[1];
|
|
288
|
+
function carimbaLista(lista) {
|
|
289
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
290
|
+
var completo;
|
|
291
|
+
return __generator(this, function (_a) {
|
|
292
|
+
console.log('carimbaLista', lista);
|
|
293
|
+
completo = [];
|
|
294
|
+
lista.map(function (arr, index) {
|
|
295
|
+
index === 0 && favoritePage && setDados(function (v) { return (__assign(__assign({}, v), { favoritosLength: arr.length })); });
|
|
296
|
+
return arr.map(function (itemArr) { return itemArr.length < itemArr.length + 1 && itemArr.push(groupName[index]); });
|
|
297
|
+
});
|
|
298
|
+
console.log('listaCarimbada', lista);
|
|
299
|
+
// lista.forEach(v => {
|
|
300
|
+
// for (let item of v.values()) {
|
|
301
|
+
// completo.push(item);
|
|
302
|
+
// }
|
|
303
|
+
// });
|
|
304
|
+
lista.map(function (v) { return v.map(function (d) { return completo.push(d); }); });
|
|
305
|
+
console.log('carimbaLista completo', completo);
|
|
306
|
+
setDados(function (v) { return (__assign(__assign({}, v), { lista: completo })); });
|
|
307
|
+
return [2 /*return*/];
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
var buscar = react_1.useCallback(function (valor) { return __awaiter(void 0, void 0, void 0, function () {
|
|
312
|
+
var res;
|
|
313
|
+
var _a;
|
|
314
|
+
var _b;
|
|
315
|
+
return __generator(this, function (_c) {
|
|
316
|
+
switch (_c.label) {
|
|
317
|
+
case 0:
|
|
318
|
+
setLoading(true);
|
|
319
|
+
return [4 /*yield*/, api_1.serverAction(action, __assign((_a = {}, _a[busca] = valor || inputValue, _a), searchParams), true, pgCode)];
|
|
320
|
+
case 1:
|
|
321
|
+
res = _c.sent();
|
|
322
|
+
if (res)
|
|
323
|
+
console.log('Resposta busca', res);
|
|
324
|
+
if (!(((_b = res[resposta || 'result']) === null || _b === void 0 ? void 0 : _b.length) > 1)) return [3 /*break*/, 3];
|
|
325
|
+
return [4 /*yield*/, carimbaLista(res[resposta || 'result'])];
|
|
326
|
+
case 2:
|
|
327
|
+
_c.sent();
|
|
328
|
+
return [3 /*break*/, 4];
|
|
329
|
+
case 3:
|
|
330
|
+
if (res[resposta || 'result'])
|
|
331
|
+
setDados({ lista: res[resposta || 'result'] || [] });
|
|
332
|
+
else
|
|
333
|
+
api_1.setError('Erro ao tentar buscar dados.');
|
|
334
|
+
_c.label = 4;
|
|
335
|
+
case 4:
|
|
336
|
+
setLoading(false);
|
|
337
|
+
return [2 /*return*/];
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}); }, [inputValue, searchParams]);
|
|
341
|
+
react_1.useEffect(function () { return buscar(); }, [inputValue, buscar]);
|
|
342
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
343
|
+
react_1.useEffect(function () { return lodash_1.isString(value) && buscar(value); }, []);
|
|
344
|
+
console.log('Lista', dados.lista);
|
|
345
|
+
return (react_1.default.createElement(lab_1.Autocomplete, __assign({}, props, { value: value, onChange: onChange }, { options: lodash_1.isObject(value) ? dados === null || dados === void 0 ? void 0 : dados.lista.filter(function (v) { return filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]; }) : dados === null || dados === void 0 ? void 0 : dados.lista, getOptionLabel: getOptionLabel && (function (option) { return getOptionLabel(option, dados === null || dados === void 0 ? void 0 : dados.lista); }), noOptionsText: inputValue.length < 2 ? 'Digite para pesquisar' : 'Não Encontrado', 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) || ''); }, getOptionSelected: function (o, v) { return o[0] === v; }, autoComplete: true, autoHighlight: true, openText: 'Abrir', clearText: 'Limpar', filterSelectedOptions: true, renderInput: function (params) { return (react_1.default.createElement(core_1.TextField, __assign({ margin: 'dense', variant: 'outlined', label: label }, params, textFieldProps, { InputProps: __assign(__assign(__assign({}, textFieldProps.InputProps), params.InputProps), { endAdornment: (react_1.default.createElement(react_1.default.Fragment, null,
|
|
346
|
+
params.InputProps.endAdornment,
|
|
347
|
+
react_1.default.createElement(core_1.Fade, { in: loading },
|
|
348
|
+
react_1.default.createElement(core_1.CircularProgress, { disableShrink: true, color: loadingColor || 'inherit', size: 20 })))) }) }))); }, ListboxComponent: ListboxFavorites, ListboxProps: { dados: dados, setDados: setDados, favoritePage: favoritePage, groupHeaderColor: groupHeaderColor, groupTitleColor: groupTitleColor } })));
|
|
349
|
+
};
|
|
350
|
+
exports.default = AutoCompleteFavorites;
|
|
@@ -89,16 +89,16 @@ const useStyles = makeStyles((theme) => ({
|
|
|
89
89
|
}
|
|
90
90
|
}));
|
|
91
91
|
|
|
92
|
-
const CustomTooltip = withStyles((theme) => ({
|
|
92
|
+
export const CustomTooltip = withStyles((theme) => ({
|
|
93
93
|
tooltip: theme.palette.type === 'light' ? {
|
|
94
94
|
fontSize: 15,
|
|
95
95
|
fontWeight: 400,
|
|
96
|
-
color: '
|
|
96
|
+
color: '#FFF',
|
|
97
97
|
backgroundColor: '#333333e3',
|
|
98
98
|
} : {
|
|
99
99
|
fontSize: 15,
|
|
100
100
|
fontWeight: 400,
|
|
101
|
-
color: '
|
|
101
|
+
color: '#000',
|
|
102
102
|
backgroundColor: '#fbfbfbd1',
|
|
103
103
|
},
|
|
104
104
|
arrow: {
|
|
@@ -106,91 +106,14 @@ const CustomTooltip = withStyles((theme) => ({
|
|
|
106
106
|
}
|
|
107
107
|
}))(Tooltip);
|
|
108
108
|
|
|
109
|
-
const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode, favoritePage, groupName, groupHeaderColor, groupTitleColor, loadingColor, filterFunction, getOptionLabel, onChange = e => e, textFieldProps = {}, searchParams, ...props }) => {
|
|
110
|
-
|
|
111
|
-
const [dados, setDados] = useState({
|
|
112
|
-
lista: [],
|
|
113
|
-
slide: true,
|
|
114
|
-
direction: '',
|
|
115
|
-
favoritosLength: '',
|
|
116
|
-
pageNumber: favoritePage ? 1 : '',
|
|
117
|
-
});
|
|
118
|
-
const [loading, setLoading] = useState(false);
|
|
119
|
-
const [inputValue, setInputValue] = useState('');
|
|
120
|
-
|
|
121
|
-
const buscar = useCallback(async valor => {
|
|
122
|
-
setLoading(true);
|
|
123
|
-
const res = await serverAction(action, { [busca]: valor || inputValue, ...searchParams }, true, pgCode);
|
|
124
|
-
if (res[resposta || 'result']?.length > 1) carimbaLista(res[resposta || 'result']);
|
|
125
|
-
else if (res[resposta || 'result']) setDados({ lista: res[resposta || 'result'] || [] });
|
|
126
|
-
else setError('Erro ao tentar buscar dados.');
|
|
127
|
-
setLoading(false);
|
|
128
|
-
}, [inputValue, searchParams]);
|
|
129
|
-
|
|
130
|
-
function carimbaLista(lista) {
|
|
131
|
-
let completo = [];
|
|
132
|
-
lista.map((arr, index) => {
|
|
133
|
-
index === 0 && favoritePage && setDados(v => ({ ...v, favoritosLength: arr.length }));
|
|
134
|
-
return arr.map(itemArr => itemArr.length < 3 && itemArr.push(groupName[index]));
|
|
135
|
-
});
|
|
136
|
-
lista.forEach(v => {
|
|
137
|
-
for (let item of v.values()) {
|
|
138
|
-
completo.push(item);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
setDados(v => ({ ...v, lista: completo }));
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
useEffect(() => buscar(), [inputValue, buscar]);
|
|
145
|
-
useEffect(() => isString(value) && buscar(value), []);
|
|
146
|
-
|
|
147
|
-
return (
|
|
148
|
-
<Autocomplete
|
|
149
|
-
autoComplete
|
|
150
|
-
autoHighlight
|
|
151
|
-
openText='Abrir'
|
|
152
|
-
clearText='Limpar'
|
|
153
|
-
filterSelectedOptions
|
|
154
|
-
onInputChange={e => setInputValue(e?.target?.value || '')}
|
|
155
|
-
options={isObject(value) ? dados?.lista.filter(v => filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]) : dados?.lista}
|
|
156
|
-
getOptionLabel={getOptionLabel && (option => getOptionLabel(option, dados?.lista))}
|
|
157
|
-
getOptionSelected={(o, v) => o[0] === v}
|
|
158
|
-
renderInput={params => (
|
|
159
|
-
<TextField
|
|
160
|
-
margin='dense'
|
|
161
|
-
variant='outlined'
|
|
162
|
-
label={label}
|
|
163
|
-
{...params}
|
|
164
|
-
{...textFieldProps}
|
|
165
|
-
InputProps={{
|
|
166
|
-
...textFieldProps.InputProps,
|
|
167
|
-
...params.InputProps,
|
|
168
|
-
endAdornment: (
|
|
169
|
-
<>
|
|
170
|
-
{params.InputProps.endAdornment}
|
|
171
|
-
<Fade in={loading}><CircularProgress disableShrink color={loadingColor || 'inherit'} size={20} /></Fade>
|
|
172
|
-
</>
|
|
173
|
-
)
|
|
174
|
-
}}
|
|
175
|
-
/>
|
|
176
|
-
)}
|
|
177
|
-
{...props}
|
|
178
|
-
{...{ value, onChange }}
|
|
179
|
-
ListboxComponent={ListboxFavorites}
|
|
180
|
-
ListboxProps={{ dados, setDados, favoritePage, groupHeaderColor, groupTitleColor }}
|
|
181
|
-
/>
|
|
182
|
-
);
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
export default AutoCompleteFavorites;
|
|
186
|
-
|
|
187
|
-
|
|
188
109
|
const ListboxFavorites = forwardRef((props, ref) => {
|
|
189
110
|
|
|
190
111
|
const classes = useStyles();
|
|
191
112
|
const { children, favoritePage, dados, setDados, groupHeaderColor, groupTitleColor } = props;
|
|
192
113
|
const { pageNumber, favoritosLength, direction, slide } = dados;
|
|
193
114
|
|
|
115
|
+
console.log('Listbox', children);
|
|
116
|
+
|
|
194
117
|
function retornaInicio() {
|
|
195
118
|
switch (pageNumber) {
|
|
196
119
|
case 1:
|
|
@@ -279,11 +202,11 @@ const ListboxFavorites = forwardRef((props, ref) => {
|
|
|
279
202
|
<div onClick={e => buttonClick(e, 2)} className={clsx({ [classes.buttonActive]: pageNumber === 2 }, classes.button)}>2</div>
|
|
280
203
|
</div>
|
|
281
204
|
{favoritosLength > 14 &&
|
|
282
|
-
|
|
205
|
+
<React.Fragment>
|
|
283
206
|
<div className={classes.areaButton}>
|
|
284
207
|
<div onClick={e => buttonClick(e, 3)} className={clsx({ [classes.buttonActive]: pageNumber === 3 }, classes.button)}>3</div>
|
|
285
208
|
</div>
|
|
286
|
-
|
|
209
|
+
</React.Fragment>
|
|
287
210
|
}
|
|
288
211
|
</div>
|
|
289
212
|
</Fade>
|
|
@@ -291,4 +214,92 @@ const ListboxFavorites = forwardRef((props, ref) => {
|
|
|
291
214
|
{retornaArray(sectionIndex, section).map((item, itemIndex) => retornaEstrutura(sectionIndex, item))}
|
|
292
215
|
</ul>
|
|
293
216
|
));
|
|
294
|
-
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode, favoritePage, groupName, groupHeaderColor, groupTitleColor, loadingColor, filterFunction, getOptionLabel, onChange = e => e, textFieldProps = {}, searchParams, ...props }) => {
|
|
220
|
+
|
|
221
|
+
const [dados, setDados] = useState({
|
|
222
|
+
lista: [],
|
|
223
|
+
slide: true,
|
|
224
|
+
direction: '',
|
|
225
|
+
favoritosLength: '',
|
|
226
|
+
pageNumber: favoritePage ? 1 : '',
|
|
227
|
+
});
|
|
228
|
+
const [loading, setLoading] = useState(false);
|
|
229
|
+
const [inputValue, setInputValue] = useState('');
|
|
230
|
+
|
|
231
|
+
async function carimbaLista(lista) {
|
|
232
|
+
console.log('carimbaLista', lista);
|
|
233
|
+
let completo = [];
|
|
234
|
+
lista.map((arr, index) => {
|
|
235
|
+
index === 0 && favoritePage && setDados(v => ({ ...v, favoritosLength: arr.length }));
|
|
236
|
+
return arr.map(itemArr => itemArr.length < itemArr.length + 1 && itemArr.push(groupName[index]));
|
|
237
|
+
});
|
|
238
|
+
console.log('listaCarimbada', lista);
|
|
239
|
+
// lista.forEach(v => {
|
|
240
|
+
// for (let item of v.values()) {
|
|
241
|
+
// completo.push(item);
|
|
242
|
+
// }
|
|
243
|
+
// });
|
|
244
|
+
lista.map(v => v.map(d => completo.push(d)));
|
|
245
|
+
console.log('carimbaLista completo', completo);
|
|
246
|
+
setDados(v => ({ ...v, lista: completo }));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const buscar = useCallback(async valor => {
|
|
250
|
+
setLoading(true);
|
|
251
|
+
const res = await serverAction(action, { [busca]: valor || inputValue, ...searchParams }, true, pgCode);
|
|
252
|
+
if (res) console.log('Resposta busca', res);
|
|
253
|
+
if (res[resposta || 'result']?.length > 1) await carimbaLista(res[resposta || 'result']);
|
|
254
|
+
else if (res[resposta || 'result']) setDados({ lista: res[resposta || 'result'] || [] });
|
|
255
|
+
else setError('Erro ao tentar buscar dados.');
|
|
256
|
+
setLoading(false);
|
|
257
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
258
|
+
}, [inputValue, searchParams]);
|
|
259
|
+
|
|
260
|
+
useEffect(() => buscar(), [inputValue, buscar]);
|
|
261
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
262
|
+
useEffect(() => isString(value) && buscar(value), []);
|
|
263
|
+
|
|
264
|
+
console.log('Lista', dados.lista);
|
|
265
|
+
|
|
266
|
+
return (
|
|
267
|
+
<Autocomplete
|
|
268
|
+
{...props}
|
|
269
|
+
{...{ value, onChange }}
|
|
270
|
+
options={isObject(value) ? dados?.lista.filter(v => filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]) : dados?.lista}
|
|
271
|
+
getOptionLabel={getOptionLabel && (option => getOptionLabel(option, dados?.lista))}
|
|
272
|
+
noOptionsText={inputValue.length < 2 ? 'Digite para pesquisar' : 'Não Encontrado'}
|
|
273
|
+
onInputChange={e => setInputValue(e?.target?.value || '')}
|
|
274
|
+
getOptionSelected={(o, v) => o[0] === v}
|
|
275
|
+
autoComplete
|
|
276
|
+
autoHighlight
|
|
277
|
+
openText='Abrir'
|
|
278
|
+
clearText='Limpar'
|
|
279
|
+
filterSelectedOptions
|
|
280
|
+
renderInput={params => (
|
|
281
|
+
<TextField
|
|
282
|
+
margin='dense'
|
|
283
|
+
variant='outlined'
|
|
284
|
+
label={label}
|
|
285
|
+
{...params}
|
|
286
|
+
{...textFieldProps}
|
|
287
|
+
InputProps={{
|
|
288
|
+
...textFieldProps.InputProps,
|
|
289
|
+
...params.InputProps,
|
|
290
|
+
endAdornment: (
|
|
291
|
+
<React.Fragment>
|
|
292
|
+
{params.InputProps.endAdornment}
|
|
293
|
+
<Fade in={loading}><CircularProgress disableShrink color={loadingColor || 'inherit'} size={20} /></Fade>
|
|
294
|
+
</React.Fragment>
|
|
295
|
+
)
|
|
296
|
+
}}
|
|
297
|
+
/>
|
|
298
|
+
)}
|
|
299
|
+
ListboxComponent={ListboxFavorites}
|
|
300
|
+
ListboxProps={{ dados, setDados, favoritePage, groupHeaderColor, groupTitleColor }}
|
|
301
|
+
/>
|
|
302
|
+
);
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
export default AutoCompleteFavorites;
|