argous 1.2.135 → 1.2.136
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.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare var _default: React.ForwardRefExoticComponent<Pick<{
|
|
2
|
+
[x: string]: any;
|
|
3
|
+
action: any;
|
|
4
|
+
busca: any;
|
|
5
|
+
resposta: any;
|
|
6
|
+
label: any;
|
|
7
|
+
value: any;
|
|
8
|
+
pgCode: any;
|
|
9
|
+
favoritePage: any;
|
|
10
|
+
groupName: any;
|
|
11
|
+
groupHeaderColor: any;
|
|
12
|
+
groupTitleColor: any;
|
|
13
|
+
loadingColor: any;
|
|
14
|
+
filterFunction: any;
|
|
15
|
+
getOptionLabel: any;
|
|
16
|
+
onChange?: ((e: any) => any) | undefined;
|
|
17
|
+
textFieldProps?: {} | undefined;
|
|
18
|
+
searchParams: any;
|
|
19
|
+
}, string | number> & React.RefAttributes<any>>;
|
|
20
|
+
export default _default;
|
|
21
|
+
import React from "react";
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
33
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
34
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
35
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
36
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
37
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
38
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
42
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
43
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
44
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
45
|
+
function step(op) {
|
|
46
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
47
|
+
while (_) try {
|
|
48
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
49
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
50
|
+
switch (op[0]) {
|
|
51
|
+
case 0: case 1: t = op; break;
|
|
52
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
53
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
54
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
55
|
+
default:
|
|
56
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
57
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
58
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
59
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
60
|
+
if (t[2]) _.ops.pop();
|
|
61
|
+
_.trys.pop(); continue;
|
|
62
|
+
}
|
|
63
|
+
op = body.call(thisArg, _);
|
|
64
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
65
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
69
|
+
var t = {};
|
|
70
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
71
|
+
t[p] = s[p];
|
|
72
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
73
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
74
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
75
|
+
t[p[i]] = s[p[i]];
|
|
76
|
+
}
|
|
77
|
+
return t;
|
|
78
|
+
};
|
|
79
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
80
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
81
|
+
};
|
|
82
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
83
|
+
var api_1 = require("../../utils/api");
|
|
84
|
+
var core_1 = require("@material-ui/core");
|
|
85
|
+
var lab_1 = require("@material-ui/lab");
|
|
86
|
+
var clsx_1 = __importDefault(require("clsx"));
|
|
87
|
+
var lodash_1 = require("lodash");
|
|
88
|
+
var react_1 = __importStar(require("react"));
|
|
89
|
+
var useStyles = core_1.makeStyles(function (theme) { return ({
|
|
90
|
+
subHeader: {
|
|
91
|
+
display: 'flex',
|
|
92
|
+
alignItems: 'center',
|
|
93
|
+
justifyContent: 'space-between',
|
|
94
|
+
backgroundColor: theme.palette.background.default,
|
|
95
|
+
height: 25
|
|
96
|
+
},
|
|
97
|
+
divButton: {
|
|
98
|
+
display: 'flex',
|
|
99
|
+
alignItems: 'center',
|
|
100
|
+
justifyContent: 'center',
|
|
101
|
+
},
|
|
102
|
+
areaButton: {
|
|
103
|
+
padding: '0px 8px 0px 8px'
|
|
104
|
+
},
|
|
105
|
+
button: theme.palette.type === 'light' ? {
|
|
106
|
+
width: 15,
|
|
107
|
+
height: 15,
|
|
108
|
+
display: 'flex',
|
|
109
|
+
alignItems: 'center',
|
|
110
|
+
justifyContent: 'center',
|
|
111
|
+
cursor: 'pointer',
|
|
112
|
+
color: 'rgba(0, 0, 0, 0.4)',
|
|
113
|
+
'&:hover': {
|
|
114
|
+
fontWeight: 500,
|
|
115
|
+
color: '#000000',
|
|
116
|
+
}
|
|
117
|
+
} : {
|
|
118
|
+
width: 15,
|
|
119
|
+
height: 15,
|
|
120
|
+
display: 'flex',
|
|
121
|
+
alignItems: 'center',
|
|
122
|
+
justifyContent: 'center',
|
|
123
|
+
cursor: 'pointer',
|
|
124
|
+
color: 'rgba(255, 255, 255, 0.4)',
|
|
125
|
+
'&:hover': {
|
|
126
|
+
fontWeight: 500,
|
|
127
|
+
color: '#ffffff',
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
buttonActive: theme.palette.type === 'light' ? {
|
|
131
|
+
color: 'rgba(0, 0, 0, 0.8)',
|
|
132
|
+
'&:hover': {
|
|
133
|
+
fontWeight: 600,
|
|
134
|
+
}
|
|
135
|
+
} : {
|
|
136
|
+
color: 'rgba(255, 255, 255, 0.8)',
|
|
137
|
+
'&:hover': {
|
|
138
|
+
fontWeight: 600,
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
listItem: {
|
|
142
|
+
padding: 0,
|
|
143
|
+
width: '100%',
|
|
144
|
+
cursor: 'pointer',
|
|
145
|
+
'&:hover': {
|
|
146
|
+
background: theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.05)' : 'rgba(255, 255, 255, 0.08)'
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
listItemText: {
|
|
150
|
+
margin: 0,
|
|
151
|
+
width: '100%',
|
|
152
|
+
direction: 'ltr',
|
|
153
|
+
overflow: 'visible',
|
|
154
|
+
whiteSpace: 'nowrap',
|
|
155
|
+
textOverflow: 'ellipsis',
|
|
156
|
+
padding: '0px 0px 0px 6px',
|
|
157
|
+
},
|
|
158
|
+
box: {
|
|
159
|
+
padding: 0,
|
|
160
|
+
overflowX: 'hidden',
|
|
161
|
+
'&::-webkit-scrollbar': {
|
|
162
|
+
width: 5
|
|
163
|
+
},
|
|
164
|
+
'&::-webkit-scrollbar-track': {
|
|
165
|
+
background: '#0000'
|
|
166
|
+
},
|
|
167
|
+
'&::-webkit-scrollbar-thumb': {
|
|
168
|
+
background: theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.1)' : 'rgba(255, 255, 255, 0.1)'
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}); });
|
|
172
|
+
var CustomTooltip = core_1.withStyles(function (theme) { return ({
|
|
173
|
+
tooltip: theme.palette.type === 'light' ? {
|
|
174
|
+
fontSize: 15,
|
|
175
|
+
fontWeight: 400,
|
|
176
|
+
color: 'rgb(255, 255, 255)',
|
|
177
|
+
backgroundColor: '#333333e3',
|
|
178
|
+
} : {
|
|
179
|
+
fontSize: 15,
|
|
180
|
+
fontWeight: 400,
|
|
181
|
+
color: 'rgb(0, 0, 0)',
|
|
182
|
+
backgroundColor: '#fbfbfbd1',
|
|
183
|
+
},
|
|
184
|
+
arrow: {
|
|
185
|
+
color: theme.palette.type === 'light' ? '#333333e3' : '#fbfbfbd1'
|
|
186
|
+
}
|
|
187
|
+
}); })(core_1.Tooltip);
|
|
188
|
+
var ListboxFavorites = react_1.forwardRef(function (props, ref) {
|
|
189
|
+
var classes = useStyles();
|
|
190
|
+
var children = props.children, favoritePage = props.favoritePage, dados = props.dados, setDados = props.setDados, groupHeaderColor = props.groupHeaderColor, groupTitleColor = props.groupTitleColor;
|
|
191
|
+
var pageNumber = dados.pageNumber, favoritosLength = dados.favoritosLength, direction = dados.direction, slide = dados.slide;
|
|
192
|
+
function retornaInicio() {
|
|
193
|
+
switch (pageNumber) {
|
|
194
|
+
case 1:
|
|
195
|
+
return 0;
|
|
196
|
+
case 2:
|
|
197
|
+
return 7;
|
|
198
|
+
case 3:
|
|
199
|
+
return 14;
|
|
200
|
+
default: return;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function retornaFim() {
|
|
204
|
+
switch (pageNumber) {
|
|
205
|
+
case 1:
|
|
206
|
+
return 7;
|
|
207
|
+
case 2:
|
|
208
|
+
return 14;
|
|
209
|
+
case 3:
|
|
210
|
+
return favoritosLength;
|
|
211
|
+
default: return;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function retornaArray(sectionIndex, section) {
|
|
215
|
+
if (sectionIndex === 0 && favoritePage && favoritosLength > 7)
|
|
216
|
+
return section.props.children[1].props.children.slice(retornaInicio(), retornaFim());
|
|
217
|
+
return section.props.children[1].props.children;
|
|
218
|
+
}
|
|
219
|
+
function retornaEstrutura(sectionIndex, item) {
|
|
220
|
+
if (sectionIndex === 0 && favoritePage && favoritosLength > 7) {
|
|
221
|
+
return (react_1.default.createElement(core_1.Slide, { in: slide, direction: direction },
|
|
222
|
+
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 } } },
|
|
223
|
+
react_1.default.createElement(core_1.ListItem, __assign({}, item.props, { key: item.key, className: classes.listItem }),
|
|
224
|
+
react_1.default.createElement(core_1.ListItemText, { primary: item.props.children, className: classes.listItemText })))));
|
|
225
|
+
}
|
|
226
|
+
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 } } },
|
|
227
|
+
react_1.default.createElement(core_1.ListItem, __assign({}, item.props, { key: item.key, className: classes.listItem }),
|
|
228
|
+
react_1.default.createElement(core_1.ListItemText, { primary: item.props.children, className: classes.listItemText }))));
|
|
229
|
+
}
|
|
230
|
+
function buttonClick(evento, value) {
|
|
231
|
+
evento.preventDefault();
|
|
232
|
+
evento.stopPropagation();
|
|
233
|
+
if (value !== pageNumber) {
|
|
234
|
+
verificaSaidaSlide(value);
|
|
235
|
+
setDados(function (v) { return (__assign(__assign({}, v), { slide: false })); });
|
|
236
|
+
setTimeout(function () {
|
|
237
|
+
setDados(function (v) { return (__assign(__assign({}, v), { pageNumber: value, direction: retornaDirection(value) })); });
|
|
238
|
+
setTimeout(function () { return setDados(function (v) { return (__assign(__assign({}, v), { slide: true })); }); }, 100);
|
|
239
|
+
}, 200);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function verificaSaidaSlide(value) {
|
|
243
|
+
var direction = '';
|
|
244
|
+
if ((value === 2 || value === 3) && pageNumber === 1)
|
|
245
|
+
direction = 'right';
|
|
246
|
+
else if (value === 3 && pageNumber === 2)
|
|
247
|
+
direction = 'right';
|
|
248
|
+
else if (value === 1 && pageNumber === 2)
|
|
249
|
+
direction = 'left';
|
|
250
|
+
direction && setDados(function (v) { return (__assign(__assign({}, v), { direction: direction })); });
|
|
251
|
+
}
|
|
252
|
+
function retornaDirection(value) {
|
|
253
|
+
if (value < pageNumber)
|
|
254
|
+
return 'right';
|
|
255
|
+
return 'left';
|
|
256
|
+
}
|
|
257
|
+
return children.map(function (section, sectionIndex) {
|
|
258
|
+
var _a, _b, _c;
|
|
259
|
+
return (react_1.default.createElement("ul", __assign({}, props, { className: clsx_1.default('MuiAutocomplete-listbox', classes.box) }),
|
|
260
|
+
react_1.default.createElement(core_1.ListSubheader, { className: classes.subHeader, style: { backgroundColor: groupHeaderColor === null || groupHeaderColor === void 0 ? void 0 : groupHeaderColor[sectionIndex], color: groupTitleColor === null || groupTitleColor === void 0 ? void 0 : groupTitleColor[sectionIndex] } },
|
|
261
|
+
section.props.children[0].props.children,
|
|
262
|
+
react_1.default.createElement(core_1.Fade, { in: sectionIndex === 0 && favoritePage && favoritosLength > 7 },
|
|
263
|
+
react_1.default.createElement("div", { className: classes.divButton },
|
|
264
|
+
react_1.default.createElement("div", { className: classes.areaButton },
|
|
265
|
+
react_1.default.createElement("div", { onClick: function (e) { return buttonClick(e, 1); }, className: clsx_1.default((_a = {}, _a[classes.buttonActive] = pageNumber === 1, _a), classes.button) }, "1")),
|
|
266
|
+
react_1.default.createElement("div", { className: classes.areaButton },
|
|
267
|
+
react_1.default.createElement("div", { onClick: function (e) { return buttonClick(e, 2); }, className: clsx_1.default((_b = {}, _b[classes.buttonActive] = pageNumber === 2, _b), classes.button) }, "2")),
|
|
268
|
+
favoritosLength > 14 &&
|
|
269
|
+
react_1.default.createElement(react_1.default.Fragment, null,
|
|
270
|
+
react_1.default.createElement("div", { className: classes.areaButton },
|
|
271
|
+
react_1.default.createElement("div", { onClick: function (e) { return buttonClick(e, 3); }, className: clsx_1.default((_c = {}, _c[classes.buttonActive] = pageNumber === 3, _c), classes.button) }, "3")))))),
|
|
272
|
+
retornaArray(sectionIndex, section).map(function (item, itemIndex) { return retornaEstrutura(sectionIndex, item); })));
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
var AutoCompleteFavorites = function (_a) {
|
|
276
|
+
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"]);
|
|
277
|
+
var _d = react_1.useState({
|
|
278
|
+
lista: [],
|
|
279
|
+
slide: true,
|
|
280
|
+
direction: '',
|
|
281
|
+
favoritosLength: '',
|
|
282
|
+
pageNumber: favoritePage ? 1 : '',
|
|
283
|
+
}), dados = _d[0], setDados = _d[1];
|
|
284
|
+
var _e = react_1.useState(false), loading = _e[0], setLoading = _e[1];
|
|
285
|
+
var _f = react_1.useState(''), inputValue = _f[0], setInputValue = _f[1];
|
|
286
|
+
var buscar = react_1.useCallback(function (valor) { return __awaiter(void 0, void 0, void 0, function () {
|
|
287
|
+
var res;
|
|
288
|
+
var _a;
|
|
289
|
+
var _b;
|
|
290
|
+
return __generator(this, function (_c) {
|
|
291
|
+
switch (_c.label) {
|
|
292
|
+
case 0:
|
|
293
|
+
setLoading(true);
|
|
294
|
+
return [4 /*yield*/, api_1.serverAction(action, __assign((_a = {}, _a[busca] = valor || inputValue, _a), searchParams), true, pgCode)];
|
|
295
|
+
case 1:
|
|
296
|
+
res = _c.sent();
|
|
297
|
+
if (((_b = res[resposta || 'result']) === null || _b === void 0 ? void 0 : _b.length) > 1)
|
|
298
|
+
carimbaLista(res[resposta || 'result']);
|
|
299
|
+
else if (res[resposta || 'result'])
|
|
300
|
+
setDados(function (v) { return (__assign(__assign({}, v), { lista: res[resposta || 'result'] || [] })); });
|
|
301
|
+
else
|
|
302
|
+
api_1.setError('Erro ao tentar buscar dados.');
|
|
303
|
+
setLoading(false);
|
|
304
|
+
return [2 /*return*/];
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}); }, [inputValue, searchParams]);
|
|
308
|
+
function carimbaLista(lista) {
|
|
309
|
+
var completo = [];
|
|
310
|
+
lista.map(function (arr, index) {
|
|
311
|
+
index === 0 && favoritePage && setDados(function (v) { return (__assign(__assign({}, v), { favoritosLength: arr.length })); });
|
|
312
|
+
return arr.map(function (itemArr) { return itemArr.length < 3 && itemArr.push(groupName[index]); });
|
|
313
|
+
});
|
|
314
|
+
lista.forEach(function (v) {
|
|
315
|
+
for (var _i = 0, _a = v.values(); _i < _a.length; _i++) {
|
|
316
|
+
var item = _a[_i];
|
|
317
|
+
completo.push(item);
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
setDados(function (v) { return (__assign(__assign({}, v), { lista: completo })); });
|
|
321
|
+
}
|
|
322
|
+
react_1.useEffect(function () { return buscar(); }, [inputValue, buscar]);
|
|
323
|
+
react_1.useEffect(function () { return lodash_1.isString(value) && buscar(value); }, []);
|
|
324
|
+
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; }, renderTags: function (value, getTagProps) {
|
|
325
|
+
return value.map(function (option, index) { return (react_1.default.createElement(core_1.Chip, __assign({ variant: 'outlined', size: 'small', label: option }, getTagProps({ index: index })))); });
|
|
326
|
+
}, 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,
|
|
327
|
+
params.InputProps.endAdornment,
|
|
328
|
+
react_1.default.createElement(core_1.Fade, { in: loading },
|
|
329
|
+
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 } })));
|
|
330
|
+
};
|
|
331
|
+
exports.default = react_1.forwardRef(AutoCompleteFavorites);
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { serverAction, setError } from '../../utils/api';
|
|
2
|
+
import { Chip, CircularProgress, Fade, ListItem, ListItemText, ListSubheader, makeStyles, Slide, TextField, Tooltip, withStyles } from '@material-ui/core';
|
|
3
|
+
import { Autocomplete } from '@material-ui/lab';
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
import { isObject, isString } from 'lodash';
|
|
6
|
+
import React, { forwardRef, useCallback, useEffect, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
const useStyles = makeStyles((theme) => ({
|
|
9
|
+
subHeader: {
|
|
10
|
+
display: 'flex',
|
|
11
|
+
alignItems: 'center',
|
|
12
|
+
justifyContent: 'space-between',
|
|
13
|
+
backgroundColor: theme.palette.background.default,
|
|
14
|
+
height: 25
|
|
15
|
+
},
|
|
16
|
+
divButton: {
|
|
17
|
+
display: 'flex',
|
|
18
|
+
alignItems: 'center',
|
|
19
|
+
justifyContent: 'center',
|
|
20
|
+
},
|
|
21
|
+
areaButton: {
|
|
22
|
+
padding: '0px 8px 0px 8px'
|
|
23
|
+
},
|
|
24
|
+
button: theme.palette.type === 'light' ? {
|
|
25
|
+
width: 15,
|
|
26
|
+
height: 15,
|
|
27
|
+
display: 'flex',
|
|
28
|
+
alignItems: 'center',
|
|
29
|
+
justifyContent: 'center',
|
|
30
|
+
cursor: 'pointer',
|
|
31
|
+
color: 'rgba(0, 0, 0, 0.4)',
|
|
32
|
+
'&:hover': {
|
|
33
|
+
fontWeight: 500,
|
|
34
|
+
color: '#000000',
|
|
35
|
+
}
|
|
36
|
+
} : {
|
|
37
|
+
width: 15,
|
|
38
|
+
height: 15,
|
|
39
|
+
display: 'flex',
|
|
40
|
+
alignItems: 'center',
|
|
41
|
+
justifyContent: 'center',
|
|
42
|
+
cursor: 'pointer',
|
|
43
|
+
color: 'rgba(255, 255, 255, 0.4)',
|
|
44
|
+
'&:hover': {
|
|
45
|
+
fontWeight: 500,
|
|
46
|
+
color: '#ffffff',
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
buttonActive: theme.palette.type === 'light' ? {
|
|
50
|
+
color: 'rgba(0, 0, 0, 0.8)',
|
|
51
|
+
'&:hover': {
|
|
52
|
+
fontWeight: 600,
|
|
53
|
+
}
|
|
54
|
+
} : {
|
|
55
|
+
color: 'rgba(255, 255, 255, 0.8)',
|
|
56
|
+
'&:hover': {
|
|
57
|
+
fontWeight: 600,
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
listItem: {
|
|
61
|
+
padding: 0,
|
|
62
|
+
width: '100%',
|
|
63
|
+
cursor: 'pointer',
|
|
64
|
+
'&:hover': {
|
|
65
|
+
background: theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.05)' : 'rgba(255, 255, 255, 0.08)'
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
listItemText: {
|
|
69
|
+
margin: 0,
|
|
70
|
+
width: '100%',
|
|
71
|
+
direction: 'ltr',
|
|
72
|
+
overflow: 'visible',
|
|
73
|
+
whiteSpace: 'nowrap',
|
|
74
|
+
textOverflow: 'ellipsis',
|
|
75
|
+
padding: '0px 0px 0px 6px',
|
|
76
|
+
},
|
|
77
|
+
box: {
|
|
78
|
+
padding: 0,
|
|
79
|
+
overflowX: 'hidden',
|
|
80
|
+
'&::-webkit-scrollbar': {
|
|
81
|
+
width: 5
|
|
82
|
+
},
|
|
83
|
+
'&::-webkit-scrollbar-track': {
|
|
84
|
+
background: '#0000'
|
|
85
|
+
},
|
|
86
|
+
'&::-webkit-scrollbar-thumb': {
|
|
87
|
+
background: theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.1)' : 'rgba(255, 255, 255, 0.1)'
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}));
|
|
91
|
+
|
|
92
|
+
const CustomTooltip = withStyles((theme) => ({
|
|
93
|
+
tooltip: theme.palette.type === 'light' ? {
|
|
94
|
+
fontSize: 15,
|
|
95
|
+
fontWeight: 400,
|
|
96
|
+
color: 'rgb(255, 255, 255)',
|
|
97
|
+
backgroundColor: '#333333e3',
|
|
98
|
+
} : {
|
|
99
|
+
fontSize: 15,
|
|
100
|
+
fontWeight: 400,
|
|
101
|
+
color: 'rgb(0, 0, 0)',
|
|
102
|
+
backgroundColor: '#fbfbfbd1',
|
|
103
|
+
},
|
|
104
|
+
arrow: {
|
|
105
|
+
color: theme.palette.type === 'light' ? '#333333e3' : '#fbfbfbd1'
|
|
106
|
+
}
|
|
107
|
+
}))(Tooltip);
|
|
108
|
+
|
|
109
|
+
const ListboxFavorites = forwardRef((props, ref) => {
|
|
110
|
+
|
|
111
|
+
const classes = useStyles();
|
|
112
|
+
const { children, favoritePage, dados, setDados, groupHeaderColor, groupTitleColor } = props;
|
|
113
|
+
const { pageNumber, favoritosLength, direction, slide } = dados;
|
|
114
|
+
|
|
115
|
+
function retornaInicio() {
|
|
116
|
+
switch (pageNumber) {
|
|
117
|
+
case 1:
|
|
118
|
+
return 0;
|
|
119
|
+
case 2:
|
|
120
|
+
return 7;
|
|
121
|
+
case 3:
|
|
122
|
+
return 14;
|
|
123
|
+
default: return;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function retornaFim() {
|
|
128
|
+
switch (pageNumber) {
|
|
129
|
+
case 1:
|
|
130
|
+
return 7;
|
|
131
|
+
case 2:
|
|
132
|
+
return 14;
|
|
133
|
+
case 3:
|
|
134
|
+
return favoritosLength;
|
|
135
|
+
default: return;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function retornaArray(sectionIndex, section) {
|
|
140
|
+
if (sectionIndex === 0 && favoritePage && favoritosLength > 7) return section.props.children[1].props.children.slice(retornaInicio(), retornaFim());
|
|
141
|
+
return section.props.children[1].props.children;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function retornaEstrutura(sectionIndex, item) {
|
|
145
|
+
if (sectionIndex === 0 && favoritePage && favoritosLength > 7) {
|
|
146
|
+
return (
|
|
147
|
+
<Slide in={slide} direction={direction}>
|
|
148
|
+
<CustomTooltip title={item.props.children} arrow enterDelay='1000' enterNextDelay='1000' placement='top-end' TransitionComponent={Fade} TransitionProps={{ timeout: { enter: 100, exit: 500 } }}>
|
|
149
|
+
<ListItem {...item.props} key={item.key} className={classes.listItem}>
|
|
150
|
+
<ListItemText primary={item.props.children} className={classes.listItemText} />
|
|
151
|
+
</ListItem>
|
|
152
|
+
</CustomTooltip>
|
|
153
|
+
</Slide>
|
|
154
|
+
);
|
|
155
|
+
} return (
|
|
156
|
+
<CustomTooltip title={item.props.children} arrow enterDelay='1000' enterNextDelay='1000' placement='top-end' TransitionComponent={Fade} TransitionProps={{ timeout: { enter: 100, exit: 500 } }}>
|
|
157
|
+
<ListItem {...item.props} key={item.key} className={classes.listItem}>
|
|
158
|
+
<ListItemText primary={item.props.children} className={classes.listItemText} />
|
|
159
|
+
</ListItem>
|
|
160
|
+
</CustomTooltip>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function buttonClick(evento, value) {
|
|
165
|
+
evento.preventDefault();
|
|
166
|
+
evento.stopPropagation();
|
|
167
|
+
if (value !== pageNumber) {
|
|
168
|
+
verificaSaidaSlide(value);
|
|
169
|
+
setDados(v => ({ ...v, slide: false }));
|
|
170
|
+
setTimeout(() => {
|
|
171
|
+
setDados(v => ({ ...v, pageNumber: value, direction: retornaDirection(value) }));
|
|
172
|
+
setTimeout(() => setDados(v => ({ ...v, slide: true })), 100);
|
|
173
|
+
}, 200);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function verificaSaidaSlide(value) {
|
|
178
|
+
let direction = '';
|
|
179
|
+
if ((value === 2 || value === 3) && pageNumber === 1) direction = 'right';
|
|
180
|
+
else if (value === 3 && pageNumber === 2) direction = 'right';
|
|
181
|
+
else if (value === 1 && pageNumber === 2) direction = 'left';
|
|
182
|
+
direction && setDados(v => ({ ...v, direction: direction }));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function retornaDirection(value) {
|
|
186
|
+
if (value < pageNumber) return 'right';
|
|
187
|
+
return 'left';
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return children.map((section, sectionIndex) => (
|
|
191
|
+
<ul {...props} className={clsx('MuiAutocomplete-listbox', classes.box)}>
|
|
192
|
+
<ListSubheader className={classes.subHeader} style={{ backgroundColor: groupHeaderColor?.[sectionIndex], color: groupTitleColor?.[sectionIndex] }}>
|
|
193
|
+
{section.props.children[0].props.children}
|
|
194
|
+
<Fade in={sectionIndex === 0 && favoritePage && favoritosLength > 7}>
|
|
195
|
+
<div className={classes.divButton}>
|
|
196
|
+
<div className={classes.areaButton}>
|
|
197
|
+
<div onClick={e => buttonClick(e, 1)} className={clsx({ [classes.buttonActive]: pageNumber === 1 }, classes.button)}>1</div>
|
|
198
|
+
</div>
|
|
199
|
+
<div className={classes.areaButton}>
|
|
200
|
+
<div onClick={e => buttonClick(e, 2)} className={clsx({ [classes.buttonActive]: pageNumber === 2 }, classes.button)}>2</div>
|
|
201
|
+
</div>
|
|
202
|
+
{favoritosLength > 14 &&
|
|
203
|
+
<>
|
|
204
|
+
<div className={classes.areaButton}>
|
|
205
|
+
<div onClick={e => buttonClick(e, 3)} className={clsx({ [classes.buttonActive]: pageNumber === 3 }, classes.button)}>3</div>
|
|
206
|
+
</div>
|
|
207
|
+
</>
|
|
208
|
+
}
|
|
209
|
+
</div>
|
|
210
|
+
</Fade>
|
|
211
|
+
</ListSubheader>
|
|
212
|
+
{retornaArray(sectionIndex, section).map((item, itemIndex) => retornaEstrutura(sectionIndex, item))}
|
|
213
|
+
</ul>
|
|
214
|
+
));
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const AutoCompleteFavorites = ({ action, busca, resposta, label, value, pgCode, favoritePage, groupName, groupHeaderColor, groupTitleColor, loadingColor, filterFunction, getOptionLabel, onChange = e => e, textFieldProps = {}, searchParams, ...props }) => {
|
|
218
|
+
|
|
219
|
+
const [dados, setDados] = useState({
|
|
220
|
+
lista: [],
|
|
221
|
+
slide: true,
|
|
222
|
+
direction: '',
|
|
223
|
+
favoritosLength: '',
|
|
224
|
+
pageNumber: favoritePage ? 1 : '',
|
|
225
|
+
});
|
|
226
|
+
const [loading, setLoading] = useState(false);
|
|
227
|
+
const [inputValue, setInputValue] = useState('');
|
|
228
|
+
|
|
229
|
+
const buscar = useCallback(async valor => {
|
|
230
|
+
setLoading(true);
|
|
231
|
+
const res = await serverAction(action, { [busca]: valor || inputValue, ...searchParams }, true, pgCode);
|
|
232
|
+
if (res[resposta || 'result']?.length > 1) carimbaLista(res[resposta || 'result']);
|
|
233
|
+
else if (res[resposta || 'result']) setDados(v => ({ ...v, lista: res[resposta || 'result'] || [] }));
|
|
234
|
+
else setError('Erro ao tentar buscar dados.');
|
|
235
|
+
setLoading(false);
|
|
236
|
+
}, [inputValue, searchParams]);
|
|
237
|
+
|
|
238
|
+
function carimbaLista(lista) {
|
|
239
|
+
let completo = [];
|
|
240
|
+
lista.map((arr, index) => {
|
|
241
|
+
index === 0 && favoritePage && setDados(v => ({ ...v, favoritosLength: arr.length }));
|
|
242
|
+
return arr.map(itemArr => itemArr.length < 3 && itemArr.push(groupName[index]));
|
|
243
|
+
});
|
|
244
|
+
lista.forEach(v => {
|
|
245
|
+
for (let item of v.values()) {
|
|
246
|
+
completo.push(item);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
setDados(v => ({ ...v, lista: completo }));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
useEffect(() => buscar(), [inputValue, buscar]);
|
|
253
|
+
useEffect(() => isString(value) && buscar(value), []);
|
|
254
|
+
|
|
255
|
+
return (
|
|
256
|
+
<Autocomplete
|
|
257
|
+
autoComplete
|
|
258
|
+
autoHighlight
|
|
259
|
+
openText='Abrir'
|
|
260
|
+
clearText='Limpar'
|
|
261
|
+
filterSelectedOptions
|
|
262
|
+
onInputChange={e => setInputValue(e?.target?.value || '')}
|
|
263
|
+
options={isObject(value) ? dados?.lista.filter(v => filterFunction ? filterFunction(v, value) : true || v[0] !== value[0]) : dados?.lista}
|
|
264
|
+
getOptionLabel={getOptionLabel && (option => getOptionLabel(option, dados?.lista))}
|
|
265
|
+
getOptionSelected={(o, v) => o[0] === v}
|
|
266
|
+
renderTags={(value, getTagProps) =>
|
|
267
|
+
value.map((option, index) => (
|
|
268
|
+
<Chip variant='outlined' size='small' label={option} {...getTagProps({ index })} />
|
|
269
|
+
))
|
|
270
|
+
}
|
|
271
|
+
renderInput={params => (
|
|
272
|
+
<TextField
|
|
273
|
+
margin='dense'
|
|
274
|
+
variant='outlined'
|
|
275
|
+
label={label}
|
|
276
|
+
{...params}
|
|
277
|
+
{...textFieldProps}
|
|
278
|
+
InputProps={{
|
|
279
|
+
...textFieldProps.InputProps,
|
|
280
|
+
...params.InputProps,
|
|
281
|
+
endAdornment: (
|
|
282
|
+
<>
|
|
283
|
+
{params.InputProps.endAdornment}
|
|
284
|
+
<Fade in={loading}><CircularProgress disableShrink color={loadingColor || 'inherit'} size={20} /></Fade>
|
|
285
|
+
</>
|
|
286
|
+
)
|
|
287
|
+
}}
|
|
288
|
+
/>
|
|
289
|
+
)}
|
|
290
|
+
{...props}
|
|
291
|
+
{...{ value, onChange }}
|
|
292
|
+
ListboxComponent={ListboxFavorites}
|
|
293
|
+
ListboxProps={{ dados, setDados, favoritePage, groupHeaderColor, groupTitleColor }}
|
|
294
|
+
/>
|
|
295
|
+
);
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
export default forwardRef(AutoCompleteFavorites);
|