@credithub/harlan-components 1.83.5 → 1.83.8

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.
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { DataInput } from './types/iChart';
3
- declare const ChartContent: React.FC<{
3
+ declare const _default: React.NamedExoticComponent<{
4
4
  dataInput: DataInput;
5
5
  }>;
6
- export default ChartContent;
6
+ export default _default;
@@ -33,7 +33,7 @@ var ChartContainer = styled.div(templateObject_2 || (templateObject_2 = __makeTe
33
33
  var windowWidth = _a.windowWidth, chartType = _a.chartType;
34
34
  return getWidth(windowWidth, chartType);
35
35
  });
36
- var ChartContent = function (_a) {
36
+ var ChartContentBase = function (_a) {
37
37
  var dataInput = _a.dataInput;
38
38
  var windowWidth = useWindowSize().width;
39
39
  return (React.createElement(React.Fragment, null,
@@ -46,5 +46,5 @@ var ChartContent = function (_a) {
46
46
  React.createElement(MixedChart, { dataInput: dataInput }))),
47
47
  React.createElement(CategoriaProtesto, { dataInput: dataInput.protestosCategory || [] })));
48
48
  };
49
- export default ChartContent;
49
+ export default React.memo(ChartContentBase);
50
50
  var templateObject_1, templateObject_2;
@@ -57,7 +57,7 @@ import { areModulesLoaded } from '../../utils/isGlobalReady';
57
57
  import { formatMoney } from '../../utils/number';
58
58
  import { isCpf } from '../../utils/string';
59
59
  import { Spinner } from 'phosphor-react';
60
- import React, { useContext, useEffect, useMemo, useState } from 'react';
60
+ import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
61
61
  import styled from 'styled-components';
62
62
  import useToggle from '../../hooks/useToggle';
63
63
  import { ConsultasComplementaresContext } from '../consultasComplementares';
@@ -98,7 +98,7 @@ var ChartSystem = function (_a) {
98
98
  var consultaBoaVista = (_e = (_d = ctxConsultasComplementares === null || ctxConsultasComplementares === void 0 ? void 0 : ctxConsultasComplementares.consultasComplementares) === null || _d === void 0 ? void 0 : _d.refinBoaVista) === null || _e === void 0 ? void 0 : _e.data;
99
99
  var _o = useState({}), loadingButtons = _o[0], setLoadingButtons = _o[1];
100
100
  var productsPrices = getProductsPrices(isCpf(documento));
101
- var handleOnClick = function (key) {
101
+ var handleOnClick = useCallback(function (key) {
102
102
  return function () { return __awaiter(void 0, void 0, void 0, function () {
103
103
  var callback;
104
104
  return __generator(this, function (_a) {
@@ -139,14 +139,25 @@ var ChartSystem = function (_a) {
139
139
  }
140
140
  });
141
141
  }); };
142
- };
142
+ }, [loadingButtons, hasCredits, productsPrices, setConsultasComplementares]);
143
143
  var _p = useChartData(consultaSerasa, consultaBoaVista), chartData = _p.data, isLoadingChart = _p.isLoading, errorChart = _p.error, refetchChart = _p.refetch, chartDataProgress = _p.loadingProgress;
144
144
  var _q = useDividasPublicas(), quantidadeDividas = _q.quantidade, valorTotalDividas = _q.valorTotal, ultimaOcorrenciaDividas = _q.ultimaOcorrencia, dividasProgress = _q.loadingProgress;
145
+ var lastComplementary = useRef({
146
+ serasa: null,
147
+ boaVista: null
148
+ });
145
149
  useEffect(function () {
146
- if (consultaSerasa || consultaBoaVista) {
150
+ var serasaChanged = consultaSerasa !== lastComplementary.current.serasa;
151
+ var boaVistaChanged = consultaBoaVista !== lastComplementary.current.boaVista;
152
+ if (serasaChanged || boaVistaChanged) {
153
+ lastComplementary.current = {
154
+ serasa: consultaSerasa,
155
+ boaVista: consultaBoaVista
156
+ };
147
157
  refetchChart();
148
158
  }
149
- }, [consultaSerasa, consultaBoaVista, refetchChart]);
159
+ // eslint-disable-next-line react-hooks/exhaustive-deps
160
+ }, [consultaSerasa, consultaBoaVista]);
150
161
  var errorMessage = typeof errorChart === 'string' ? new Error(errorChart) : errorChart;
151
162
  var isOpen = useToggle(true)[0];
152
163
  var quantidadeProtestos = ((_g = (_f = chartData === null || chartData === void 0 ? void 0 : chartData.protestos) === null || _f === void 0 ? void 0 : _f[(chartData === null || chartData === void 0 ? void 0 : chartData.protestos.length) - 1]) === null || _g === void 0 ? void 0 : _g.quantidade) || 0;
@@ -3,5 +3,5 @@ import { DataInput } from '../types/iChart';
3
3
  interface MixedChartProps {
4
4
  dataInput: DataInput;
5
5
  }
6
- declare const MixedChart: React.FC<MixedChartProps>;
7
- export default MixedChart;
6
+ declare const _default: React.NamedExoticComponent<MixedChartProps>;
7
+ export default _default;
@@ -48,5 +48,5 @@ var MixedChart = function (_a) {
48
48
  : '1 Mês')); })),
