@credithub/harlan-components 1.127.0 → 1.128.0

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.
@@ -37,7 +37,8 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
37
37
  var _g = useState(false), isProcessing = _g[0], setIsProcessing = _g[1];
38
38
  var _h = useState(false), dataReady = _h[0], setDataReady = _h[1];
39
39
  var lastProgress = useRef(0);
40
- var lastProcessedDocument = useRef(null);
40
+ /** Evita reprocessar o mesmo JSON + mesmos totais ao vivo; totais/PJ mudam → nova chave. */
41
+ var lastProcessSnapshotKey = useRef(null);
41
42
  var processingTimeout = useRef(null);
42
43
  var ctxHistory = useContext(Queries.GraficosAnaliticos);
43
44
  var ctxProtestos = useContext(Queries.Protestos);
@@ -182,6 +183,7 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
182
183
  if (ctxHistory.type === RequestStatus.Loading ||
183
184
  ctxProtestos.type === RequestStatus.Loading ||
184
185
  ctxCCF.type === RequestStatus.Loading) {
186
+ lastProcessSnapshotKey.current = null;
185
187
  setDataReady(false);
186
188
  setErrorState(null);
187
189
  setIsProcessing(false);
@@ -191,20 +193,25 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
191
193
  setErrorState(((_a = ctxHistory.error) === null || _a === void 0 ? void 0 : _a.message) || 'Erro ao consultar histórico');
192
194
  setIsProcessing(false);
193
195
  setDataReady(false);
194
- lastProcessedDocument.current = null;
196
+ lastProcessSnapshotKey.current = null;
195
197
  return;
196
198
  }
197
199
  // Só processa quando TODOS os contextos estiverem prontos
