@credithub/harlan-components 1.107.1 → 1.108.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/section.js +20 -10
- package/dist/components/webservice.d.ts +1 -0
- package/dist/components/webservice.js +52 -2
- package/lib/cjs/index.js +75 -15
- package/lib/esm/index.js +75 -15
- package/package.json +1 -1
|
@@ -57,7 +57,7 @@ var Section = forwardRef(function (_a, ref) {
|
|
|
57
57
|
var printMode = usePrintMode().printMode;
|
|
58
58
|
if (!ctx)
|
|
59
59
|
return null;
|
|
60
|
-
var type = ctx.type, progress = ctx.progress;
|
|
60
|
+
var type = ctx.type, progress = ctx.progress, warningMessage = ctx.warningMessage;
|
|
61
61
|
var renderResponse = useCallback(function () {
|
|
62
62
|
switch (type) {
|
|
63
63
|
case RequestStatus.Success:
|
|
@@ -79,18 +79,28 @@ var Section = forwardRef(function (_a, ref) {
|
|
|
79
79
|
}
|
|
80
80
|
}, [type, onSuccess, isError, onLoading, ctx, printMode]);
|
|
81
81
|
var renderedResponse = renderResponse();
|
|
82
|
+
var descriptionWithWarning = useCallback(function (description) {
|
|
83
|
+
if (!warningMessage)
|
|
84
|
+
return description;
|
|
85
|
+
return (React.createElement(React.Fragment, null,
|
|
86
|
+
React.createElement(StatusMessage, { type: "warning" }, warningMessage),
|
|
87
|
+
description));
|
|
88
|
+
}, [warningMessage]);
|
|
82
89
|
var defaultHeaderActions = useMemo(function () {
|
|
83
90
|
return !printMode ? (React.createElement(BtnWrapper, { hidden: type === RequestStatus.Loading, onClick: toggleOpen }, isOpen ? React.createElement(ChevronUp, null) : React.createElement(ChevronDown, null))) : null;
|
|
84
91
|
}, [type, isOpen, toggleOpen, printMode]);
|
|
85
|
-
var renderHeader = function (props) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
var renderHeader = function (props) {
|
|
93
|
+
var description = props.description, actions = props.actions, rest = __rest(props, ["description", "actions"]);
|
|
94
|
+
return (React.createElement(Header, __assign({ printBar: renderedResponse !== null && isOpen }, rest, { description: descriptionWithWarning(description), className: cn(className, type !== undefined && headerStatus[type]
|
|
95
|
+
? headerStatus[type]
|
|
96
|
+
: '', props.className), variant: type === RequestStatus.Loading ? 'loading' : props.variant, loadingProps: {
|
|
97
|
+
percentage: progress !== null && progress !== void 0 ? progress : 0,
|
|
98
|
+
activeRequests: ctx.activeRequests,
|
|
99
|
+
hidden: false
|
|
100
|
+
}, actions: React.createElement(React.Fragment, null,
|
|
101
|
+
actions,
|
|
102
|
+
renderedResponse && defaultHeaderActions) })));
|
|
103
|
+
};
|
|
94
104
|
if (React.isValidElement(renderedResponse)) {
|
|
95
105
|
return (React.createElement(PrintSectionWrapper, { enabled: !hideHeader },
|
|
96
106
|
!hideHeader && renderHeader(headerProps),
|
|
@@ -62,6 +62,53 @@ export var RequestStatus;
|
|
|
62
62
|
RequestStatus[RequestStatus["Success"] = 2] = "Success";
|
|
63
63
|
RequestStatus[RequestStatus["Error"] = 3] = "Error";
|
|
64
64
|
})(RequestStatus || (RequestStatus = {}));
|
|
65
|
+
var isDocument = function (value) {
|
|
66
|
+
return typeof Document !== 'undefined' && value instanceof Document;
|
|
67
|
+
};
|
|
68
|
+
var extractWarningFromDocument = function (document) {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
if (!document)
|
|
71
|
+
return null;
|
|
72
|
+
if (isDocument(document)) {
|
|
73
|
+
var header = document.querySelector('header');
|
|
74
|
+
if (!header)
|
|
75
|
+
return null;
|
|
76
|
+
var warningElement = (_a = header.querySelector('warning, Warning, WARNING')) !== null && _a !== void 0 ? _a : null;
|
|
77
|
+
if (warningElement === null || warningElement === void 0 ? void 0 : warningElement.textContent) {
|
|
78
|
+
var text = warningElement.textContent.trim();
|
|
79
|
+
if (text)
|
|
80
|
+
return text;
|
|
81
|
+
}
|
|
82
|
+
var attributeWarning = (_b = header.getAttribute('_warning')) !== null && _b !== void 0 ? _b : header.getAttribute('warning');
|
|
83
|
+
if (attributeWarning) {
|
|
84
|
+
var trimmed = attributeWarning.trim();
|
|
85
|
+
if (trimmed)
|
|
86
|
+
return trimmed;
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
if (typeof document === 'object') {
|
|
91
|
+
var warning = document._warning;
|
|
92
|
+
if (typeof warning === 'string') {
|
|
93
|
+
var trimmed = warning.trim();
|
|
94
|
+
return trimmed ? trimmed : null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (typeof document === 'string') {
|
|
98
|
+
try {
|
|
99
|
+
var parsed = JSON.parse(document);
|
|
100
|
+
var warning = parsed === null || parsed === void 0 ? void 0 : parsed._warning;
|
|
101
|
+
if (typeof warning === 'string') {
|
|
102
|
+
var trimmed = warning.trim();
|
|
103
|
+
return trimmed ? trimmed : null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (_c) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
};
|
|
65
112
|
export function CustomProvider(Provider, query) {
|
|
66
113
|
return function (_a) {
|
|
67
114
|
var children = _a.children, data = _a.data, urlData = _a.urlData, _b = _a.depends, depends = _b === void 0 ? [] : _b;
|
|
@@ -181,6 +228,7 @@ export function CustomProvider(Provider, query) {
|
|
|
181
228
|
}, [shouldRetry, fetchData]);
|
|
182
229
|
var contextValue = useMemo(function () {
|
|
183
230
|
var activeRequestsCount = requestsMap.size;
|
|
231
|
+
var warningMessage = extractWarningFromDocument(response === null || response === void 0 ? void 0 : response.document);
|
|
184
232
|
return {
|
|
185
233
|
type: error
|
|
186
234
|
? RequestStatus.Error
|
|
@@ -201,7 +249,8 @@ export function CustomProvider(Provider, query) {
|
|
|
201
249
|
},
|
|
202
250
|
progress: progress,
|
|
203
251
|
activeRequests: activeRequestsCount,
|
|
204
|
-
showLoadingBar: showLoadingBar
|
|
252
|
+
showLoadingBar: showLoadingBar,
|
|
253
|
+
warningMessage: warningMessage
|
|
205
254
|
};
|
|
206
255
|
}, [
|
|
207
256
|
error,
|
|
@@ -378,7 +427,8 @@ export function query(query) {
|
|
|
378
427
|
urlData: undefined,
|
|
379
428
|
progress: 0,
|
|
380
429
|
activeRequests: 0,
|
|
381
|
-
showLoadingBar: false
|
|
430
|
+
showLoadingBar: false,
|
|
431
|
+
warningMessage: null
|
|
382
432
|
});
|
|
383
433
|
return Object.assign(RequestContext, {
|
|
384
434
|
Request: CustomProvider(RequestContext, query)
|