49
49
  React.createElement(Chart, { className: "mixed-chart", type: chartType, data: data, options: options })));
50
50
  };
51
- export default MixedChart;
51
+ export default React.memo(MixedChart);
52
52
  var templateObject_1, templateObject_2, templateObject_3;
@@ -3,5 +3,5 @@ import { DataInput } from '../types/iChart';
3
3
  interface PieChartProps {
4
4
  dataInput: DataInput;
5
5
  }
6
- declare const PieChart: React.FC<PieChartProps>;
7
- export default PieChart;
6
+ declare const _default: React.NamedExoticComponent<PieChartProps>;
7
+ export default _default;
@@ -6,4 +6,4 @@ var PieChart = function (_a) {
6
6
  var _b = usePieChartData(dataInput), data = _b.data, options = _b.options;
7
7
  return React.createElement(Pie, { className: "pie-chart", data: data, options: options });
8
8
  };
9
- export default PieChart;
9
+ export default React.memo(PieChart);
@@ -3,5 +3,5 @@ import { DataInput } from '../types/iChart';
3
3
  interface ProtestoCategory {
4
4
  dataInput: DataInput['protestosCategory'];
5
5
  }
6
- declare const CategoriaProtesto: React.FC<ProtestoCategory>;
7
- export default CategoriaProtesto;
6
+ declare const _default: React.NamedExoticComponent<ProtestoCategory>;
7
+ export default _default;
@@ -13,5 +13,5 @@ var CategoriaProtesto = function (_a) {
13
13
  return (React.createElement(ChartContainer, null,
14
14
  React.createElement(Bar, { className: "categoria-protesto", data: data, options: options })));
15
15
  };
16
- export default CategoriaProtesto;
16
+ export default React.memo(CategoriaProtesto);
17
17
  var templateObject_1;
@@ -1,12 +1,13 @@
1
1
  import { Queries, RequestStatus } from '../../../components/webservice';
2
2
  import { useGlobalData } from '../../../contexts/globalDataContext';
3
- import { useContext, useEffect, useMemo, useState } from 'react';
3
+ import { useContext, useEffect, useMemo, useRef, useState } from 'react';
4
4
  import { processData, processProtestData } from '../utils/dataProcessing';
5
5
  var useChartData = function (consultaSerasa, consultaBoaVista) {
6
6
  var _a;
7
7
  var _b = useState(null), data = _b[0], setData = _b[1];
8
8
  var _c = useState(null), errorState = _c[0], setErrorState = _c[1];
9
- var _d = useState(0), loadingProgress = _d[0], setLoadingProgress = _d[1];
9
+ var _d = useState(0), loadingProgress = _d[0], _setLoadingProgress = _d[1];
10
+ var lastProgress = useRef(0);
10
11
  var ctxHistory = useContext(Queries.GraficosAnaliticos);
11
12
  var ctxProtestos = useContext(Queries.Protestos);
12
13
  var ctxCCF = useContext(Queries.CCF);
@@ -26,7 +27,6 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
26
27
  }
