@credithub/harlan-components 1.129.0 → 1.130.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.
- package/dist/components/chart/chartSystem.js +28 -12
- package/dist/components/chart/hooks/useChartData.d.ts +3 -1
- package/dist/components/chart/hooks/useChartData.js +25 -6
- package/dist/components/dossie/generativeAi/generativeAi.js +10 -4
- package/dist/components/liminar/liminar.js +27 -5
- package/dist/components/requestContextTypes.d.ts +7 -0
- package/dist/components/section.d.ts +2 -0
- package/dist/components/section.js +42 -14
- package/dist/components/streamQuery.js +16 -6
- package/dist/components/webservice.d.ts +2 -1
- package/dist/components/webservice.js +55 -31
- package/dist/dev/manualPushSectionPreview.d.ts +2 -0
- package/dist/dev/manualPushSectionPreview.js +42 -0
- package/dist/hooks/useSafeQuery.d.ts +1 -0
- package/dist/utils/classifyRequestError.d.ts +9 -0
- package/dist/utils/classifyRequestError.js +26 -0
- package/lib/cjs/index.js +223 -78
- package/lib/esm/index.js +223 -78
- package/package.json +1 -1
|
@@ -14,7 +14,8 @@ import { ConsultasComplementaresContext } from '../consultasComplementares';
|
|
|
14
14
|
import { ButtonsSummary, SummaryButton } from '../dossie/summary/styles';
|
|
15
15
|
import { getProductsPrices } from '../dossie/summary/utils';
|
|
16
16
|
import StatusMessage from '../interface/statusMessage';
|
|
17
|
-
import Section from '../section';
|
|
17
|
+
import Section, { pushExceptionDescription } from '../section';
|
|
18
|
+
import { isErrorWithPushFlag } from '../../utils/classifyRequestError';
|
|
18
19
|
import { RequestStatus } from '../webservice';
|
|
19
20
|
import ChartContent from './chartContent';
|
|
20
21
|
import useChartData from './hooks/useChartData';
|
|
@@ -90,7 +91,7 @@ var ChartSystem = function (_a) {
|
|
|
90
91
|
});
|
|
91
92
|
}); };
|
|
92
93
|
}, [loadingButtons, hasCredits, productsPrices, setConsultasComplementares]);
|
|
93
|
-
var _p = useChartData(consultaSerasa, consultaBoaVista), chartData = _p.data, isLoadingChart = _p.isLoading, errorChart = _p.error, refetchChart = _p.refetch, chartDataProgress = _p.loadingProgress;
|
|
94
|
+
var _p = useChartData(consultaSerasa, consultaBoaVista), chartData = _p.data, isLoadingChart = _p.isLoading, errorChart = _p.error, chartUpstreamFailed = _p.upstreamRequestFailed, refetchChart = _p.refetch, chartDataProgress = _p.loadingProgress;
|
|
94
95
|
var _q = useDividasPublicas(), quantidadeDividas = _q.quantidade, valorTotalDividas = _q.valorTotal, ultimaOcorrenciaDividas = _q.ultimaOcorrencia, dividasProgress = _q.loadingProgress;
|
|
95
96
|
var lastComplementary = useRef({
|
|
96
97
|
serasa: null,
|
|
@@ -99,7 +100,14 @@ var ChartSystem = function (_a) {
|
|
|
99
100
|
// Evita escrever documentHistory repetidamente com o mesmo conteúdo
|
|
100
101
|
var lastDocHistorySigRef = useRef('');
|
|
101
102
|
// (refetch de histórico por mudança complementar centralizado no hook useChartData)
|
|
102
|
-
var
|
|
103
|
+
var chartHasError = chartUpstreamFailed || errorChart != null;
|
|
104
|
+
var errorMessage = errorChart instanceof Error
|
|
105
|
+
? errorChart
|
|
106
|
+
: typeof errorChart === 'string'
|
|
107
|
+
? new Error(errorChart)
|
|
108
|
+
: chartUpstreamFailed
|
|
109
|
+
? new Error()
|
|
110
|
+
: null;
|
|
103
111
|
var isOpen = useToggle(true)[0];
|
|
104
112
|
// Usa valores já calculados de globalData.protestosData (calculados uma única vez em protestos.tsx)
|
|
105
113
|
var quantidadeProtestos = (_g = (_f = globalData === null || globalData === void 0 ? void 0 : globalData.protestosData) === null || _f === void 0 ? void 0 : _f.totalProtestos) !== null && _g !== void 0 ? _g : 0;
|
|
@@ -231,10 +239,10 @@ var ChartSystem = function (_a) {
|
|
|
231
239
|
response: undefined,
|
|
232
240
|
type: isLoadingChart
|
|
233
241
|
? RequestStatus.Loading
|
|
234
|
-
:
|
|
242
|
+
: chartHasError
|
|
235
243
|
? RequestStatus.Error
|
|
236
244
|
: RequestStatus.Success,
|
|
237
|
-
error: errorMessage
|
|
245
|
+
error: errorMessage,
|
|
238
246
|
refetch: refetchChart,
|
|
239
247
|
document: chartData,
|
|
240
248
|
progress: loadingProgress,
|
|
@@ -267,13 +275,21 @@ var ChartSystem = function (_a) {
|
|
|
267
275
|
: undefined, ultimaOcorrenciaPefinSerasa: Array.isArray(chartData === null || chartData === void 0 ? void 0 : chartData.serasa) && chartData.serasa.length > 0
|
|
268
276
|
? (ultimaOcorrenciaSerasa !== null && ultimaOcorrenciaSerasa !== void 0 ? ultimaOcorrenciaSerasa : undefined)
|
|
269
277
|
: undefined })));
|
|
270
|
-
}, isError: function (err) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
278
|
+
}, isError: function (err) {
|
|
279
|
+
return isErrorWithPushFlag(err)
|
|
280
|
+
? {
|
|
281
|
+
children: React.createElement(React.Fragment, null),
|
|
282
|
+
description: pushExceptionDescription(err),
|
|
283
|
+
variant: 'default'
|
|
284
|
+
}
|
|
285
|
+
: {
|
|
286
|
+
children: React.createElement(React.Fragment, null),
|
|
287
|
+
description: (React.createElement(StatusMessage, { type: "error" },
|
|
288
|
+
"Erro ao realizar a an\u00E1lise: ",
|
|
289
|
+
err.message)),
|
|
290
|
+
variant: 'error'
|
|
291
|
+
};
|
|
292
|
+
} }));
|
|
277
293
|
};
|
|
278
294
|
export default ChartSystem;
|
|
279
295
|
var templateObject_1;
|
|
@@ -2,7 +2,9 @@ import { DataInput } from '../../../components/chart/types/iChart';
|
|
|
2
2
|
declare const useChartData: (consultaSerasa: any, consultaBoaVista: any) => {
|
|
3
3
|
data: DataInput | null;
|
|
4
4
|
isLoading: boolean;
|
|
5
|
-
error:
|
|
5
|
+
error: Error | null;
|
|
6
|
+
/** True quando Histórico/Protestos/CCF estão em Error (mesmo sem mensagem no Error). */
|
|
7
|
+
upstreamRequestFailed: boolean;
|
|
6
8
|
refetch: () => void;
|
|
7
9
|
loadingProgress: number;
|
|
8
10
|
};
|
|
@@ -159,6 +159,7 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
|
|
|
159
159
|
boaVista: null
|
|
160
160
|
});
|
|
161
161
|
useEffect(function () {
|
|
162
|
+
var _a;
|
|
162
163
|
var serasaChanged = consultaSerasa !== lastComplementary.current.serasa;
|
|
163
164
|
var boaVistaChanged = consultaBoaVista !== lastComplementary.current.boaVista;
|
|
164
165
|
if (serasaChanged || boaVistaChanged) {
|
|
@@ -166,7 +167,12 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
|
|
|
166
167
|
serasa: consultaSerasa,
|
|
167
168
|
boaVista: consultaBoaVista
|
|
168
169
|
};
|
|
169
|
-
ctxHistory.
|
|
170
|
+
if (ctxHistory.type !== RequestStatus.Error) {
|
|
171
|
+
ctxHistory.refetch();
|
|
172
|
+
}
|
|
173
|
+
else if ((_a = import.meta.env) === null || _a === void 0 ? void 0 : _a.DEV) {
|
|
174
|
+
console.debug('[useChartData] refetch de histórico ignorado: consulta anterior em erro');
|
|
175
|
+
}
|
|
170
176
|
}
|
|
171
177
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
172
178
|
}, [consultaSerasa, consultaBoaVista]);
|
|
@@ -176,8 +182,12 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
|
|
|
176
182
|
ctxProtestos.type === RequestStatus.Success &&
|
|
177
183
|
ctxCCF.type === RequestStatus.Success;
|
|
178
184
|
}, [ctxHistory.type, ctxProtestos.type, ctxCCF.type]);
|
|
185
|
+
var upstreamRequestFailed = useMemo(function () {
|
|
186
|
+
return ctxHistory.type === RequestStatus.Error ||
|
|
187
|
+
ctxProtestos.type === RequestStatus.Error ||
|
|
188
|
+
ctxCCF.type === RequestStatus.Error;
|
|
189
|
+
}, [ctxHistory.type, ctxProtestos.type, ctxCCF.type]);
|
|
179
190
|
useEffect(function () {
|
|
180
|
-
var _a;
|
|
181
191
|
// Limpa timeout anterior se existir
|
|
182
192
|
if (processingTimeout.current) {
|
|
183
193
|
clearTimeout(processingTimeout.current);
|
|
@@ -193,8 +203,13 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
|
|
|
193
203
|
setIsProcessing(false);
|
|
194
204
|
return;
|
|
195
205
|
}
|
|
196
|
-
if (
|
|
197
|
-
|
|
206
|
+
if (upstreamRequestFailed) {
|
|
207
|
+
var err = ctxHistory.type === RequestStatus.Error
|
|
208
|
+
? ctxHistory.error
|
|
209
|
+
: ctxProtestos.type === RequestStatus.Error
|
|
210
|
+
? ctxProtestos.error
|
|
211
|
+
: ctxCCF.error;
|
|
212
|
+
setErrorState(err !== null && err !== void 0 ? err : null);
|
|
198
213
|
setIsProcessing(false);
|
|
199
214
|
setDataReady(false);
|
|
200
215
|
lastProcessSnapshotKey.current = null;
|
|
@@ -236,7 +251,7 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
|
|
|
236
251
|
}
|
|
237
252
|
catch (error) {
|
|
238
253
|
console.error('[useChartData] Erro ao processar dados:', error);
|
|
239
|
-
setErrorState(
|
|
254
|
+
setErrorState(error instanceof Error ? error : new Error(String(error)));
|
|
240
255
|
setIsProcessing(false);
|
|
241
256
|
setDataReady(false);
|
|
242
257
|
lastProcessSnapshotKey.current = null;
|
|
@@ -268,11 +283,15 @@ var useChartData = function (consultaSerasa, consultaBoaVista) {
|
|
|
268
283
|
// Verifica se está carregando - aguarda TODOS os contextos necessários terminarem
|
|
269
284
|
// E aguarda o processamento E renderização dos dados estar completo
|
|
270
285
|
// Só sai de loading quando dataReady === true (todos os contextos prontos + dados processados)
|
|
271
|
-
var isLoading = !
|
|
286
|
+
var isLoading = !upstreamRequestFailed &&
|
|
287
|
+
errorState == null &&
|
|
288
|
+
(!dataReady || isProcessing || !allContextsReady);
|
|
272
289
|
return {
|
|
273
290
|
data: data,
|
|
274
291
|
isLoading: isLoading,
|
|
275
292
|
error: errorState,
|
|
293
|
+
/** True quando Histórico/Protestos/CCF estão em Error (mesmo sem mensagem no Error). */
|
|
294
|
+
upstreamRequestFailed: upstreamRequestFailed,
|
|
276
295
|
refetch: ctxHistory.refetch,
|
|
277
296
|
loadingProgress: loadingProgress
|
|
278
297
|
};
|
|
@@ -70,12 +70,16 @@ var GenerativeAI = function (_a) {
|
|
|
70
70
|
var _o = useStreamQuery("SELECT FROM 'LlamaApi'.'Consulta'", summaryQueryData, streamMode === 'summary' && !!summaryQueryData), summaryIterator = _o.responseIterator, summaryError = _o.error, summaryLoading = _o.isLoading, refetchSummary = _o.refetch, abortSummary = _o.abort;
|
|
71
71
|
// Configura a query chat
|
|
72
72
|
var _p = useStreamQuery("SELECT FROM 'LlamaApi'.'Consulta'", chatQueryData, streamMode === 'chat' && !!chatQueryData), chatIterator = _p.responseIterator, chatError = _p.error, chatLoading = _p.isLoading, refetchChat = _p.refetch, abortChat = _p.abort;
|
|
73
|
-
// Dispara o refetch
|
|
73
|
+
// Dispara o refetch quando summaryQueryData mudar, exceto após erro real (evita loop de crédito)
|
|
74
74
|
useEffect(function () {
|
|
75
|
-
|
|
75
|
+
var _a;
|
|
76
|
+
if (summaryQueryData && !summaryError) {
|
|
76
77
|
refetchSummary();
|
|
77
78
|
}
|
|
78
|
-
|
|
79
|
+
else if (summaryQueryData && summaryError && ((_a = import.meta.env) === null || _a === void 0 ? void 0 : _a.DEV)) {
|
|
80
|
+
console.debug('[GenerativeAI] refetch summary ignorado: erro na consulta anterior');
|
|
81
|
+
}
|
|
82
|
+
}, [summaryQueryData, refetchSummary, summaryError]);
|
|
79
83
|
// Detecta a transição de refreshQuery de false para true para reiniciar a consulta
|
|
80
84
|
var prevRefreshQueryRef = useRef(refreshQuery);
|
|
81
85
|
useEffect(function () {
|
|
@@ -90,9 +94,11 @@ var GenerativeAI = function (_a) {
|
|
|
90
94
|
}
|
|
91
95
|
// Incrementa o refreshKey para forçar a atualização da query
|
|
92
96
|
setRefreshKey(function (prev) { return prev + 1; });
|
|
97
|
+
// Retry explícito (refresh externo), mesmo se houve erro antes
|
|
98
|
+
refetchSummary();
|
|
93
99
|
}
|
|
94
100
|
prevRefreshQueryRef.current = refreshQuery;
|
|
95
|
-
}, [refreshQuery, abortSummary, streamMode]);
|
|
101
|
+
}, [refreshQuery, abortSummary, streamMode, refetchSummary]);
|
|
96
102
|
// Processa o stream da consulta summary (apenas uma vez)
|
|
97
103
|
var processedSummaryRef = useRef(false);
|
|
98
104
|
useEffect(function () {
|
|
@@ -246,21 +246,43 @@ var Liminar = function (_a) {
|
|
|
246
246
|
return;
|
|
247
247
|
var fetch = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
248
248
|
var dossie, processosJuridicos, depsLoaded, newIds, hash, sourceApi, sourceProcessos, _a, possuiIndiciosDeLiminarProtestosDoPassado, protestosIds, sourceProtestos, combined, finalStatus;
|
|
249
|
-
var _b;
|
|
250
|
-
return __generator(this, function (
|
|
251
|
-
switch (
|
|
249
|
+
var _b, _c, _d;
|
|
250
|
+
return __generator(this, function (_e) {
|
|
251
|
+
switch (_e.label) {
|
|
252
252
|
case 0:
|
|
253
253
|
dossie = globalData === null || globalData === void 0 ? void 0 : globalData.dossie;
|
|
254
254
|
processosJuridicos = globalData === null || globalData === void 0 ? void 0 : globalData.processosJuridicosData;
|
|
255
255
|
depsLoaded = !!(processosJuridicos === null || processosJuridicos === void 0 ? void 0 : processosJuridicos.isLoaded) && !!(dossie === null || dossie === void 0 ? void 0 : dossie.carousel);
|
|
256
256
|
if (!depsLoaded || ctx.type === RequestStatus.Loading)
|
|
257
257
|
return [2 /*return*/];
|
|
258
|
+
if (ctx.type === RequestStatus.Error ||
|
|
259
|
+
(processosJuridicos === null || processosJuridicos === void 0 ? void 0 : processosJuridicos.error) ||
|
|
260
|
+
((_b = globalData === null || globalData === void 0 ? void 0 : globalData.protestosData) === null || _b === void 0 ? void 0 : _b.error)) {
|
|
261
|
+
if ((_c = import.meta.env) === null || _c === void 0 ? void 0 : _c.DEV) {
|
|
262
|
+
console.debug('[Liminar] consulta complementar ignorada: upstream em erro');
|
|
263
|
+
}
|
|
264
|
+
if (!processedRef.current) {
|
|
265
|
+
setData(function (prev) { return (__assign(__assign({}, prev), { liminar: {
|
|
266
|
+
indiciosDeLiminar: false,
|
|
267
|
+
message: 'Não encontrado',
|
|
268
|
+
isLoaded: true,
|
|
269
|
+
processosComLiminarIds: [],
|
|
270
|
+
indiciosDeLiminarProtestosDoPassado: false,
|
|
271
|
+
protestosDoPassadoIds: '',
|
|
272
|
+
invertedProcessos: [],
|
|
273
|
+
origensLiminar: [],
|
|
274
|
+
descricaoLiminar: 'Não encontrado'
|
|
275
|
+
} })); });
|
|
276
|
+
processedRef.current = true;
|
|
277
|
+
}
|
|
278
|
+
return [2 /*return*/];
|
|
279
|
+
}
|
|
258
280
|
newIds = foundBusinessEntity
|
|
259
281
|
? processosComAssuntoValido.map(function (p) { return p.id; })
|
|
260
282
|
: [];
|
|
261
283
|
hash = JSON.stringify({
|
|
262
284
|
t: ctx.type,
|
|
263
|
-
indicios: (
|
|
285
|
+
indicios: (_d = ctx.document) === null || _d === void 0 ? void 0 : _d.indiciosDeLiminar,
|
|
264
286
|
carousel: dossie.carousel,
|
|
265
287
|
empresas: processosJuridicos.empresa
|
|
266
288
|
});
|
|
@@ -273,7 +295,7 @@ var Liminar = function (_a) {
|
|
|
273
295
|
setIsLoadingLiminarProtestosDoPassado(true);
|
|
274
296
|
return [4 /*yield*/, fetchLiminarProtestosDoPassado()];
|
|
275
297
|
case 1:
|
|
276
|
-
_a =
|
|
298
|
+
_a = _e.sent(), possuiIndiciosDeLiminarProtestosDoPassado = _a.possuiIndiciosDeLiminarProtestosDoPassado, protestosIds = _a.protestosDoPassadoIds;
|
|
277
299
|
setIsLoadingLiminarProtestosDoPassado(false);
|
|
278
300
|
sourceProtestos = detectLiminarFromProtestosDoPassado(possuiIndiciosDeLiminarProtestosDoPassado, protestosIds);
|
|
279
301
|
combined = combineLiminarSources([
|
|
@@ -11,6 +11,11 @@ export type ParsedResponse<T> = {
|
|
|
11
11
|
response: Response;
|
|
12
12
|
document: T;
|
|
13
13
|
};
|
|
14
|
+
/** Aviso de exceção esperada (`push=true` no XML); só exibe UI se houver `message` ou `code`. */
|
|
15
|
+
export type PushNotice = {
|
|
16
|
+
message?: string;
|
|
17
|
+
code?: number;
|
|
18
|
+
};
|
|
14
19
|
export type RequestContext<R> = {
|
|
15
20
|
data?: Client.Form;
|
|
16
21
|
urlData?: Client.Form;
|
|
@@ -24,6 +29,8 @@ export type RequestContext<R> = {
|
|
|
24
29
|
activeRequests?: number;
|
|
25
30
|
showLoadingBar?: boolean;
|
|
26
31
|
warningMessage?: string | null;
|
|
32
|
+
/** Presente quando o backend sinalizou `push=true` (situação esperada, fluxo segue). */
|
|
33
|
+
pushNotice?: PushNotice | null;
|
|
27
34
|
};
|
|
28
35
|
export type HeaderReplaceResponse = {
|
|
29
36
|
children: ReactNode;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ISectionProps, RequestStatus } from './requestContextTypes';
|
|
3
|
+
/** Aviso no header para exceção esperada (`push=true`): só a mensagem do backend. */
|
|
4
|
+
export declare function pushExceptionDescription(err: Error): React.ReactNode;
|
|
3
5
|
declare const Section: React.ForwardRefExoticComponent<Omit<ISectionProps<unknown>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
4
6
|
export declare const headerStatus: Record<RequestStatus, string>;
|
|
5
7
|
export default Section;
|
|
@@ -14,6 +14,7 @@ import { PrintSectionWrapper } from './common/printSectionWrapper';
|
|
|
14
14
|
import Header from './interface/header';
|
|
15
15
|
import StatusMessage from './interface/statusMessage';
|
|
16
16
|
import { RequestStatus } from './requestContextTypes';
|
|
17
|
+
import { isErrorWithPushFlag } from '../utils/classifyRequestError';
|
|
17
18
|
var ButtonWrapper = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n justify-content: center;\n width: 100%;\n height: 40%;\n max-height: 52px;\n max-width: 300px;\n margin: 0 auto;\n"], ["\n justify-content: center;\n width: 100%;\n height: 40%;\n max-height: 52px;\n max-width: 300px;\n margin: 0 auto;\n"])));
|
|
18
19
|
var sectionIdCounter = 0;
|
|
19
20
|
var nextSectionId = function () {
|
|
@@ -49,12 +50,22 @@ var useSectionPrintBlocker = function (ctx, title, enabled, registerBlocker, res
|
|
|
49
50
|
}
|
|
50
51
|
}, [ctx, enabled, registerBlocker, resolveBlocker, title]);
|
|
51
52
|
};
|
|
53
|
+
/** Aviso no header para exceção esperada (`push=true`): só a mensagem do backend. */
|
|
54
|
+
export function pushExceptionDescription(err) {
|
|
55
|
+
var _a;
|
|
56
|
+
var message = (_a = err.message) === null || _a === void 0 ? void 0 : _a.trim();
|
|
57
|
+
if (!message)
|
|
58
|
+
return undefined;
|
|
59
|
+
return React.createElement(StatusMessage, { type: "warning" }, message);
|
|
60
|
+
}
|
|
52
61
|
var Section = forwardRef(function (_a, ref) {
|
|
53
62
|
var onSuccess = _a.onSuccess, _b = _a.isError, isError = _b === void 0 ? function (err, ctx) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
if (isErrorWithPushFlag(err)) {
|
|
64
|
+
return {
|
|
65
|
+
children: React.createElement(React.Fragment, null),
|
|
66
|
+
description: pushExceptionDescription(err),
|
|
67
|
+
variant: 'default'
|
|
68
|
+
};
|
|
58
69
|
}
|
|
59
70
|
var message = 'Problemas de comunicação, tente novamente.';
|
|
60
71
|
return {
|
|
@@ -72,10 +83,18 @@ var Section = forwardRef(function (_a, ref) {
|
|
|
72
83
|
useSectionPrintBlocker(ctx, headerProps === null || headerProps === void 0 ? void 0 : headerProps.title, readinessEnabled, printReadiness.registerBlocker, printReadiness.resolveBlocker);
|
|
73
84
|
if (!ctx)
|
|
74
85
|
return null;
|
|
75
|
-
var type = ctx.type, progress = ctx.progress, warningMessage = ctx.warningMessage;
|
|
86
|
+
var type = ctx.type, progress = ctx.progress, warningMessage = ctx.warningMessage, pushNotice = ctx.pushNotice;
|
|
76
87
|
var renderResponse = useCallback(function () {
|
|
77
88
|
switch (type) {
|
|
78
89
|
case RequestStatus.Success:
|
|
90
|
+
if (pushNotice &&
|
|
91
|
+
(ctx.document === undefined || ctx.document === null)) {
|
|
92
|
+
return {
|
|
93
|
+
children: React.createElement(React.Fragment, null),
|
|
94
|
+
description: undefined,
|
|
95
|
+
variant: 'default'
|
|
96
|
+
};
|
|
97
|
+
}
|
|
79
98
|
return onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(ctx.document, ctx);
|
|
80
99
|
case RequestStatus.Error: {
|
|
81
100
|
var errorResult = isError(ctx.error, ctx);
|
|
@@ -92,21 +111,30 @@ var Section = forwardRef(function (_a, ref) {
|
|
|
92
111
|
default:
|
|
93
112
|
return null;
|
|
94
113
|
}
|
|
95
|
-
}, [type, onSuccess, isError, onLoading, ctx, printMode]);
|
|
114
|
+
}, [type, onSuccess, isError, onLoading, ctx, printMode, pushNotice]);
|
|
96
115
|
var renderedResponse = renderResponse();
|
|
97
|
-
var
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
React.createElement(
|
|
102
|
-
|
|
103
|
-
|
|
116
|
+
var descriptionWithAlerts = useCallback(function (description) {
|
|
117
|
+
var _a;
|
|
118
|
+
var out = description;
|
|
119
|
+
if (warningMessage) {
|
|
120
|
+
out = (React.createElement(React.Fragment, null,
|
|
121
|
+
React.createElement(StatusMessage, { type: "warning" }, warningMessage),
|
|
122
|
+
out));
|
|
123
|
+
}
|
|
124
|
+
var pushMessage = (_a = pushNotice === null || pushNotice === void 0 ? void 0 : pushNotice.message) === null || _a === void 0 ? void 0 : _a.trim();
|
|
125
|
+
if (pushMessage) {
|
|
126
|
+
out = (React.createElement(React.Fragment, null,
|
|
127
|
+
React.createElement(StatusMessage, { type: "warning" }, pushMessage),
|
|
128
|
+
out));
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}, [warningMessage, pushNotice]);
|
|
104
132
|
var defaultHeaderActions = useMemo(function () {
|
|
105
133
|
return !printMode ? (React.createElement(BtnWrapper, { hidden: type === RequestStatus.Loading, onClick: toggleOpen }, isOpen ? React.createElement(ChevronUp, null) : React.createElement(ChevronDown, null))) : null;
|
|
106
134
|
}, [type, isOpen, toggleOpen, printMode]);
|
|
107
135
|
var renderHeader = function (props) {
|
|
108
136
|
var description = props.description, actions = props.actions, rest = __rest(props, ["description", "actions"]);
|
|
109
|
-
return (React.createElement(Header, __assign({ printBar: renderedResponse !== null && isOpen }, rest, { description:
|
|
137
|
+
return (React.createElement(Header, __assign({ printBar: renderedResponse !== null && isOpen }, rest, { description: descriptionWithAlerts(description), className: cn(className, type !== undefined && headerStatus[type]
|
|
110
138
|
? headerStatus[type]
|
|
111
139
|
: '', props.className), variant: type === RequestStatus.Loading ? 'loading' : props.variant, loadingProps: {
|
|
112
140
|
percentage: progress !== null && progress !== void 0 ? progress : 0,
|
|
@@ -214,16 +214,26 @@ export function useStreamQuery(query, data, enabled) {
|
|
|
214
214
|
!abortControllerRef.current.signal.aborted) {
|
|
215
215
|
abortControllerRef.current.abort();
|
|
216
216
|
abortControllerRef.current = null;
|
|
217
|
-
setIsLoading(false);
|
|
218
|
-
hasStreamStartedRef.current = false;
|
|
219
|
-
setResponseIterator(null);
|
|
220
217
|
}
|
|
218
|
+
setIsLoading(false);
|
|
219
|
+
hasStreamStartedRef.current = false;
|
|
220
|
+
setResponseIterator(null);
|
|
221
221
|
}, []);
|
|
222
|
+
/**
|
|
223
|
+
* Invariante anti-loop: após falha, mantemos `responseIterator` não-nulo até `abortStream`
|
|
224
|
+
* (o `useEffect` abaixo só dispara novo fetch quando `!responseIterator`). Limpar o iterator
|
|
225
|
+
* em todo erro sem esse contrato faria o efeito reabrir HTTP em ciclo.
|
|
226
|
+
*/
|
|
222
227
|
useEffect(function () {
|
|
223
|
-
if (enabled
|
|
224
|
-
|
|
228
|
+
if (!enabled) {
|
|
229
|
+
abortStream();
|
|
230
|
+
return;
|
|
225
231
|
}
|
|
226
|
-
|
|
232
|
+
if (responseIterator)
|
|
233
|
+
return;
|
|
234
|
+
fetchStream();
|
|
235
|
+
}, [enabled, responseIterator, fetchStream, abortStream]);
|
|
236
|
+
useEffect(function () { return function () { return abortStream(); }; }, [abortStream]);
|
|
227
237
|
return {
|
|
228
238
|
responseIterator: responseIterator,
|
|
229
239
|
error: error,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EditalResponse, LiminarResponse, PDFProtestoDiscoverResponse, ProcessosJuridicosState } from '../@types/domain';
|
|
2
2
|
import { Client } from '@credithub/webservice';
|
|
3
3
|
import React, { Context, FC, PropsWithChildren } from 'react';
|
|
4
|
-
import { type ParsedResponse, type RequestContext } from './requestContextTypes';
|
|
4
|
+
import { type ParsedResponse, type PushNotice, type RequestContext } from './requestContextTypes';
|
|
5
5
|
export * from './requestContextTypes';
|
|
6
6
|
export declare const WebService: React.Context<Client.WebService>;
|
|
7
7
|
type RequestDefaults = {
|
|
@@ -25,6 +25,7 @@ export declare function CustomProvider<T extends Client.Form = Client.Form, R =
|
|
|
25
25
|
export declare function useQuery<R = unknown, T extends Client.Form = Client.Form>(query: string, data?: T, enabled?: boolean): {
|
|
26
26
|
response: ParsedResponse<R> | null;
|
|
27
27
|
error: Error | null;
|
|
28
|
+
pushNotice: PushNotice | null;
|
|
28
29
|
isLoading: boolean;
|
|
29
30
|
loadingProgress: number;
|
|
30
31
|
refetch: () => void;
|