Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1 of 3, feat(serviceConfig): sw-2024 allow response polling #1272

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ REACT_APP_UI_WINDOW_ID=curiosity

REACT_APP_AJAX_TIMEOUT=60000
REACT_APP_AJAX_CACHE=15000
REACT_APP_AJAX_POLL_INTERVAL=15000
REACT_APP_SELECTOR_CACHE=120000

REACT_APP_CONFIG_SERVICE_LOCALES_COOKIE=rh_locale
Expand Down
20 changes: 20 additions & 0 deletions src/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ Download the debug log file.
## General

* [General](#Helpers.module_General)
* [~memoClone](#Helpers.module_General..memoClone) ⇒ <code>any</code>
* [~noop](#Helpers.module_General..noop)
* [~noopPromise](#Helpers.module_General..noopPromise) : <code>Promise.&lt;{}&gt;</code>
* [~setImmutableData](#Helpers.module_General..setImmutableData) ⇒ <code>\*</code>
Expand Down Expand Up @@ -315,6 +316,25 @@ Download the debug log file.
* [~objFreeze(obj)](#Helpers.module_General..objFreeze) ⇒ <code>\*</code>
* [~browserExpose(obj, options)](#Helpers.module_General..browserExpose)

<a name="Helpers.module_General..memoClone"></a>

### General~memoClone ⇒ <code>any</code>
Used for the numerous configuration callbacks that drive the UI. Often the same data
is passed repeatedly. Avoid "accidental" mutation.

**Kind**: inner constant of [<code>General</code>](#Helpers.module_General)
<table>
<thead>
<tr>
<th>Param</th><th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>value</td><td><code>any</code></td>
</tr> </tbody>
</table>

<a name="Helpers.module_General..noop"></a>

### General~noop
Expand Down
3 changes: 3 additions & 0 deletions src/common/__tests__/__snapshots__/helpers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ exports[`Helpers should expose a window object: limited window object 1`] = `
"isPromise": [Function],
"lorem": "ipsum",
"memo": [Function],
"memoClone": [Function],
"noop": [Function],
"noopPromise": Promise {},
"numberDisplay": [Function],
Expand Down Expand Up @@ -90,6 +91,7 @@ exports[`Helpers should expose a window object: window object 1`] = `
"isPromise": [Function],
"lorem": "ipsum",
"memo": [Function],
"memoClone": [Function],
"noop": [Function],
"noopPromise": Promise {},
"numberDisplay": [Function],
Expand Down Expand Up @@ -147,6 +149,7 @@ exports[`Helpers should have specific functions: helpers 1`] = `
"isDate": [Function],
"isPromise": [Function],
"memo": [Function],
"memoClone": [Function],
"noop": [Function],
"noopPromise": Promise {},
"numberDisplay": [Function],
Expand Down
10 changes: 10 additions & 0 deletions src/common/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ const memo = (func, { cacheLimit = 1 } = {}) => {
return ized();
};

/**
* Used for the numerous configuration callbacks that drive the UI. Often the same data
* is passed repeatedly. Avoid "accidental" mutation.
*
* @param {any} value
* @returns {any}
*/
const memoClone = memo(value => _cloneDeep(value), { cacheLimit: 25 });

/**
* An empty function.
* Typically used as a default prop.
Expand Down Expand Up @@ -444,6 +453,7 @@ const helpers = {
isDate,
isPromise,
memo,
memoClone,
noop,
noopPromise,
numberDisplay,
Expand Down
11 changes: 11 additions & 0 deletions src/services/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ Axios config for cancelling, caching, and emulated service calls.

* [ServiceConfig](#Helpers.module_ServiceConfig)
* [~globalXhrTimeout](#Helpers.module_ServiceConfig..globalXhrTimeout) : <code>number</code>
* [~globalPollInterval](#Helpers.module_ServiceConfig..globalPollInterval) : <code>number</code>
* [~globalCancelTokens](#Helpers.module_ServiceConfig..globalCancelTokens) : <code>object</code>
* [~globalResponseCache](#Helpers.module_ServiceConfig..globalResponseCache) : <code>object</code>
* [~axiosServiceCall(config, options)](#Helpers.module_ServiceConfig..axiosServiceCall) ⇒ <code>Promise.&lt;\*&gt;</code>
Expand All @@ -169,6 +170,12 @@ Axios config for cancelling, caching, and emulated service calls.
### ServiceConfig~globalXhrTimeout : <code>number</code>
Set Axios XHR default timeout.

**Kind**: inner constant of [<code>ServiceConfig</code>](#Helpers.module_ServiceConfig)
<a name="Helpers.module_ServiceConfig..globalPollInterval"></a>

### ServiceConfig~globalPollInterval : <code>number</code>
Set Axios polling default.

**Kind**: inner constant of [<code>ServiceConfig</code>](#Helpers.module_ServiceConfig)
<a name="Helpers.module_ServiceConfig..globalCancelTokens"></a>

Expand Down Expand Up @@ -211,6 +218,8 @@ page or wait the "maxAge".
</tr><tr>
<td>config.params</td><td><code>object</code></td>
</tr><tr>
<td>config.poll</td><td><code>Object</code> | <code>function</code></td>
</tr><tr>
<td>config.schema</td><td><code>Array</code></td>
</tr><tr>
<td>config.transform</td><td><code>Array</code></td>
Expand All @@ -224,6 +233,8 @@ page or wait the "maxAge".
<td>options.responseCache</td><td><code>object</code></td>
</tr><tr>
<td>options.xhrTimeout</td><td><code>number</code></td>
</tr><tr>
<td>options.pollInterval</td><td><code>number</code></td>
</tr> </tbody>
</table>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ exports[`Service Helpers should have specific functions: serviceHelpers 1`] = `
{
"camelCase": [Function],
"generateHash": [Function],
"memoClone": [Function],
"passDataToCallback": [Function],
"schemaResponse": [Function],
"timeoutFunctionCancel": [Function],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,240 @@ exports[`ServiceConfig should handle cancelling service calls: cancelled request
]
`;

exports[`ServiceConfig should handle polling service call errors: location error 1`] = `
[
[
[Error: location string error],
],
]
`;

exports[`ServiceConfig should handle polling service call errors: status error 1`] = `
[
[
[Error: status error],
],
[
[Error: status error],
],
[
[Error: status error],
],
]
`;

exports[`ServiceConfig should handle polling service call errors: status error polling 1`] = `
{
"status": [
{
"count": 0,
"error": {
"data": "error",
"pollConfig": {
"__retryCount": 1,
"location": "/pollError",
"pollInterval": 1,
"status": [Function],
"validate": [Function],
},
},
"success": undefined,
},
],
}
`;

exports[`ServiceConfig should handle polling service call errors: status of a status error 1`] = `
[
[
[Error: status error],
],
]
`;

exports[`ServiceConfig should handle polling service call errors: status of a status error polling 1`] = `
{
"status": [
{
"count": 0,
"error": {
"data": "error",
"pollConfig": {
"__retryCount": 1,
"location": "/pollError",
"pollInterval": 1,
"status": [Function],
"validate": [Function],
},
},
"success": undefined,
},
],
}
`;

exports[`ServiceConfig should handle polling service call errors: validation error 1`] = `
[
[
[Error: basic validation error],
],
]
`;

exports[`ServiceConfig should handle polling service calls: basic polling validator 1`] = `
{
"output": {
"data": "success",
"pollConfig": {
"__retryCount": 1,
"location": "/test/",
"pollInterval": 1,
"validate": [Function],
},
},
"validator": [
{
"count": 0,
"success": {
"data": "success",
"pollConfig": [Function],
},
},
{
"count": 1,
"success": {
"data": "success",
"pollConfig": {
"__retryCount": 1,
"location": "/test/",
"pollInterval": 1,
"validate": [Function],
},
},
},
],
}
`;

exports[`ServiceConfig should handle polling service calls: custom location 1`] = `
{
"output": {
"data": "success",
"pollConfig": {
"__retryCount": 2,
"location": [Function],
"pollInterval": 1,
"validate": [Function],
},
},
"validator": [
{
"count": 0,
"success": {
"data": "success",
"pollConfig": {
"location": [Function],
"validate": [Function],
},
"url": "/test/",
},
},
{
"count": 1,
"success": {
"data": "success",
"pollConfig": {
"__retryCount": 1,
"location": [Function],
"pollInterval": 1,
"validate": [Function],
},
"url": "/pollSuccess/",
},
},
],
}
`;

exports[`ServiceConfig should handle polling service calls: specific polling validator 1`] = `
{
"output": {
"data": "success",
"pollConfig": {
"__retryCount": 1,
"location": "/test/",
"pollInterval": 1,
"validate": [Function],
},
},
"validator": [
{
"count": 0,
"success": {
"data": "success",
"pollConfig": {
"validate": [Function],
},
},
},
{
"count": 1,
"success": {
"data": "success",
"pollConfig": {
"__retryCount": 1,
"location": "/test/",
"pollInterval": 1,
"validate": [Function],
},
},
},
],
}
`;

exports[`ServiceConfig should handle polling service calls: status polling 1`] = `
{
"output": {
"data": "success",
"pollConfig": {
"status": [Function],
"validate": [Function],
},
},
"status": [
{
"count": 0,
"err": undefined,
"success": {
"data": "success",
"pollConfig": {
"__retryCount": 1,
"location": "/test/",
"pollInterval": 1,
"status": [Function],
"validate": [Function],
},
},
},
{
"count": 1,
"err": undefined,
"success": {
"data": "success",
"pollConfig": {
"__retryCount": 2,
"location": "/test/",
"pollInterval": 1,
"status": [Function],
"validate": [Function],
},
},
},
],
}
`;

exports[`ServiceConfig should handle producing a service call configuration: response configs 1`] = `
[
"{
Expand Down Expand Up @@ -363,7 +597,9 @@ exports[`ServiceConfig should handle transforming service call responses: transf
[
"success-schema-transform",
"success-transform",
"success",
"error-error-transform",
"error",
[
"cancelled request",
undefined,
Expand All @@ -375,6 +611,7 @@ exports[`ServiceConfig should have specific properties and methods: specific pro
[
"axiosServiceCall",
"globalXhrTimeout",
"globalPollInterval",
"globalCancelTokens",
"globalResponseCache",
]
Expand Down
Loading
Loading