27
28
  return [];
28
29
  }, [ctxProtestos.type, ctxProtestos.document, iaOverrides]);
29
- // aggregate progress from all contexts
30
30
  useEffect(function () {
31
31
  var _a, _b, _c, _d;
32
32
  var parts = [
@@ -36,20 +36,32 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
36
36
  (_d = ctxProcessos.progress) !== null && _d !== void 0 ? _d : 0
37
37
  ];
38
38
  var avg = parts.reduce(function (sum, p) { return sum + p; }, 0) / parts.length;
39
- setLoadingProgress(avg);
39
+ if (avg === 100 || Math.abs(avg - lastProgress.current) >= 10) {
40
+ lastProgress.current = avg;
41
+ _setLoadingProgress(avg);
42
+ }
40
43
  }, [
41
44
  ctxHistory.progress,
42
45
  ctxProtestos.progress,
43
46
  ctxCCF.progress,
44
47
  ctxProcessos.progress
45
48
  ]);
46
- // trigger refetch when complementary queries change
49
+ var lastComplementary = useRef({
50
+ serasa: null,
51
+ boaVista: null
52
+ });
47
53
  useEffect(function () {
48
- if (consultaSerasa || consultaBoaVista) {
54
+ var serasaChanged = consultaSerasa !== lastComplementary.current.serasa;
55
+ var boaVistaChanged = consultaBoaVista !== lastComplementary.current.boaVista;
56
+ if (serasaChanged || boaVistaChanged) {
57
+ lastComplementary.current = {
58
+ serasa: consultaSerasa,
59
+ boaVista: consultaBoaVista
60
+ };
49
61
  ctxHistory.refetch();
50
62
  }
51
- }, [consultaSerasa, consultaBoaVista, ctxHistory.refetch]);
52
- // handle history response
63
+ // eslint-disable-next-line react-hooks/exhaustive-deps
64
+ }, [consultaSerasa, consultaBoaVista]);
53
65
  useEffect(function () {
54
66
  var _a;
55
67
  if (ctxHistory.type === RequestStatus.Loading) {
@@ -63,7 +75,7 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
63
75
  try {
64
76
  var parsed = JSON.parse(ctxHistory.document);
65
77
  parsed.protestosCategory = dadosProtestos;
66
- var processed = processData(parsed, quantidadeProcessos);
78
+ var processed = processData(structuredClone(parsed), quantidadeProcessos);
67
79
  setData(processed);
68
80
  }
69
81
  catch (_b) {
@@ -1,6 +1,6 @@
1
1
  import { ChartData, ChartOptions } from 'chart.js';
2
- import { DataInput, TimeFilter } from '../types/iChart';
3
2
  import 'chartjs-adapter-date-fns';
3
+ import { DataInput, TimeFilter } from '../types/iChart';
4
4
  export declare const useMixedChartData: (dataInput: DataInput, timeFilter?: TimeFilter) => {
5
5
  data: ChartData<"line" | "bar", (number | {
6
6
  x: string;
@@ -1,7 +1,7 @@
1
- import { useMemo } from 'react';
2
1
  import 'chartjs-adapter-date-fns';
3
- import { getEndDate, getUniqueDates, addMissingDateEntries, getFilteredStartDate, getEarliestDate } from '../utils/dataManipulation';
2
+ import { useMemo } from 'react';
4
3
  import { createDatasets, getChartOptions } from '../utils/chartCustomization';
4
+ import { addMissingDateEntries, getEarliestDate, getEndDate, getFilteredStartDate, getUniqueDates } from '../utils/dataManipulation';
5
5
  export var useMixedChartData = function (dataInput, timeFilter) {
6
6
  if (timeFilter === void 0) { timeFilter = '1m'; }
7
7
  return useMemo(function () {
@@ -1,3 +1,6 @@
1
1
  import { DataInput } from '../../../components/chart/types/iChart';
2
+ /**
3
+ * Normaliza todos os datasets do DataInput.
4
+ */
2
5
  export declare const processData: (data: DataInput, quantidadeProcessosJuridicos: number) => DataInput;
3
6
  export declare function processProtestData(document: Document, iaOverrides?: Record<string, string>): DataInput['protestosCategory'];
@@ -13,63 +13,91 @@ import { classifyProtestos } from '../../../hooks/useProtestosClassification';
13
13
  import { converterParaFormatoValido, formatDatePtBrToDate } from '../../../utils/date';
14
14
  import XPathUtils from '../../../utils/xpath';
15
15
  import { groupBy, sortBy, unique } from 'underscore';
16
+ /**
17
+ * Remove pontos internos com quantidade = 0
18
+ * (mantém o 1.º e o último sempre).
19
+ */
20
+ var removeZeros = function (current, index, arr) {
21
+ return index === 0 || index === arr.length - 1
22
+ ? true
23
+ : ((current === null || current === void 0 ? void 0 : current.quantidade) || 0) > 0;
24
+ };
25
+ /** Mantém apenas break-points: 1.º, último e trocas de quantidade. */
26
+ var removeSameAsNext = function (current, index, arr) {
27
+ if (index === 0 || index === arr.length - 1)
28
+ return true;
29
+ return current.quantidade !== arr[index - 1].quantidade;
30
+ };
31
+ /** Converte chave de agrupamento (string) em timestamp ordenável. */
32
+ var keyToTime = function (key) {
33
+ return new Date(formatDatePtBrToDate(key)).getTime();
34
+ };
35
+ /**
36
+ * Normaliza todos os datasets do DataInput.
37
+ */
16
38
  export var processData = function (data, quantidadeProcessosJuridicos) {
17
- var removeZeros = function (current, index, arr) {
18
- return index === 0 || index === arr.length - 1
19
- ? true
20
- : ((current === null || current === void 0 ? void 0 : current.quantidade) || 0) > 0;
21
- };
22
- var removeSameAsNext = function (current, index, arr) {
23
- if (index === 0 || index === arr.length - 1)
24
- return true;
25
- return current.quantidade !== arr[index + 1].quantidade;
26
- };
27
- data.pieChartTotalConfig = {
28
- processosJuridicos: quantidadeProcessosJuridicos
29
- };
39
+ // ------------------------------------------------------------------
40
+ // PROTESTOS
41
+ // ------------------------------------------------------------------
30
42
  var grouped = groupBy(data.protestos, function (e) { return e.data; });
31
- data.protestos = Object.values(grouped)
32
- .map(function (e) {
33
- if (e.length === 1)
34
- return e;
35
- return e.filter(function (el) { return Number(el.quantidade) > 0; });
43
+ // transforma em array ordenado por data asc
44
+ var groupedOrdered = Object.entries(grouped).sort(function (_a, _b) {
45
+ var kA = _a[0];
46
+ var kB = _b[0];
47
+ return keyToTime(kA) - keyToTime(kB);
48
+ });
49
+ data.protestos = groupedOrdered
50
+ .map(function (_a) {
51
+ var registros = _a[1];
52
+ return registros.length === 1
53
+ ? registros
54
+ : registros.filter(function (el) { return Number(el.quantidade) > 0; });
36
55
  })
37
56
  .flat();
38
57
  data.protestos = sortBy(unique(data.protestos, function (x) { return x.data; })
39
58
  .filter(removeZeros)
40
59
  .filter(removeSameAsNext)
41
- .map(function (info) { return (__assign(__assign({}, info), { data: formatDatePtBrToDate(info.data) })); }), function (info) { return info.data; });
60
+ .map(function (info) { return (__assign(__assign({}, info), { data: formatDatePtBrToDate(info.data) // normaliza p/ ISO local
61
+ })); }), function (info) { return info.data; });
62
+ // ------------------------------------------------------------------
63
+ // CCFs
64
+ // ------------------------------------------------------------------
42
65
  data.ccfs = sortBy(unique(data.ccfs, function (x) { return x.data; })
43
66
  .filter(removeZeros)
44
67
  .filter(removeSameAsNext)
45
68
  .map(function (info) { return (__assign(__assign({}, info), { data: formatDatePtBrToDate(info.data) })); }), function (info) { return info.data; });
69
+ // ------------------------------------------------------------------
70
+ // BOA VISTA - não tem quantidade → só formata e filtra vazios
71
+ // ------------------------------------------------------------------
46
72
  data.boaVista = data.boaVista
47
73
  .map(function (entry) {
48
74
  var formattedDate = formatDatePtBrToDate(entry.creation);
49
75
  return __assign(__assign({}, entry), { data: formattedDate, creation: undefined });
50
76
  })
51
77
  .filter(function (entry) { return entry.data; });
78
+ // ------------------------------------------------------------------
79
+ // SERASA
80
+ // ------------------------------------------------------------------
52
81
  data.serasa = data.serasa
53
82
  .map(function (entry) {
54
83
  var formattedDate = formatDatePtBrToDate(entry.creation);
55
84
  return __assign(__assign({}, entry), { data: formattedDate, creation: undefined });
56
85
  })
57
86
  .filter(function (entry) { return entry.data; });
87
+ // ------------------------------------------------------------------
88
+ // DÍVIDAS PÚBLICAS
89
+ // ------------------------------------------------------------------
58
90
  data.dividasPublicasGrafico = data.dividasPublicasGrafico
59
91
  .map(function (info) { return (__assign(__assign({}, info), { data: formatDatePtBrToDate(info.data), valorTotal: info.total, total: undefined })); })
60
92
  .filter(function (info) { return info.data; });
93
+ // ------------------------------------------------------------------
94
+ // PIE-CHART EXTRA
95
+ // ------------------------------------------------------------------
96
+ data.pieChartTotalConfig = {
97
+ processosJuridicos: quantidadeProcessosJuridicos
98
+ };
61
99
  return __assign(__assign({}, data), { protestos: data.protestos, ccfs: data.ccfs, boaVista: data.boaVista, serasa: data.serasa, dividasPublicasGrafico: data.dividasPublicasGrafico, pieChartTotalConfig: __assign(__assign({}, data.pieChartTotalConfig), { processosJuridicos: quantidadeProcessosJuridicos }) });
62
100
  };
63
- var obterUltimaData = function (protestos) {
64
- if (!protestos.length)
65
- return null;
66
- var datas = protestos
67
- .map(function (p) { return new Date(converterParaFormatoValido(p.dataProtesto)).getTime(); })
68
- .filter(function (d) { return !isNaN(d); });
69
- return datas.length
70
- ? new Date(Math.max.apply(Math, datas)).toLocaleDateString('pt-BR')
71
- : null;
72
- };
73
101
  export function processProtestData(document, iaOverrides) {
74
102
  var _a = classifyProtestos(document, iaOverrides), protestosDeCredito = _a.protestosDeCredito, protestosDeImposto = _a.protestosDeImposto, protestosGerais = _a.protestosGerais;
75
103
  var obterUltimaData = function (protestos) {
@@ -190,9 +190,9 @@ var Liminar = function (_a) {
190
190
  return;
191
191
  var fetch = function () { return __awaiter(void 0, void 0, void 0, function () {
192
192
  var dossie, processosJuridicos, depsLoaded, newIds, hash, indiciosApi, indiciosDeLiminarProtestosDoPassado, protestosDoPassadoIds, _a, possuiIndiciosDeLiminarProtestosDoPassado, protestosIds, finalStatus, descricaoLiminar;
193
- var _b, _c, _d;
194
- return __generator(this, function (_e) {
195
- switch (_e.label) {
193
+ var _b, _c;
194
+ return __generator(this, function (_d) {
195
+ switch (_d.label) {
196
196
  case 0:
197
197
  dossie = globalData === null || globalData === void 0 ? void 0 : globalData.dossie;
198
198
  processosJuridicos = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData;
@@ -214,11 +214,10 @@ var Liminar = function (_a) {
214
214
  indiciosApi = ((_c = ctx.document) === null || _c === void 0 ? void 0 : _c.indiciosDeLiminar) === true;
215
215
  indiciosDeLiminarProtestosDoPassado = false;
216
216
  protestosDoPassadoIds = '';
217
- if (!((_d = globalData === null || globalData === void 0 ? void 0 : globalData.documentHistory) === null || _d === void 0 ? void 0 : _d.protestoLiminar)) return [3 /*break*/, 2];
218
217
  setIsLoadingLiminarProtestosDoPassado(true);
219
218
  return [4 /*yield*/, fetchLiminarProtestosDoPassado()];
220
219
  case 1:
221
- _a = _e.sent(), possuiIndiciosDeLiminarProtestosDoPassado = _a.possuiIndiciosDeLiminarProtestosDoPassado, protestosIds = _a.protestosDoPassadoIds;
220
+ _a = _d.sent(), possuiIndiciosDeLiminarProtestosDoPassado = _a.possuiIndiciosDeLiminarProtestosDoPassado, protestosIds = _a.protestosDoPassadoIds;
222
221
  if (possuiIndiciosDeLiminarProtestosDoPassado) {
223
222
  origensDetectadas.push('Liminar no Cenprot');
224
223
  indiciosDeLiminarProtestosDoPassado =
@@ -226,8 +225,6 @@ var Liminar = function (_a) {
226
225
  protestosDoPassadoIds = protestosIds.join(',');
227
226
  }
228
227
  setIsLoadingLiminarProtestosDoPassado(false);
229
- _e.label = 2;
230
- case 2:
231
228
  finalStatus = indiciosApi ||
232
229
  processosComAssuntoValido.length ||
233
230
  indiciosDeLiminarProtestosDoPassado
@@ -7,7 +7,7 @@ interface LiminarProtestosDoPassadoProps {
7
7
  *
8
8
  * Regras (2025‑07‑01)
9
9
  * • Um instrumento é **oculto** se a consulta a `PDFPROTESTO.PDF` **não** retornar PDF.
10
- * • Se todos ainda possuem PDF, não há indício de liminar.
10
+ * • Se todos ainda possuem PDF, não há indício de liminar. (!?)
11
11
  *
12
12
  * Esta versão limita a concorrência (10 chamadas em paralelo) e aplica
13
13
  * timeout defensivo para cada requisição.
@@ -44,7 +44,7 @@ import { useGlobalData } from '../../contexts/globalDataContext';
44
44
  *
45
45
  * Regras (2025‑07‑01)
46
46
  * • Um instrumento é **oculto** se a consulta a `PDFPROTESTO.PDF` **não** retornar PDF.
47
- * • Se todos ainda possuem PDF, não há indício de liminar.
47
+ * • Se todos ainda possuem PDF, não há indício de liminar. (!?)
48
48
  *
49
49
  * Esta versão limita a concorrência (10 chamadas em paralelo) e aplica
50
50
  * timeout defensivo para cada requisição.
@@ -56,7 +56,7 @@ var useLiminarProtestosDoPassado = function (_a) {
56
56
  /** Máximo de requisições simultâneas ao endpoint de PDF. */
57
57
  var MAX_CONCURRENT = 10;
58
58
  /** Timeout (ms) por requisição individual ao PDF. */
59
- var PDF_TIMEOUT = 8000;
59
+ var PDF_TIMEOUT = 80000;
60
60
  /**
61
61
  * Checa se um `nm_chave` ainda possui PDF no CENPROT.
62
62
  * Retorna `true` quando há PDF, `false` caso contrário ou erro.