@credithub/harlan-components 1.35.0 → 1.35.1

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.
@@ -38,12 +38,14 @@ import { PrintSectionWrapper } from './common/printSectionWrapper';
38
38
  import Header from './interface/header';
39
39
  import StatusMessage from './interface/statusMessage';
40
40
  import { RequestStatus } from './webservice';
41
+ 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"])));
41
42
  export var Section = function (_a) {
42
43
  var onSuccess = _a.onSuccess, _b = _a.isError, isError = _b === void 0 ? function (err, ctx) { return ({
43
44
  children: React.createElement(React.Fragment, null),
44
45
  description: (React.createElement(React.Fragment, null,
45
46
  React.createElement(StatusMessage, { type: "error" }, err.message))),
46
- actions: (React.createElement(React.Fragment, null, (ctx === null || ctx === void 0 ? void 0 : ctx.refetch) && (React.createElement(Button, { onClick: function () { return ctx.refetch(); } }, "Tentar Novamente"))))
47
+ actions: (React.createElement(React.Fragment, null, (ctx === null || ctx === void 0 ? void 0 : ctx.refetch) && (React.createElement(ButtonWrapper, null,
48
+ React.createElement(Button, { onClick: function () { return ctx.refetch(); } }, "Tentar Novamente")))))
47
49
  }); } : _b, _c = _a.onLoading, onLoading = _c === void 0 ? function () { return React.createElement(React.Fragment, null); } : _c, ctx = _a.ctx, className = _a.className, _d = _a.hideHeader, hideHeader = _d === void 0 ? false : _d, _e = _a.minimized, minimized = _e === void 0 ? false : _e, headerProps = __rest(_a, ["onSuccess", "isError", "onLoading", "ctx", "className", "hideHeader", "minimized"]);
48
50
  var _f = useToggle(!minimized), isOpen = _f[0], toggleOpen = _f[1];
49
51
  if (!ctx)
@@ -83,11 +85,11 @@ export var Section = function (_a) {
83
85
  !hideHeader && renderHeader(unifiedHeaderProps),
84
86
  React.createElement(ShowRenderedChildren, { isOpen: isOpen }, renderedChildren)));
85
87
  };
86
- var ShowRenderedChildren = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: ", ";\n"], ["\n display: ", ";\n"])), function (props) { return (props.isOpen ? 'block' : 'none'); });
88
+ var ShowRenderedChildren = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: ", ";\n"], ["\n display: ", ";\n"])), function (props) { return (props.isOpen ? 'block' : 'none'); });
87
89
  export var headerStatus = (_a = {},
88
90
  _a[RequestStatus === null || RequestStatus === void 0 ? void 0 : RequestStatus.Loading] = 'external-source loading',
89
91
  _a[RequestStatus === null || RequestStatus === void 0 ? void 0 : RequestStatus.Success] = 'success',
90
92
  _a[RequestStatus === null || RequestStatus === void 0 ? void 0 : RequestStatus.Error] = 'external-source error',
91
93
  _a[RequestStatus === null || RequestStatus === void 0 ? void 0 : RequestStatus.Empty] = 'external-source error',
92
94
  _a);
93
- var templateObject_1;
95
+ var templateObject_1, templateObject_2;
@@ -23,7 +23,8 @@ export function CustomProvider(Provider, query) {
23
23
  var _e = useState(0), progress = _e[0], setProgress = _e[1];
24
24
  var _f = useState(new Map()), requestsMap = _f[0], setRequestsMap = _f[1];
25
25
  var _g = useState(false), showLoadingBar = _g[0], setShowLoadingBar = _g[1];
26
- // Simula o progresso da barra de carregamento
26
+ var _h = useState(false), shouldRetry = _h[0], setShouldRetry = _h[1];
27
+ var _j = useState(false), requestCompleted = _j[0], setRequestCompleted = _j[1];
27
28
  var simulateProgress = useCallback(function () {
28
29
  setProgress(0);
29
30
  var currentProgress = 0;
@@ -37,8 +38,8 @@ export function CustomProvider(Provider, query) {
37
38
  return function () { return clearInterval(interval); };
38
39
  }, []);
39
40
  var fetchData = useCallback(function () {
40
- if (loading)
41
- return; // Evita chamadas duplicadas
41
+ if (loading || requestCompleted)
42
+ return;
42
43
  setLoading(true);
43
44
  setError(null);
44
45
  setShowLoadingBar(true);
@@ -57,6 +58,7 @@ export function CustomProvider(Provider, query) {
57
58
  .then(function (parsedResponse) {
58
59
  setResponse(parsedResponse);
59
60
  setError(null);
61
+ setRequestCompleted(true);
60
62
  })
61
63
  .catch(function (requestError) {
62
64
  if (requestError.name !== 'AbortError') {
@@ -64,6 +66,7 @@ export function CustomProvider(Provider, query) {
64
66
  ? requestError
65
67
  : new Error(String(requestError)));
66
68
  }
69
+ setRequestCompleted(true);
67
70
  })
68
71
  .finally(function () {
69
72
  setLoading(false);
@@ -72,7 +75,6 @@ export function CustomProvider(Provider, query) {
72
75
  newMap.delete(requestId);
73
76
  return newMap;
74
77
  });
75
- // Atualiza o progresso para 100% e esconde a barra de carregamento
76
78
  setProgress(100);
77
79
  setTimeout(function () {
78
80
  setShowLoadingBar(false);
@@ -86,13 +88,30 @@ export function CustomProvider(Provider, query) {
86
88
  return newMap;
87
89
  });
88
90
  };
89
- }, [client, query, data, urlData, loading, simulateProgress]); // Adiciona `loading` como dependência
90
- // `useEffect` para iniciar a busca de dados apenas uma vez
91
+ }, [
92
+ client,
93
+ query,
94
+ data,
95
+ urlData,
96
+ loading,
97
+ simulateProgress,
98
+ requestCompleted
99
+ ]);
100
+ useEffect(function () {
101
+ if (!response &&
102
+ !loading &&
103
+ requestsMap.size === 0 &&
104
+ !requestCompleted) {
105
+ fetchData();
106
+ }
107
+ }, [fetchData, response, loading, requestsMap, requestCompleted]);
91
108
  useEffect(function () {
92
- if (!response && !loading && requestsMap.size === 0) {
109
+ if (shouldRetry) {
110
+ setShouldRetry(false);
111
+ setRequestCompleted(false);
93
112
  fetchData();
94
113
  }
95
- }, [fetchData, response, loading, requestsMap]);
114
+ }, [shouldRetry, fetchData]);
96
115
  var contextValue = useMemo(function () {
97
116
  var activeRequestsCount = requestsMap.size;
98
117
  return {
@@ -109,7 +128,10 @@ export function CustomProvider(Provider, query) {
109
128
  response: response === null || response === void 0 ? void 0 : response.response,
110
129
  document: response === null || response === void 0 ? void 0 : response.document,
111
130
  Section: Section,
112
- refetch: fetchData,
131
+ refetch: function () {
132
+ setShouldRetry(true);
133
+ setRequestCompleted(false);
134
+ },
113
135
  progress: progress,
114
136
  activeRequests: activeRequestsCount,
115
137
  showLoadingBar: showLoadingBar
@@ -120,7 +142,6 @@ export function CustomProvider(Provider, query) {
120
142
  data,
121
143
  urlData,
122
144
  loading,
123
- fetchData,
124
145
  progress,
125
146
  requestsMap,
126
147
  showLoadingBar