argous 1.2.149 → 1.2.152

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.
@@ -95,13 +95,13 @@ var useStyles = core_1.makeStyles(function (theme) { return ({
95
95
  },
96
96
  }); });
97
97
  var ArgousAvatar = react_1.default.forwardRef(function (_a, ref) {
98
- var nome = _a.nome, src = _a.src, className = _a.className, idUsuario = _a.idUsuario, props = __rest(_a, ["nome", "src", "className", "idUsuario"]);
98
+ var nome = _a.nome, src = _a.src, className = _a.className, idUsuario = _a.idUsuario, forwardedBlockSearch = _a.forwardedBlockSearch, props = __rest(_a, ["nome", "src", "className", "idUsuario", "forwardedBlockSearch"]);
99
99
  var classes = useStyles();
100
100
  var cores = [classes.orange, classes.purple, classes.blue, classes.rosa, classes.cinza, classes.red, classes.amarelo, classes.marrom, classes.preto, classes.green];
101
101
  var _b = react_1.useState(undefined), userImage = _b[0], setUserImage = _b[1];
102
102
  react_1.useEffect(function () {
103
103
  setUserImage(localStorage.getItem("imgUsuario-" + idUsuario) || '');
104
- if (!idUsuario || userImage || localStorage.getItem("imgUsuario-" + idUsuario))
104
+ if (!idUsuario || userImage || localStorage.getItem("imgUsuario-" + idUsuario) || (forwardedBlockSearch === null || forwardedBlockSearch === void 0 ? void 0 : forwardedBlockSearch.return))
105
105
  return;
106
106
  api_1.fetchToArgous('aguserimage', { idUsuario: idUsuario })
107
107
  .then(function (_a) {
@@ -87,6 +87,7 @@ var lab_1 = require("@material-ui/lab");
87
87
  var clsx_1 = __importDefault(require("clsx"));
88
88
  var lodash_1 = require("lodash");
89
89
  var react_1 = __importStar(require("react"));
90
+ var io_1 = require("react-icons/io");
90
91
  var useStyles = core_1.makeStyles(function (theme) { return ({
91
92
  subHeader: {
92
93
  display: 'flex',
@@ -168,6 +169,13 @@ var useStyles = core_1.makeStyles(function (theme) { return ({
168
169
  '&::-webkit-scrollbar-thumb': {
169
170
  background: theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.1)' : 'rgba(255, 255, 255, 0.1)'
170
171
  }
172
+ },
173
+ searchButton: {
174
+ color: theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.4)' : 'rgba(255, 255, 255, 0.5)',
175
+ '&:hover': {
176
+ color: theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.8)' : 'rgba(255, 255, 255, 0.9)',
177
+ background: '#0000'
178
+ }
171
179
  }
172
180
  }); });
173
181
  exports.CustomTooltip = core_1.withStyles(function (theme) { return ({
@@ -274,7 +282,8 @@ var ListboxFavorites = react_1.forwardRef(function (props, ref) {
274
282
  });
275
283
  });
276
284
  var AutoCompleteFavorites = function (_a) {
277
- 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"]);
285
+ var action = _a.action, busca = _a.busca, resposta = _a.resposta, autoSearch = _a.autoSearch, 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", "autoSearch", "label", "value", "pgCode", "favoritePage", "groupName", "groupHeaderColor", "groupTitleColor", "loadingColor", "filterFunction", "getOptionLabel", "onChange", "textFieldProps", "searchParams"]);
286
+ var classes = useStyles();
278
287
  var _d = react_1.useState({
279
288
  lista: [],
280
289
  slide: true,
@@ -284,6 +293,20 @@ var AutoCompleteFavorites = function (_a) {
284
293
  }), dados = _d[0], setDados = _d[1];
285
294
  var _e = react_1.useState(false), loading = _e[0], setLoading = _e[1];
286
295
  var _f = react_1.useState(''), inputValue = _f[0], setInputValue = _f[1];
296
+ var interval = react_1.useRef(null);
297
+ var _g = react_1.useState(1), seconds = _g[0], setSeconds = _g[1];
298
+ var startCounter = function () { return interval.current = setInterval(function () { return setSeconds(1); }, 1000); };
299
+ var stopCounter = function () {
300
+ clearInterval(interval.current);
301
+ setSeconds(0);
302
+ };
303
+ var setInput = function (value) {
304
+ if (loading)
305
+ return;
306
+ stopCounter();
307
+ setInputValue(value);
308
+ autoSearch && startCounter();
309
+ };
287
310
  function carimbaLista(lista) {
288
311
  return __awaiter(this, void 0, void 0, function () {
289
312
  var completo;
@@ -306,6 +329,7 @@ var AutoCompleteFavorites = function (_a) {
306
329
  return __generator(this, function (_c) {
307
330
  switch (_c.label) {
308
331
  case 0:
332
+ stopCounter();
309
333
  setLoading(true);
310
334
  return [4 /*yield*/, api_1.serverAction(action, __assign((_a = {}, _a[busca] = valor || inputValue, _a), searchParams), true, pgCode)];
311
335
  case 1:
@@ -327,12 +351,14 @@ var AutoCompleteFavorites = function (_a) {
327
351
  }
328
352
  });
329
353
  }); }, [inputValue, searchParams]);
330
- react_1.useEffect(function () { return buscar(); }, [inputValue, buscar]);
354
+ react_1.useEffect(function () { return autoSearch && seconds === 1 && buscar(); }, [autoSearch, seconds, buscar]);
331
355
  // eslint-disable-next-line react-hooks/exhaustive-deps
332
356
  react_1.useEffect(function () { return lodash_1.isString(value) && buscar(value); }, []);
333
- 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,
357
+ return (react_1.default.createElement(lab_1.Autocomplete, __assign({}, props, { value: value, onChange: onChange }, { autoComplete: true, autoHighlight: true, openText: 'Abrir', clearText: 'Limpar', filterSelectedOptions: true, onInputChange: function (e) { var _a; return setInput(((_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; }, 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', 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, renderInput: function (params) { return (react_1.default.createElement(core_1.TextField, __assign({ margin: 'dense', variant: 'outlined', label: label }, params, textFieldProps, { onKeyUp: function (e) { return ((e.key === 'Enter' || e.key === 'Tab') && !loading) && buscar(); }, inputProps: __assign(__assign({}, params.inputProps), { onKeyDown: function (e) { return (e.key === 'Enter' || e.key === 'Tab') && e.stopPropagation(); } }), InputProps: __assign(__assign(__assign({}, textFieldProps.InputProps), params.InputProps), { endAdornment: (react_1.default.createElement(react_1.default.Fragment, null,
334
358
  params.InputProps.endAdornment,
335
359
  react_1.default.createElement(core_1.Fade, { in: loading },
336
- 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 } })));
360
+ react_1.default.createElement(core_1.CircularProgress, { disableShrink: true, color: loadingColor || 'inherit', size: 20 })),
361
+ !autoSearch && react_1.default.createElement(core_1.IconButton, { size: 'small', onClick: function (e) { return buscar(); }, className: classes.searchButton },
362
+ react_1.default.createElement(io_1.IoIosSearch, { size: 20 })))) }) }))); }, ListboxComponent: ListboxFavorites, ListboxProps: { dados: dados, setDados: setDados, favoritePage: favoritePage, groupHeaderColor: groupHeaderColor, groupTitleColor: groupTitleColor } })));
337
363
  };
