@pagopa/selfcare-common-frontend 1.5.2 → 1.5.6

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 CHANGED
@@ -4,8 +4,32 @@ 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.6](https://github.com/pagopa/selfcare-common-frontend/compare/v1.5.5...v1.5.6)
8
+
9
+ - added useReduxCachedValue overloaded versions [`#31`](https://github.com/pagopa/selfcare-common-frontend/pull/31)
10
+
11
+ #### [v1.5.5](https://github.com/pagopa/selfcare-common-frontend/compare/v1.5.4...v1.5.5)
12
+
13
+ > 15 February 2022
14
+
15
+ - useReduxCachedValueTranscoded transcode function will accept retrieverServiceArgs [`#30`](https://github.com/pagopa/selfcare-common-frontend/pull/30)
16
+
17
+ #### [v1.5.4](https://github.com/pagopa/selfcare-common-frontend/compare/v1.5.3...v1.5.4)
18
+
19
+ > 15 February 2022
20
+
21
+ - fixed useReduxCachedValueTranscoded parameters types [`#29`](https://github.com/pagopa/selfcare-common-frontend/pull/29)
22
+
23
+ #### [v1.5.3](https://github.com/pagopa/selfcare-common-frontend/compare/v1.5.2...v1.5.3)
24
+
25
+ > 15 February 2022
26
+
27
+ - added useReduxCachedValueTranscoded [`#28`](https://github.com/pagopa/selfcare-common-frontend/pull/28)
28
+
7
29
  #### [v1.5.2](https://github.com/pagopa/selfcare-common-frontend/compare/v1.5.1...v1.5.2)
8
30
 
31
+ > 14 February 2022
32
+
9
33
  - Fixed useReduxCachedValue setterAction type [`#27`](https://github.com/pagopa/selfcare-common-frontend/pull/27)
10
34
  - Bump follow-redirects from 1.14.7 to 1.14.8 [`#26`](https://github.com/pagopa/selfcare-common-frontend/pull/26)
11
35
 
package/README.md CHANGED
@@ -204,17 +204,32 @@ 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
- It will return a method that only at the very first invocation it will call the retrieverService only the first time, storing the obtained values, and returning always cached values.
207
+ See [useReduxCachedValueParametricRetrieverTranscoded](#usereduxcachedvaluetranscoded) when there is not RETRIEVER_ARGS and RETRIEVED_VALUE === RETRIEVER_ARGS
208
+
209
+ ## useReduxCachedValueParametricRetriever
210
+ See [useReduxCachedValueParametricRetrieverTranscoded](#usereduxcachedvaluetranscoded) when RETRIEVED_VALUE === RETRIEVER_ARGS
211
+
212
+ ## useReduxCachedValueTranscoded
213
+ See [useReduxCachedValueParametricRetrieverTranscoded](#usereduxcachedvaluetranscoded) when there is not RETRIEVER_ARGS
214
+
215
+ ## useReduxCachedValueParametricRetrieverTranscoded
216
+ 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
217
  See useReduxCachedValue.test.tsx file for an example.
209
218
 
219
+ Given the following type parametes:
220
+ * RETRIEVED_VALUE the type desired
221
+ * STORED_VALUE the type stored
222
+
210
223
  The arguments to provide to the custom hook are the following:
211
224
 
212
225
  | Prop | Type | Mandatory | Description |
213
226
  |------|------|-----------|-------------|
214
227
  | entity | string | Y | The name of the entity, used just for logging purpose |
215
- | retrieverService | () => Promise`<T>` | Y | The service that will retrieve the value |
216
- | reduxSelector | (state: any) => T | undefined | Y | The selector to verify if a value already exists |
217
- | reduxSetterAction | (value: T) => PayloadAction`<any>` | Y | The action to store the value |
228
+ | retrieverService | (retrieverServiceArgs: RETRIEVER_ARGS) => Promise`<RETRIEVED_VALUE>` | Y | The service that will retrieve the value |
229
+ | reduxSelector | (state: any) => STORED_VALUE | undefined | Y | The selector to read the value from redux |
230
+ | reduxSetterAction | (value: RETRIEVED_VALUE, retrieverServiceArgs: RETRIEVER_ARGS) => PayloadAction`<STORED_VALUE>` | Y | The action to store the value |
231
+ | 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 |
232
+ | 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
233
  | alwaysRetrieve | boolean | N | If true, it will always retrieve and store the new value |
219
234
 
220
235
  # Features
package/build.info CHANGED
@@ -1,2 +1,2 @@
1
- 20220214.2 - selfcare-common-frontend.deploy(20361)
2
- tags/v1.5.2^0 e3f44b5032269a2cdb3136c6fd00f4a803d7457d
1
+ 20220215.4 - selfcare-common-frontend.deploy(20523)
2
+ tags/v1.5.6^0 a10eb0eb4a982c94dbdc31dd302451d6f6b9ac4d
@@ -1,4 +1,14 @@
1
1
  import { PayloadAction } from '@reduxjs/toolkit';
2
- /** It will return a method that only at the very first invocation it will call the retrieverService only the first time, storing the obtained values, and returning always cached values */
3
- declare const useReduxCachedValue: <T extends any[] | Record<string, any>>(entity: string, retrieverService: () => Promise<T>, reduxSelector: (state: any) => T | undefined, reduxSetterAction: (value: T) => PayloadAction<any>, alwaysRetrieve?: boolean | undefined) => () => Promise<T>;
2
+ /** @see {useReduxCachedValue} when there is not RETRIEVER_ARGS and RETRIEVED_VALUE === STORED_VALUE */
3
+ declare const useReduxCachedValue: <RETRIEVED_VALUE extends Record<string, any>>(entity: string, retrieverService: () => Promise<RETRIEVED_VALUE>, reduxSelector: (state: any) => RETRIEVED_VALUE | undefined, reduxSetterAction: (value: RETRIEVED_VALUE) => PayloadAction<any>, selectedValuePredicate2Retrieve?: ((value: RETRIEVED_VALUE) => boolean) | undefined, alwaysRetrieve?: boolean | undefined) => () => Promise<RETRIEVED_VALUE>;
4
+ /** @see {useReduxCachedValueParametricRetrieverTranscoded} when there is not RETRIEVER_ARGS */
5
+ export declare const useReduxCachedValueTranscoded: <RETRIEVED_VALUE, STORED_VALUE>(entity: string, retrieverService: () => Promise<RETRIEVED_VALUE>, reduxSelector: (state: any) => STORED_VALUE | undefined, reduxSetterAction: (value: RETRIEVED_VALUE) => {
6
+ payload: STORED_VALUE;
7
+ type: string;
8
+ }, selectedValue2RetrievedValue: (value: STORED_VALUE) => RETRIEVED_VALUE, selectedValuePredicate2Retrieve?: ((value: STORED_VALUE) => boolean) | undefined, alwaysRetrieve?: boolean | undefined) => () => Promise<RETRIEVED_VALUE>;
9
+ /** 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 */
10
+ export declare const useReduxCachedValueParametricRetrieverTranscoded: <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) => {
11
+ payload: STORED_VALUE;
12
+ type: string;
13
+ }, 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
14
  export default useReduxCachedValue;
@@ -1,39 +1,55 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useReduxCachedValueParametricRetrieverTranscoded = 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
- /** It will return a method that only at the very first invocation it will call the retrieverService only the first time, storing the obtained values, and returning always cached values */
8
- const useReduxCachedValue = (
8
+ /** @see {useReduxCachedValue} when there is not RETRIEVER_ARGS and RETRIEVED_VALUE === STORED_VALUE */
9
+ const useReduxCachedValue = (entity, retrieverService, reduxSelector, reduxSetterAction, selectedValuePredicate2Retrieve, alwaysRetrieve) => useReduxCachedValueParametricRetriever(entity, retrieverService, reduxSelector, reduxSetterAction, selectedValuePredicate2Retrieve, alwaysRetrieve);
10
+ /** @see {useReduxCachedValueParametricRetrieverTranscoded} when RETRIEVED_VALUE === STORED_VALUE */
11
+ const useReduxCachedValueParametricRetriever = (entity, retrieverService, reduxSelector, reduxSetterAction, selectedValuePredicate2Retrieve, alwaysRetrieve) => (0, exports.useReduxCachedValueParametricRetrieverTranscoded)(entity, retrieverService, reduxSelector, reduxSetterAction, (value) => value, selectedValuePredicate2Retrieve, alwaysRetrieve);
12
+ /** @see {useReduxCachedValueParametricRetrieverTranscoded} when there is not RETRIEVER_ARGS */
13
+ const useReduxCachedValueTranscoded = (entity, retrieverService, reduxSelector, reduxSetterAction, selectedValue2RetrievedValue, selectedValuePredicate2Retrieve, alwaysRetrieve) => (0, exports.useReduxCachedValueParametricRetrieverTranscoded)(entity, retrieverService, reduxSelector, reduxSetterAction, selectedValue2RetrievedValue, selectedValuePredicate2Retrieve, alwaysRetrieve);
14
+ exports.useReduxCachedValueTranscoded = useReduxCachedValueTranscoded;
15
+ /** 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 */
16
+ const useReduxCachedValueParametricRetrieverTranscoded = (
9
17
  /** The name of the entity, used just for logging purpose */
10
18
  entity,
11
19
  /** The service that will retrieve the value */
12
20
  retrieverService,
13
- /** The selector to verify if a value already exists */
21
+ /** The selector to read the value from redux */
14
22
  reduxSelector,
15
- /** The action to store the value */
23
+ /** The action to store the new value */
16
24
  reduxSetterAction,
25
+ /** A function called to transform STORED_VALUE into RETRIEVED_VALUE and called when hitting the cache */
26
+ selectedValue2RetrievedValue,
27
+ /** 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 */
28
+ selectedValuePredicate2Retrieve,
17
29
  /** If true, it will always retrieve and store the new value */
18
30
  alwaysRetrieve) => {
19
31
  const dispatch = (0, react_redux_1.useDispatch)();
20
32
  const entities = (0, react_redux_1.useSelector)(reduxSelector);
21
- const setEntities = (value) => dispatch(reduxSetterAction(value));
33
+ const setEntities = (value, retrieverServiceArgs) => dispatch(reduxSetterAction(value, retrieverServiceArgs));
22
34
  const setLoading = (0, useLoading_1.default)(`${constants_1.LOADING_TASK_RETRIEVE_CACHED_VALUES}_${entity}`);
23
- return () => {
24
- if (alwaysRetrieve || !entities) {
35
+ return (retrieverServiceArgs) => {
36
+ if (alwaysRetrieve ||
37
+ !entities ||
38
+ (selectedValuePredicate2Retrieve &&
39
+ selectedValuePredicate2Retrieve(entities, retrieverServiceArgs))) {
25
40
  setLoading(true);
26
- return retrieverService()
41
+ return retrieverService(retrieverServiceArgs)
27
42
  .then((e) => {
28
- setEntities(e);
43
+ setEntities(e, retrieverServiceArgs);
29
44
  return e;
30
45
  })
31
46
  .finally(() => setLoading(false));
32
47
  }
33
48
  else {
34
- return new Promise((resolve) => resolve(entities));
49
+ return new Promise((resolve) => resolve(selectedValue2RetrievedValue(entities, retrieverServiceArgs)));
35
50
  }
36
51
  };
37
52
  };
53
+ exports.useReduxCachedValueParametricRetrieverTranscoded = useReduxCachedValueParametricRetrieverTranscoded;
38
54
  exports.default = useReduxCachedValue;
39
55
  //# sourceMappingURL=useReduxCachedValue.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useReduxCachedValue.js","sourceRoot":"","sources":["../../src/lib/hooks/useReduxCachedValue.tsx"],"names":[],"mappings":";;;AACA,6CAAuD;AACvD,kDAAyE;AACzE,2EAAsC;AAEtC,4LAA4L;AAC5L,MAAM,mBAAmB,GAAG;AAC1B,4DAA4D;AAC5D,MAAc;AACd,+CAA+C;AAC/C,gBAAkC;AAClC,uDAAuD;AACvD,aAA4C;AAC5C,oCAAoC;AACpC,iBAAmD;AACnD,+DAA+D;AAC/D,cAAwB,EACJ,EAAE;IACtB,MAAM,QAAQ,GAAG,IAAA,yBAAW,GAAE,CAAC;IAC/B,MAAM,QAAQ,GAAG,IAAA,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AClE;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;AAlDW,QAAA,gDAAgD,oDAkD3D;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.2",
4
+ "version": "1.5.6",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/pagopa/selfcare-common-frontend",
7
7
  "author": "https://www.pagopa.gov.it",