@pagopa/selfcare-common-frontend 1.5.1 → 1.5.5
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/CHANGELOG.md +25 -0
- package/README.md +13 -4
- package/build.info +2 -2
- package/hooks/useReduxCachedValue.d.ts +8 -3
- package/hooks/useReduxCachedValue.js +21 -10
- package/hooks/useReduxCachedValue.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,8 +4,33 @@ All notable changes to this project will be documented in this file. Dates are d
|
|
|
4
4
|
|
|
5
5
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
6
6
|
|
|
7
|
+
#### [v1.5.5](https://github.com/pagopa/selfcare-common-frontend/compare/v1.5.4...v1.5.5)
|
|
8
|
+
|
|
9
|
+
- useReduxCachedValueTranscoded transcode function will accept retrieverServiceArgs [`#30`](https://github.com/pagopa/selfcare-common-frontend/pull/30)
|
|
10
|
+
|
|
11
|
+
#### [v1.5.4](https://github.com/pagopa/selfcare-common-frontend/compare/v1.5.3...v1.5.4)
|
|
12
|
+
|
|
13
|
+
> 15 February 2022
|
|
14
|
+
|
|
15
|
+
- fixed useReduxCachedValueTranscoded parameters types [`#29`](https://github.com/pagopa/selfcare-common-frontend/pull/29)
|
|
16
|
+
|
|
17
|
+
#### [v1.5.3](https://github.com/pagopa/selfcare-common-frontend/compare/v1.5.2...v1.5.3)
|
|
18
|
+
|
|
19
|
+
> 15 February 2022
|
|
20
|
+
|
|
21
|
+
- added useReduxCachedValueTranscoded [`#28`](https://github.com/pagopa/selfcare-common-frontend/pull/28)
|
|
22
|
+
|
|
23
|
+
#### [v1.5.2](https://github.com/pagopa/selfcare-common-frontend/compare/v1.5.1...v1.5.2)
|
|
24
|
+
|
|
25
|
+
> 14 February 2022
|
|
26
|
+
|
|
27
|
+
- Fixed useReduxCachedValue setterAction type [`#27`](https://github.com/pagopa/selfcare-common-frontend/pull/27)
|
|
28
|
+
- Bump follow-redirects from 1.14.7 to 1.14.8 [`#26`](https://github.com/pagopa/selfcare-common-frontend/pull/26)
|
|
29
|
+
|
|
7
30
|
#### [v1.5.1](https://github.com/pagopa/selfcare-common-frontend/compare/v1.5.0...v1.5.1)
|
|
8
31
|
|
|
32
|
+
> 14 February 2022
|
|
33
|
+
|
|
9
34
|
- withRetrievedValue will accept a component to show while loading [`#25`](https://github.com/pagopa/selfcare-common-frontend/pull/25)
|
|
10
35
|
|
|
11
36
|
#### [v1.5.0](https://github.com/pagopa/selfcare-common-frontend/compare/v1.4.1...v1.5.0)
|
package/README.md
CHANGED
|
@@ -204,17 +204,26 @@ Cached values are stored using useRef, so they are local to the component using
|
|
|
204
204
|
The sorting actually is applied using string representation
|
|
205
205
|
|
|
206
206
|
## useReduxCachedValue
|
|
207
|
-
|
|
207
|
+
See [useReduxCachedValueTranscoded](#usereduxcachedvaluetranscoded) when RETRIEVED_VALUE === RETRIEVER_ARGS
|
|
208
|
+
|
|
209
|
+
## useReduxCachedValueTranscoded
|
|
210
|
+
It will return a method that will call the retrieverService only when there are not storing values, or a condition on them is not more verified.
|
|
208
211
|
See useReduxCachedValue.test.tsx file for an example.
|
|
209
212
|
|
|
213
|
+
Given the following type parametes:
|
|
214
|
+
* RETRIEVED_VALUE the type desired
|
|
215
|
+
* STORED_VALUE the type stored
|
|
216
|
+
|
|
210
217
|
The arguments to provide to the custom hook are the following:
|
|
211
218
|
|
|
212
219
|
| Prop | Type | Mandatory | Description |
|
|
213
220
|
|------|------|-----------|-------------|
|
|
214
221
|
| entity | string | Y | The name of the entity, used just for logging purpose |
|
|
215
|
-
| retrieverService | () => Promise`<
|
|
216
|
-
| reduxSelector | (state: any) =>
|
|
217
|
-
| reduxSetterAction |
|
|
222
|
+
| retrieverService | (retrieverServiceArgs: RETRIEVER_ARGS) => Promise`<RETRIEVED_VALUE>` | Y | The service that will retrieve the value |
|
|
223
|
+
| reduxSelector | (state: any) => STORED_VALUE | undefined | Y | The selector to read the value from redux |
|
|
224
|
+
| reduxSetterAction | (value: RETRIEVED_VALUE, retrieverServiceArgs: RETRIEVER_ARGS) => PayloadAction`<STORED_VALUE>` | Y | The action to store the value |
|
|
225
|
+
| selectedValue2RetrievedValue | (value: STORED_VALUE, args: RETRIEVER_ARGS) => RETRIEVED_VALUE | Y | A function called to transform STORED_VALUE into RETRIEVED_VALUE and called when hitting the cache |
|
|
226
|
+
| selectedValuePredicate2Retrieve | (value: STORED_VALUE, retrieverServiceArgs: RETRIEVER_ARGS) => boolean | N | An optional predicate evaluated when reduxSelector returned some value in order to compare it against the retrieverServiceArgs and evaluate if retrieverService should be called again |
|
|
218
227
|
| alwaysRetrieve | boolean | N | If true, it will always retrieve and store the new value |
|
|
219
228
|
|
|
220
229
|
# Features
|
package/build.info
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
20220215.3 - selfcare-common-frontend.deploy(20507)
|
|
2
|
+
tags/v1.5.5^0 53f03f574a66373756e3ebd2907ead3dc6fedc27
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
/**
|
|
3
|
-
declare const useReduxCachedValue: <
|
|
1
|
+
import { PayloadAction } from '@reduxjs/toolkit';
|
|
2
|
+
/** @see {useReduxCachedValue} when RETRIEVED_VALUE === STORED_VALUE */
|
|
3
|
+
declare const useReduxCachedValue: <RETRIEVED_VALUE, RETRIEVER_ARGS>(entity: string, retrieverService: (retrieverServiceArgs: RETRIEVER_ARGS) => Promise<RETRIEVED_VALUE>, reduxSelector: (state: any) => RETRIEVED_VALUE | undefined, reduxSetterAction: (value: RETRIEVED_VALUE, retrieverServiceArgs: RETRIEVER_ARGS) => PayloadAction<any>, selectedValuePredicate2Retrieve?: ((value: RETRIEVED_VALUE, args: RETRIEVER_ARGS) => boolean) | undefined, alwaysRetrieve?: boolean | undefined) => (retrieverServiceArgs: RETRIEVER_ARGS) => Promise<RETRIEVED_VALUE>;
|
|
4
|
+
/** It will return a method that will call the retrieverService only when there are not storing values, or a condition on them is not more verified */
|
|
5
|
+
export declare const useReduxCachedValueTranscoded: <RETRIEVED_VALUE, STORED_VALUE, RETRIEVER_ARGS>(entity: string, retrieverService: (retrieverServiceArgs: RETRIEVER_ARGS) => Promise<RETRIEVED_VALUE>, reduxSelector: (state: any) => STORED_VALUE | undefined, reduxSetterAction: (value: RETRIEVED_VALUE, retrieverServiceArgs: RETRIEVER_ARGS) => {
|
|
6
|
+
payload: STORED_VALUE;
|
|
7
|
+
type: string;
|
|
8
|
+
}, selectedValue2RetrievedValue: (value: STORED_VALUE, args: RETRIEVER_ARGS) => RETRIEVED_VALUE, selectedValuePredicate2Retrieve?: ((value: STORED_VALUE, args: RETRIEVER_ARGS) => boolean) | undefined, alwaysRetrieve?: boolean | undefined) => (retrieverServiceArgs: RETRIEVER_ARGS) => Promise<RETRIEVED_VALUE>;
|
|
4
9
|
export default useReduxCachedValue;
|
|
@@ -1,39 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useReduxCachedValueTranscoded = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
5
|
const react_redux_1 = require("react-redux");
|
|
5
6
|
const constants_1 = require("../utils/constants");
|
|
6
7
|
const useLoading_1 = (0, tslib_1.__importDefault)(require("./useLoading"));
|
|
7
|
-
/**
|
|
8
|
-
const useReduxCachedValue = (
|
|
8
|
+
/** @see {useReduxCachedValue} when RETRIEVED_VALUE === STORED_VALUE */
|
|
9
|
+
const useReduxCachedValue = (entity, retrieverService, reduxSelector, reduxSetterAction, selectedValuePredicate2Retrieve, alwaysRetrieve) => (0, exports.useReduxCachedValueTranscoded)(entity, retrieverService, reduxSelector, reduxSetterAction, (value) => value, selectedValuePredicate2Retrieve, alwaysRetrieve);
|
|
10
|
+
/** It will return a method that will call the retrieverService only when there are not storing values, or a condition on them is not more verified */
|
|
11
|
+
const useReduxCachedValueTranscoded = (
|
|
9
12
|
/** The name of the entity, used just for logging purpose */
|
|
10
13
|
entity,
|
|
11
14
|
/** The service that will retrieve the value */
|
|
12
15
|
retrieverService,
|
|
13
|
-
/** The selector to
|
|
16
|
+
/** The selector to read the value from redux */
|
|
14
17
|
reduxSelector,
|
|
15
|
-
/** The action to store the value */
|
|
18
|
+
/** The action to store the new value */
|
|
16
19
|
reduxSetterAction,
|
|
20
|
+
/** A function called to transform STORED_VALUE into RETRIEVED_VALUE and called when hitting the cache */
|
|
21
|
+
selectedValue2RetrievedValue,
|
|
22
|
+
/** An optional predicate evaluated when reduxSelector returned some value in order to compare it against the retrieverServiceArgs and evaluate if retrieverService should be called again */
|
|
23
|
+
selectedValuePredicate2Retrieve,
|
|
17
24
|
/** If true, it will always retrieve and store the new value */
|
|
18
25
|
alwaysRetrieve) => {
|
|
19
26
|
const dispatch = (0, react_redux_1.useDispatch)();
|
|
20
27
|
const entities = (0, react_redux_1.useSelector)(reduxSelector);
|
|
21
|
-
const setEntities = (value) => dispatch(reduxSetterAction(value));
|
|
28
|
+
const setEntities = (value, retrieverServiceArgs) => dispatch(reduxSetterAction(value, retrieverServiceArgs));
|
|
22
29
|
const setLoading = (0, useLoading_1.default)(`${constants_1.LOADING_TASK_RETRIEVE_CACHED_VALUES}_${entity}`);
|
|
23
|
-
return () => {
|
|
24
|
-
if (alwaysRetrieve ||
|
|
30
|
+
return (retrieverServiceArgs) => {
|
|
31
|
+
if (alwaysRetrieve ||
|
|
32
|
+
!entities ||
|
|
33
|
+
(selectedValuePredicate2Retrieve &&
|
|
34
|
+
selectedValuePredicate2Retrieve(entities, retrieverServiceArgs))) {
|
|
25
35
|
setLoading(true);
|
|
26
|
-
return retrieverService()
|
|
36
|
+
return retrieverService(retrieverServiceArgs)
|
|
27
37
|
.then((e) => {
|
|
28
|
-
setEntities(e);
|
|
38
|
+
setEntities(e, retrieverServiceArgs);
|
|
29
39
|
return e;
|
|
30
40
|
})
|
|
31
41
|
.finally(() => setLoading(false));
|
|
32
42
|
}
|
|
33
43
|
else {
|
|
34
|
-
return new Promise((resolve) => resolve(entities));
|
|
44
|
+
return new Promise((resolve) => resolve(selectedValue2RetrievedValue(entities, retrieverServiceArgs)));
|
|
35
45
|
}
|
|
36
46
|
};
|
|
37
47
|
};
|
|
48
|
+
exports.useReduxCachedValueTranscoded = useReduxCachedValueTranscoded;
|
|
38
49
|
exports.default = useReduxCachedValue;
|
|
39
50
|
//# sourceMappingURL=useReduxCachedValue.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useReduxCachedValue.js","sourceRoot":"","sources":["../../src/lib/hooks/useReduxCachedValue.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useReduxCachedValue.js","sourceRoot":"","sources":["../../src/lib/hooks/useReduxCachedValue.tsx"],"names":[],"mappings":";;;;AACA,6CAAuD;AACvD,kDAAyE;AACzE,2EAAsC;AAEtC,uEAAuE;AACvE,MAAM,mBAAmB,GAAG,CAC1B,MAAc,EACd,gBAAoF,EACpF,aAA0D,EAC1D,iBAGuB,EACvB,+BAA2F,EAC3F,cAAwB,EAC8C,EAAE,CACxE,IAAA,qCAA6B,EAC3B,MAAM,EACN,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAChB,+BAA+B,EAC/B,cAAc,CACf,CAAC;AAEJ,sJAAsJ;AAC/I,MAAM,6BAA6B,GAAG;AAC3C,4DAA4D;AAC5D,MAAc;AACd,+CAA+C;AAC/C,gBAAoF;AACpF,gDAAgD;AAChD,aAAuD;AACvD,wCAAwC;AACxC,iBAGgC;AAChC,yGAAyG;AACzG,4BAA4F;AAC5F,8LAA8L;AAC9L,+BAAwF;AACxF,+DAA+D;AAC/D,cAAwB,EAC8C,EAAE;IACxE,MAAM,QAAQ,GAAG,IAAA,yBAAW,GAAE,CAAC;IAC/B,MAAM,QAAQ,GAAG,IAAA,yBAAW,EAAC,aAAa,CAAC,CAAC;IAC5C,MAAM,WAAW,GAAG,CAAC,KAAsB,EAAE,oBAAoC,EAAE,EAAE,CACnF,QAAQ,CAAC,iBAAiB,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;IAE3D,MAAM,UAAU,GAAG,IAAA,oBAAU,EAAC,GAAG,+CAAmC,IAAI,MAAM,EAAE,CAAC,CAAC;IAElF,OAAO,CAAC,oBAAoC,EAA4B,EAAE;QACxE,IACE,cAAc;YACd,CAAC,QAAQ;YACT,CAAC,+BAA+B;gBAC9B,+BAA+B,CAAC,QAAQ,EAAE,oBAAoB,CAAC,CAAC,EAClE;YACA,UAAU,CAAC,IAAI,CAAC,CAAC;YACjB,OAAO,gBAAgB,CAAC,oBAAoB,CAAC;iBAC1C,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;gBACV,WAAW,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;gBACrC,OAAO,CAAC,CAAC;YACX,CAAC,CAAC;iBACD,OAAO,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;SACrC;aAAM;YACL,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAC7B,OAAO,CAAC,4BAA4B,CAAC,QAAQ,EAAE,oBAAoB,CAAC,CAAC,CACtE,CAAC;SACH;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AA9CW,QAAA,6BAA6B,iCA8CxC;AAEF,kBAAe,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagopa/selfcare-common-frontend",
|
|
3
3
|
"description": "Shared React components for the pagopa selfcare project",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.5",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/pagopa/selfcare-common-frontend",
|
|
7
7
|
"author": "https://www.pagopa.gov.it",
|