338
364
  exports.default = AutoCompleteFavorites;
@@ -50,14 +50,14 @@ const useStyles = makeStyles(theme => ({
50
50
  },
51
51
  }));
52
52
 
53
- const ArgousAvatar = React.forwardRef(({ nome, src, className, idUsuario, ...props }, ref) => {
53
+ const ArgousAvatar = React.forwardRef(({ nome, src, className, idUsuario, forwardedBlockSearch, ...props }, ref) => {
54
54
  const classes = useStyles();
55
55
  const cores = [classes.orange, classes.purple, classes.blue, classes.rosa, classes.cinza, classes.red, classes.amarelo, classes.marrom, classes.preto, classes.green];
56
56
  const [userImage, setUserImage] = useState(undefined);
57
57
 
58
58
  useEffect(() => {
59
59
  setUserImage(localStorage.getItem(`imgUsuario-${idUsuario}`) || '');
60
- if (!idUsuario || userImage || localStorage.getItem(`imgUsuario-${idUsuario}`)) return;
60
+ if (!idUsuario || userImage || localStorage.getItem(`imgUsuario-${idUsuario}`) || forwardedBlockSearch?.return) return;
61
61
  fetchToArgous('aguserimage', { idUsuario })
62
62
  .then(({ userImage }) => {
63
63
  if (userImage) {
@@ -1,9 +1,10 @@
1
1
  import { serverAction, setError } from '../../utils/api';
2
- import { CircularProgress, Fade, ListItem, ListItemText, ListSubheader, makeStyles, Slide, TextField, Tooltip, withStyles } from '@material-ui/core';
2
+ import { CircularProgress, Fade, IconButton, ListItem, ListItemText, ListSubheader, makeStyles, Slide, TextField, Tooltip, withStyles } from '@material-ui/core';
3
3
  import { Autocomplete } from '@material-ui/lab';
4
4
  import clsx from 'clsx';
5
5
  import { isObject, isString } from 'lodash';
6
- import React, { forwardRef, useCallback, useEffect, useState } from 'react';
6
+ import React, { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
7
+ import { IoIosSearch } from 'react-icons/io';
7
8
 
8
9
  const useStyles = makeStyles((theme) => ({
9
10
  subHeader: {
@@ -86,6 +87,13 @@ const useStyles = makeStyles((theme) => ({
86
87
  '&::-webkit-scrollbar-thumb': {
87
88
  background: theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.1)' : 'rgba(255, 255, 255, 0.1)'
88
89
  }
90
+ },
91
+ searchButton: {
92
+ color: theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.4)' : 'rgba(255, 255, 255, 0.5)',
93
+ '&:hover': {
94
+ color: theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.8)' : 'rgba(255, 255, 255, 0.9)',
95
+ background: '#0000'
96
+ }
89
97
  }
90
98
  }));
91
99
 
@@ -214,8 +222,9 @@ const ListboxFavorites = forwardRef((props, ref) => {
214
222
  ));
215
223
  });
216
224
 
217
- const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode, favoritePage, groupName, groupHeaderColor, groupTitleColor, loadingColor, filterFunction, getOptionLabel, onChange = e => e, textFieldProps = {}, searchParams, ...props }) => {
225
+ const AutoCompleteFavorites = ({ action, busca, resposta, autoSearch, label, value, pgCode, favoritePage, groupName, groupHeaderColor, groupTitleColor, loadingColor, filterFunction, getOptionLabel, onChange = e => e, textFieldProps = {}, searchParams, ...props }) => {
218
226
 
227
+ const classes = useStyles();
219
228
  const [dados, setDados] = useState({
220
229
  lista: [],
221
230
  slide: true,
@@ -226,6 +235,22 @@ const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode,
226
235
  const [loading, setLoading] = useState(false);
227
236
  const [inputValue, setInputValue] = useState('');
228
237
 
238
+ const interval = useRef(null);
239
+ const [seconds, setSeconds] = useState(1);
240
+
241
+ const startCounter = () => interval.current = setInterval(() => setSeconds(1), 1000);
242
+ const stopCounter = () => {
243
+ clearInterval(interval.current);
244
+ setSeconds(0);
245
+ };
246
+
247
+ const setInput = value => {
248
+ if (loading) return;
249
+ stopCounter();
250
+ setInputValue(value);
251
+ autoSearch && startCounter();
252
+ };
253
+
229
254
  async function carimbaLista(lista) {
230
255
  let completo = [];
231
256
  lista.map((arr, index) => {
@@ -237,6 +262,7 @@ const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode,
237
262
  }
238
263
 
239
264
  const buscar = useCallback(async valor => {
265
+ stopCounter();
240
266
  setLoading(true);
241
267
  const res = await serverAction(action, { [busca]: valor || inputValue, ...searchParams }, true, pgCode);
242
268
  if (res[resposta || 'result']?.length > 1) await carimbaLista(res[resposta || 'result']);
@@ -246,7 +272,7 @@ const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode,
246
272
  // eslint-disable-next-line react-hooks/exhaustive-deps
247
273
  }, [inputValue, searchParams]);
248
274
 
249
- useEffect(() => buscar(), [inputValue, buscar]);
275
+ useEffect(() => autoSearch && seconds === 1 && buscar(), [autoSearch, seconds, buscar]);
250
276
  // eslint-disable-next-line react-hooks/exhaustive-deps
251
277
  useEffect(() => isString(value) && buscar(value), []);
252
278
 
@@ -254,16 +280,16 @@ const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode,
254
280
  <Autocomplete
255
281
  {...props}
256
282
  {...{ value, onChange }}
257
- options={isObject(value) ? dados?.lista.filter(v => filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]) : dados?.lista}
258
- getOptionLabel={getOptionLabel && (option => getOptionLabel(option, dados?.lista))}
259
- noOptionsText={inputValue.length < 2 ? 'Digite para pesquisar' : 'Não Encontrado'}
260
- onInputChange={e => setInputValue(e?.target?.value || '')}
261
- getOptionSelected={(o, v) => o[0] === v}
262
283
  autoComplete
263
284
  autoHighlight
264
285
  openText='Abrir'
265
286
  clearText='Limpar'
266
287
  filterSelectedOptions
288
+ onInputChange={e => setInput(e?.target?.value || '')}
289
+ getOptionSelected={(o, v) => o[0] === v}
290
+ getOptionLabel={getOptionLabel && (option => getOptionLabel(option, dados?.lista))}
291
+ noOptionsText={inputValue.length < 2 ? 'Digite para pesquisar' : 'Não Encontrado'}
292
+ options={isObject(value) ? dados?.lista.filter(v => filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]) : dados?.lista}
267
293
  renderInput={params => (
268
294
  <TextField
269
295
  margin='dense'
@@ -271,6 +297,11 @@ const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode,
271
297
  label={label}
272
298
  {...params}
273
299
  {...textFieldProps}
300
+ onKeyUp={e => ((e.key === 'Enter' || e.key === 'Tab') && !loading) && buscar()}
301
+ inputProps={{
302
+ ...params.inputProps,
303
+ onKeyDown: e => (e.key === 'Enter' || e.key === 'Tab') && e.stopPropagation()
304
+ }}
274
305
  InputProps={{
275
306
  ...textFieldProps.InputProps,
276
307
  ...params.InputProps,
@@ -278,6 +309,7 @@ const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode,
278
309
  <React.Fragment>
279
310
  {params.InputProps.endAdornment}
280
311
  <Fade in={loading}><CircularProgress disableShrink color={loadingColor || 'inherit'} size={20} /></Fade>
312
+ {!autoSearch && <IconButton size='small' onClick={e => buscar()} className={classes.searchButton}><IoIosSearch size={20} /></IconButton>}
281
313
  </React.Fragment>
282
314
  )
283
315
  }}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "argous",
3
- "version": "1.2.149",
3
+ "version": "1.2.152",
4
4
  "description": "Argous.",
5
5
  "main": "lib/index.js",
6
6
  "author": "Carlos Schneider",