198
200
  if (allContextsReady && ctxHistory.document) {
199
201
  var documentSnapshot_1 = ctxHistory.document;
200
- // Evita processar o mesmo documento múltiplas vezes
201
- if (lastProcessedDocument.current === documentSnapshot_1) {
202
+ var processSnapshotKey_1 = JSON.stringify({
203
+ doc: documentSnapshot_1,
204
+ totalProtestos: totalProtestos !== null && totalProtestos !== void 0 ? totalProtestos : null,
205
+ valorTotalProtestos: valorTotalProtestos !== null && valorTotalProtestos !== void 0 ? valorTotalProtestos : null,
206
+ ultimaOcorrenciaProtestos: ultimaOcorrenciaProtestos !== null && ultimaOcorrenciaProtestos !== void 0 ? ultimaOcorrenciaProtestos : null,
207
+ quantidadeProcessosFromPJ: quantidadeProcessosFromPJ !== null && quantidadeProcessosFromPJ !== void 0 ? quantidadeProcessosFromPJ : null
208
+ });
209
+ if (lastProcessSnapshotKey.current === processSnapshotKey_1) {
202
210
  return;
203
211
  }
204
212
  // Marca como processando
205
213
  setIsProcessing(true);
206
214
  setDataReady(false);
207
- lastProcessedDocument.current = documentSnapshot_1;
208
215
  // Usa setTimeout para permitir que a UI atualize o estado de loading
209
216
  processingTimeout.current = setTimeout(function () {
210
217
  try {
@@ -217,6 +224,7 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
217
224
  var quantidadeProcessos = quantidadeProcessosFromPJ !== null && quantidadeProcessosFromPJ !== void 0 ? quantidadeProcessosFromPJ : getLastQuantidadeProcessosFromHistory(parsed);
218
225
  var processed = processData(structuredClone(parsed), quantidadeProcessos, totalProtestos, valorTotalProtestos, ultimaOcorrenciaProtestos);
219
226
  setData(processed);
227
+ lastProcessSnapshotKey.current = processSnapshotKey_1;
220
228
  setIsProcessing(false);
221
229
  setDataReady(true);
222
230
  // Garante que o progresso chegue a 100% quando dados estão prontos
@@ -227,6 +235,7 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
227
235
  setErrorState('Erro ao processar os dados');
228
236
  setIsProcessing(false);
229
237
  setDataReady(false);
238
+ lastProcessSnapshotKey.current = null;
230
239
  }
231
240
  processingTimeout.current = null;
232
241
  }, 0);
@@ -75,6 +75,13 @@ export var processData = function (data, quantidadeProcessosJuridicos, totalProt
75
75
  .filter(removeSameAsNext)
76
76
  .map(function (info) { return (__assign(__assign({}, info), { data: parseProtestStringToDate(info.data) })); })
77
77
  .filter(function (info) { return !Number.isNaN(info.data.getTime()); }), function (info) { return info.data; });
78
+ /** Alinha o último ponto (data da consulta mais recente no histórico) com os totais ao vivo (mesma fonte que o pie). */
79
+ if (totalProtestos !== undefined && data.protestos.length > 0) {
80
+ var i = data.protestos.length - 1;
81
+ data.protestos[i] = __assign(__assign(__assign({}, data.protestos[i]), { quantidade: totalProtestos }), (valorTotalProtestos !== undefined
82
+ ? { valorTotal: valorTotalProtestos }
83
+ : {}));
84
+ }
78
85
  // ------------------------------------------------------------------
79
86
  // CCFs
80
87
  // ------------------------------------------------------------------
@@ -20,7 +20,7 @@ var useLiminarProtestosDoPassado = function (_a) {
20
20
  var posthog = useContext(PostHogContext).posthog;
21
21
  var _c = useGlobalData(), globalData = _c.data, setData = _c.setData;
22
22
  var fetch = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
23
- var data, parsedData, _a, _b, normalizedData, numerosChave, protestosDoPassado, ocultos;
23
+ var data, parsedData, _a, _b, normalizedData, protestosDoPassado, instrumentosParaEvento, idsSomenteComChave;
24
24
  return __generator(this, function (_c) {
25
25
  switch (_c.label) {
26
26
  case 0: return [4 /*yield*/, client.request("SELECT FROM 'Protestos'.'History'", {
@@ -36,25 +36,27 @@ var useLiminarProtestosDoPassado = function (_a) {
36
36
  var _a;
37
37
  return (__assign(__assign({}, item), { cpfCnpj: (_a = item.cpfCnpj) !== null && _a !== void 0 ? _a : documento }));
38
38
  });
39
- numerosChave = normalizedData
40
- .filter(function (item) { return item.missingAt; })
41
- .map(function (item) { return item.chave; });
42
39
  protestosDoPassado = normalizedData.filter(function (item) { return item.missingAt; });
43
- ocultos = protestosDoPassado.map(function (item) { return item.chave; });
40
+ instrumentosParaEvento = protestosDoPassado.map(function (item) {
41
+ return item.chave != null && String(item.chave).trim() !== ''
42
+ ? String(item.chave)
43
+ : '(sem chave)';
44
+ });
45
+ idsSomenteComChave = instrumentosParaEvento.filter(function (c) { return c !== '(sem chave)'; });
44
46
  setData(function (prev) { return (__assign(__assign({}, prev), { protestosPagosBaixados: {
45
47
  isLoaded: true,
46
48
  protestos: protestosDoPassado
47
49
  } })); });
48
- if (ocultos.length > 0 && posthog) {
50
+ if (protestosDoPassado.length > 0 && posthog) {
49
51
  posthog.capture('liminar_protestos_ocultos', {
50
52
  documento: documento,
51
- quantidade: ocultos.length,
52
- instrumentos: ocultos
53
+ quantidade: protestosDoPassado.length,
54
+ instrumentos: instrumentosParaEvento
53
55
  });
54
56
  }
55
57
  return [2 /*return*/, {
56
- possuiIndiciosDeLiminarProtestosDoPassado: ocultos.length > 0,
57
- protestosDoPassadoIds: ocultos
58
+ possuiIndiciosDeLiminarProtestosDoPassado: protestosDoPassado.length > 0,
59
+ protestosDoPassadoIds: idsSomenteComChave
58
60
  }];
59
61
  }
60
62
  });
@@ -1,4 +1,8 @@
1
1
  import type { ProtestoHistoricoItem } from '@/@types/domain/protestosPagosBaixadosTypes';
2
2
  import type { Consulta } from '../../components/chart/types/iChart';
3
- export declare function adaptToUI(items: ProtestoHistoricoItem[]): ProtestoHistoricoItem[];
3
+ /** Linha normalizada para UI, com `rowId` único para listas React. */
4
+ export type ProtestoHistoricoUiRow = ProtestoHistoricoItem & {
5
+ rowId: string;
6
+ };
7
+ export declare function adaptToUI(items: ProtestoHistoricoItem[]): ProtestoHistoricoUiRow[];
4
8
  export declare function buildChartSeries(items: ProtestoHistoricoItem[]): Consulta[];
@@ -2,16 +2,31 @@ import { __assign } from "tslib";
2
2
  // Pré-compila regexes fora do hot path
3
3
  var ISO_RE = /^\d{4}-\d{2}-\d{2}/;
4
4
  var BR_RE = /^(\d{2})\/(\d{2})\/(\d{4})/;
5
+ function assignStableRowIds(items) {
6
+ var baseKeys = items.map(function (i, idx) {
7
+ var c = i.chave;
8
+ if (c != null && String(c).trim() !== '')
9
+ return String(c);
10
+ return "protesto-historico-".concat(idx);
11
+ });
12
+ var counts = new Map();
13
+ var rowIds = baseKeys.map(function (base) {
14
+ var _a;
15
+ var n = ((_a = counts.get(base)) !== null && _a !== void 0 ? _a : 0) + 1;
16
+ counts.set(base, n);
17
+ return n === 1 ? base : "".concat(base, "__").concat(n);
18
+ });
19
+ return { rowIds: rowIds };
20
+ }
5
21
  export function adaptToUI(items) {
6
- // Se realmente não quiser adaptar nada, pode remover esta função e usar items direto.
7
- // Aqui normalizo datas vazias para string vazia e default para campos opcionais.
8
- return items.map(function (i) {
22
+ var rowIds = assignStableRowIds(items).rowIds;
23
+ return items.map(function (i, idx) {
9
24
  var _a, _b, _c, _d, _e;
10
25
  return (__assign(__assign({}, i), { dataProtesto: (_b = (_a = i.dataProtesto) !== null && _a !== void 0 ? _a : i.data) !== null && _b !== void 0 ? _b : '', nomeCedente: (_c = i.nomeCedente) !== null && _c !== void 0 ? _c : '', nomeApresentante: (_d = i.nomeApresentante) !== null && _d !== void 0 ? _d : '', valor: Number.isFinite(i.valor)
11
26
  ? i.valor
12
27
  : safeNumber((_e = i.valor) !== null && _e !== void 0 ? _e : i.valorProtestado), custas: Number.isFinite(i.custas)
13
28
  ? i.custas
14
- : safeNumber(i.custas) }));
29
+ : safeNumber(i.custas), rowId: rowIds[idx] }));
15
30
  });
16
31
  }
17
32
  export function buildChartSeries(items) {
@@ -77,7 +77,7 @@ var ProtestosPagosBaixados = function (_a) {
77
77
  : "Foram encontrados ".concat((_l = (_k = data === null || data === void 0 ? void 0 : data.protestosPagosBaixados) === null || _k === void 0 ? void 0 : _k.protestos) === null || _l === void 0 ? void 0 : _l.length, " protestos")), variant: ((_o = (_m = data === null || data === void 0 ? void 0 : data.protestosPagosBaixados) === null || _m === void 0 ? void 0 : _m.protestos) === null || _o === void 0 ? void 0 : _o.length) ? 'error' : 'default', icon: ProtestosIcon, onSuccess: function () {
78
78
  var protestosAdaptados = adaptToUI(items);
79
79
  var totalProtestos = protestosAdaptados.length;
80
- var children = totalProtestos ? (React.createElement(Result, null, protestosAdaptados.map(function (protesto) { return (React.createElement(ProtestoHistoricoItemComponent, { key: protesto.chave, protesto: protesto })); }))) : null;
80
+ var children = totalProtestos ? (React.createElement(Result, null, protestosAdaptados.map(function (protesto) { return (React.createElement(ProtestoHistoricoItemComponent, { key: protesto.rowId, protesto: protesto })); }))) : null;
81
81
  return {
82
82
  children: children
83
83
  };