@pagopa/selfcare-common-frontend 1.5.0 → 1.5.4
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 +46 -12
- package/build.info +2 -2
- package/decorators/withRetrievedValue.d.ts +13 -3
- package/decorators/withRetrievedValue.js +12 -2
- package/decorators/withRetrievedValue.js.map +1 -1
- package/hooks/useReduxCachedValue.d.ts +8 -3
- package/hooks/useReduxCachedValue.js +29 -8
- 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.4](https://github.com/pagopa/selfcare-common-frontend/compare/v1.5.3...v1.5.4)
|
|
8
|
+
|
|
9
|
+
- fixed useReduxCachedValueTranscoded parameters types [`#29`](https://github.com/pagopa/selfcare-common-frontend/pull/29)
|
|
10
|
+
|
|
11
|
+
#### [v1.5.3](https://github.com/pagopa/selfcare-common-frontend/compare/v1.5.2...v1.5.3)
|
|
12
|
+
|
|
13
|
+
> 15 February 2022
|
|
14
|
+
|
|
15
|
+
- added useReduxCachedValueTranscoded [`#28`](https://github.com/pagopa/selfcare-common-frontend/pull/28)
|
|
16
|
+
|
|
17
|
+
#### [v1.5.2](https://github.com/pagopa/selfcare-common-frontend/compare/v1.5.1...v1.5.2)
|
|
18
|
+
|
|
19
|
+
> 14 February 2022
|
|
20
|
+
|
|
21
|
+
- Fixed useReduxCachedValue setterAction type [`#27`](https://github.com/pagopa/selfcare-common-frontend/pull/27)
|
|
22
|
+
- Bump follow-redirects from 1.14.7 to 1.14.8 [`#26`](https://github.com/pagopa/selfcare-common-frontend/pull/26)
|
|
23
|
+
|
|
24
|
+
#### [v1.5.1](https://github.com/pagopa/selfcare-common-frontend/compare/v1.5.0...v1.5.1)
|
|
25
|
+
|
|
26
|
+
> 14 February 2022
|
|
27
|
+
|
|
28
|
+
- withRetrievedValue will accept a component to show while loading [`#25`](https://github.com/pagopa/selfcare-common-frontend/pull/25)
|
|
29
|
+
|
|
7
30
|
#### [v1.5.0](https://github.com/pagopa/selfcare-common-frontend/compare/v1.4.1...v1.5.0)
|
|
8
31
|
|
|
32
|
+
> 11 February 2022
|
|
33
|
+
|
|
9
34
|
- Toast autoclosable in UserNotifyHandle and ErrorBoundaryfeatures [`#24`](https://github.com/pagopa/selfcare-common-frontend/pull/24)
|
|
10
35
|
- Customhook cached redux [`#23`](https://github.com/pagopa/selfcare-common-frontend/pull/23)
|
|
11
36
|
- fixed readme [`#22`](https://github.com/pagopa/selfcare-common-frontend/pull/22)
|
package/README.md
CHANGED
|
@@ -57,16 +57,16 @@ Modal used to show a list of values from which to choose a single value
|
|
|
57
57
|
| Prop | Type | Mandatory | Description |
|
|
58
58
|
|------|------|-----------|-------------|
|
|
59
59
|
| open | boolean | Y | If the popup is to be displayed |
|
|
60
|
-
| handleClose | React.MouseEventHandler
|
|
60
|
+
| handleClose | React.MouseEventHandler`<HTMLButtonElement>` | Y | The function to be invoked when clicking on exit button or selecting a value |
|
|
61
61
|
| title | string | Y | The popup title |
|
|
62
|
-
| filterModalConfig | FilterModalConfig
|
|
62
|
+
| filterModalConfig | FilterModalConfig`<any, any>` | N | See below |
|
|
63
63
|
| height | string | N | The popup height |
|
|
64
64
|
| minHeight | string | N | The popup minHeight |
|
|
65
65
|
|
|
66
66
|
FilterModalConfig fields:
|
|
67
67
|
| Field | Type | Mandatory | Description |
|
|
68
68
|
|-------|------|-----------|-------------|
|
|
69
|
-
| data | Array
|
|
69
|
+
| data | Array`<T>` | Y | The list of values between to which choose |
|
|
70
70
|
| getLabel | (e: T) => string | Y | A function that will select the label to show |
|
|
71
71
|
| getValue | (e: T) => string | Y | A function that will select the value to return when selecting an item |
|
|
72
72
|
| onFilterChange | (v: V) => void | Y | The function invoked when selecting a value |
|
|
@@ -79,10 +79,10 @@ Selfcare's popup
|
|
|
79
79
|
| open | boolean | Y | If this component should be displayed or not |
|
|
80
80
|
| title | string | Y | The title to show in the popup |
|
|
81
81
|
| message | React.ReactNode | Y | The body to show in the popup |
|
|
82
|
-
| onConfirm | React.MouseEventHandler
|
|
82
|
+
| onConfirm | React.MouseEventHandler`<HTMLButtonElement>` | N | If defined, it will render a confirm button using this function as behavior |
|
|
83
83
|
| onConfirmLabel | string | N | The confirm label text |
|
|
84
|
-
| handleClose | React.MouseEventHandler
|
|
85
|
-
| handleExit | React.MouseEventHandler
|
|
84
|
+
| handleClose | React.MouseEventHandler`<HTMLButtonElement>` | Y | The function invoked when clicking on close button or in the showed X icon |
|
|
85
|
+
| handleExit | React.MouseEventHandler`<HTMLButtonElement>` | N | If defined, it allow to set a different behavior when clicking on X icon |
|
|
86
86
|
| onCloseLabel | string | N | Close button text |
|
|
87
87
|
| height | string | N | The popup height |
|
|
88
88
|
| minHeight | string | N | The popup minHeight |
|
|
@@ -132,7 +132,7 @@ To show an error popup to inform of the not valid session
|
|
|
132
132
|
### buildFetchApi = (timeoutMs: number = 300000) => fetch
|
|
133
133
|
Return the implementation of fetch configured with a timeout
|
|
134
134
|
|
|
135
|
-
### extractResponse
|
|
135
|
+
### extractResponse `<R>`(response: t.Validation`<TypeofApiResponse<any>>`, successHttpStatus: number, onRedirectToLogin: () => void, notValidTokenHttpStatus: number | null = 401, notAuthorizedTokenHttpStatus: number | null = 403, emptyResponseHttpStatus: number | null = 404): Promise`<R>`
|
|
136
136
|
Extract the response of a @pagopa/openapi-codegen-ts generated client rest invocation having status code successHttpStatus.
|
|
137
137
|
If notValidTokenHttpStatus is not null and the returned status is equal to notValidTokenHttpStatus, it will call the onRedirectToLogin function and will schedule the redirect towards logout path.
|
|
138
138
|
If notAuthorizedTokenHttpStatus is not null and the returned status is equal to notAuthorizedTokenHttpStatus, it will throw an Error with message "Operation not allowed".
|
|
@@ -179,8 +179,23 @@ It's possible to modify the login path changing the value in [CONFIG.URL_FE.LOGI
|
|
|
179
179
|
|
|
180
180
|
## withRetrievedValue
|
|
181
181
|
Decorator to retrieve a value and serve it once ready to the decorated component.
|
|
182
|
-
|
|
183
|
-
See withRetrievedValue.test.tsx file for an
|
|
182
|
+
Using it together with [useReduxCachedValue](#usereduxcachedvalue) will allow to build a component which will use centralized and cached data
|
|
183
|
+
See withRetrievedValue.test.tsx file for an example.
|
|
184
|
+
|
|
185
|
+
Given the following type parameters:
|
|
186
|
+
* ENTITY_TYPE extends Record`<string, any>`,
|
|
187
|
+
* PROP_NAME extends string,
|
|
188
|
+
* PROPS extends Record`<PROP_NAME, ENTITY_TYPE>`
|
|
189
|
+
|
|
190
|
+
The arguments to provide to the decorator are the following:
|
|
191
|
+
|
|
192
|
+
| Prop | Type | Mandatory | Description |
|
|
193
|
+
|------|------|-----------|-------------|
|
|
194
|
+
| propEntityName | PROP_NAME | Y | The name of the prop to which serve the value when available |
|
|
195
|
+
| getRetrieverService | () => () => Promise`<ENTITY_TYPE>` | Y | A function that will return an other function to retrieve the expected value. This for allow the use of custom hook |
|
|
196
|
+
| WrappedComponent | React.ComponentType`<PROPS>` | Y | The component to decore |
|
|
197
|
+
| onError | (appError: AppError) => void | N | What to do in case of error. As default, it will use the feature ErrorBoundary |
|
|
198
|
+
| onLoading | ReactNode | N | A component to show while waiting for the value |
|
|
184
199
|
|
|
185
200
|
# Custom Hooks
|
|
186
201
|
## useFakePagination
|
|
@@ -189,8 +204,27 @@ Cached values are stored using useRef, so they are local to the component using
|
|
|
189
204
|
The sorting actually is applied using string representation
|
|
190
205
|
|
|
191
206
|
## useReduxCachedValue
|
|
192
|
-
|
|
193
|
-
|
|
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.
|
|
211
|
+
See useReduxCachedValue.test.tsx file for an example.
|
|
212
|
+
|
|
213
|
+
Given the following type parametes:
|
|
214
|
+
* RETRIEVED_VALUE the type desired
|
|
215
|
+
* STORED_VALUE the type stored
|
|
216
|
+
|
|
217
|
+
The arguments to provide to the custom hook are the following:
|
|
218
|
+
|
|
219
|
+
| Prop | Type | Mandatory | Description |
|
|
220
|
+
|------|------|-----------|-------------|
|
|
221
|
+
| entity | string | Y | The name of the entity, used just for logging purpose |
|
|
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) => 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 |
|
|
227
|
+
| alwaysRetrieve | boolean | N | If true, it will always retrieve and store the new value |
|
|
194
228
|
|
|
195
229
|
# Features
|
|
196
230
|
## LoadingOverlay
|
|
@@ -285,7 +319,7 @@ This feature can be configured with the following keys of the [CONFIG](#Configur
|
|
|
285
319
|
| PERSISTENCE | string | Where to store session data, possible values are cookie or localStorage | localStorage |
|
|
286
320
|
| LOG_IP | boolean | If the ip should be sent | false |
|
|
287
321
|
| LOG_IP | boolean | If the ip should be sent | false |
|
|
288
|
-
| PROPERTY_BLACKLIST | Array
|
|
322
|
+
| PROPERTY_BLACKLIST | Array`<string>` | If the ip should be sent | ["$current_url", "$initial_referrer", "$referrer"] |
|
|
289
323
|
| ADDITIONAL_PROPERTIES | {[key: string]: string} | An object containing a fixed set of properties to send every time, overridden if the actual event will report the same properties | {} |
|
|
290
324
|
| ADDITIONAL_PROPERTIES_IMPORTANT | {[key: string]: string} | As ADDITIONAL_PROPERTIES, but these properties will take the precedence overriding events conflicting properties | {} |
|
|
291
325
|
|
package/build.info
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
tags/v1.5.
|
|
1
|
+
20220215.2 - selfcare-common-frontend.deploy(20504)
|
|
2
|
+
tags/v1.5.4^0 032705d5c019bf056fddfc1d2caf72cf8ed4db64
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import { AppError } from '../
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { AppError } from '../model/AppError';
|
|
3
3
|
/** Decorator to retrieve a value and serve it once ready to the decorated component */
|
|
4
|
-
export default function withRetrievedValue<ENTITY_TYPE extends Record<string, any>, PROP_NAME extends string, PROPS extends Record<PROP_NAME, ENTITY_TYPE>>(
|
|
4
|
+
export default function withRetrievedValue<ENTITY_TYPE extends Record<string, any>, PROP_NAME extends string, PROPS extends Record<PROP_NAME, ENTITY_TYPE>>(
|
|
5
|
+
/** The name of the prop to which serve the value when available */
|
|
6
|
+
propEntityName: PROP_NAME,
|
|
7
|
+
/** A function that will return an other function to retrieve the expected value. This for allow the use of custom hook */
|
|
8
|
+
getRetrieverService: () => () => Promise<ENTITY_TYPE>,
|
|
9
|
+
/** The component to decore */
|
|
10
|
+
WrappedComponent: React.ComponentType<PROPS>,
|
|
11
|
+
/** What to do in case of error. As default, it will use the feature ErrorBoundary */
|
|
12
|
+
onError?: (appError: AppError) => void,
|
|
13
|
+
/** A component to show while waiting for the value */
|
|
14
|
+
onLoading?: ReactNode): import("react").ComponentType<Omit<PROPS, PROP_NAME>>;
|
|
@@ -5,7 +5,17 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const useErrorDispatcher_1 = (0, tslib_1.__importDefault)(require("../hooks/useErrorDispatcher"));
|
|
7
7
|
/** Decorator to retrieve a value and serve it once ready to the decorated component */
|
|
8
|
-
function withRetrievedValue(
|
|
8
|
+
function withRetrievedValue(
|
|
9
|
+
/** The name of the prop to which serve the value when available */
|
|
10
|
+
propEntityName,
|
|
11
|
+
/** A function that will return an other function to retrieve the expected value. This for allow the use of custom hook */
|
|
12
|
+
getRetrieverService,
|
|
13
|
+
/** The component to decore */
|
|
14
|
+
WrappedComponent,
|
|
15
|
+
/** What to do in case of error. As default, it will use the feature ErrorBoundary */
|
|
16
|
+
onError,
|
|
17
|
+
/** A component to show while waiting for the value */
|
|
18
|
+
onLoading) {
|
|
9
19
|
const displayName = WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
|
10
20
|
const ComponentWithParties = (props) => {
|
|
11
21
|
const [value, setValue] = (0, react_1.useState)();
|
|
@@ -28,7 +38,7 @@ function withRetrievedValue(propEntityName, getRetrieverService, WrappedComponen
|
|
|
28
38
|
doRetrieve();
|
|
29
39
|
}
|
|
30
40
|
}, []);
|
|
31
|
-
return
|
|
41
|
+
return value !== undefined ? ((0, jsx_runtime_1.jsx)(WrappedComponent, Object.assign({}, props, { [propEntityName]: value }), void 0)) : (onLoading !== null && onLoading !== void 0 ? onLoading : (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}, void 0));
|
|
32
42
|
};
|
|
33
43
|
// eslint-disable-next-line functional/immutable-data
|
|
34
44
|
ComponentWithParties.displayName = `withRetrieve${propEntityName}(${displayName})`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withRetrievedValue.js","sourceRoot":"","sources":["../../src/lib/decorators/withRetrievedValue.tsx"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"withRetrievedValue.js","sourceRoot":"","sources":["../../src/lib/decorators/withRetrievedValue.tsx"],"names":[],"mappings":";;;;AAAA,iCAAuD;AACvD,kGAA6D;AAG7D,uFAAuF;AACvF,SAAwB,kBAAkB;AAKxC,mEAAmE;AACnE,cAAyB;AACzB,2HAA2H;AAC3H,mBAAqD;AACrD,8BAA8B;AAC9B,gBAA4C;AAC5C,qFAAqF;AACrF,OAAsC;AACtC,sDAAsD;AACtD,SAAqB;IAErB,MAAM,WAAW,GAAG,gBAAgB,CAAC,WAAW,IAAI,gBAAgB,CAAC,IAAI,IAAI,WAAW,CAAC;IAEzF,MAAM,oBAAoB,GAAG,CAAC,KAAY,EAAE,EAAE;QAC5C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,GAAe,CAAC;QAClD,MAAM,cAAc,GAAG,mBAAmB,EAAE,CAAC;QAE7C,MAAM,QAAQ,GAAG,IAAA,4BAAkB,GAAE,CAAC;QAEtC,MAAM,UAAU,GAAG,GAAS,EAAE;YAC5B,cAAc,EAAE;iBACb,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;iBACxB,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAChB,CAAC,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,QAAQ,CAAC,CAAC;gBACpB,EAAE,EAAE,kBAAkB,cAAc,EAAE;gBACtC,QAAQ,EAAE,KAAK;gBACf,eAAe,EAAE,yCAAyC,cAAc,EAAE;gBAC1E,QAAQ,EAAE,IAAI;gBACd,KAAK,EAAE,MAAM;gBACb,OAAO,EAAE,UAAU;aACpB,CAAC,CACH,CAAC;QACN,CAAC,CAAC;QAEF,IAAA,iBAAS,EAAC,GAAG,EAAE;YACb,IAAI,CAAC,KAAK,EAAE;gBACV,UAAU,EAAE,CAAC;aACd;QACH,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,CAC3B,uBAAC,gBAAgB,oBAAM,KAAe,EAAM,EAAE,CAAC,cAAc,CAAC,EAAE,KAAK,EAAE,UAAI,CAC5E,CAAC,CAAC,CAAC,CACF,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,0DAAK,CACnB,CAAC;IACJ,CAAC,CAAC;IAEF,qDAAqD;IACrD,oBAAoB,CAAC,WAAW,GAAG,eAAe,cAAc,IAAI,WAAW,GAAG,CAAC;IAEnF,OAAO,oBAAmE,CAAC;AAC7E,CAAC;AAxDD,qCAwDC"}
|
|
@@ -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) => 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,29 +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 = (entity, retrieverService, reduxSelector, reduxSetterAction, alwaysRetrieve) =>
|
|
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 = (
|
|
12
|
+
/** The name of the entity, used just for logging purpose */
|
|
13
|
+
entity,
|
|
14
|
+
/** The service that will retrieve the value */
|
|
15
|
+
retrieverService,
|
|
16
|
+
/** The selector to read the value from redux */
|
|
17
|
+
reduxSelector,
|
|
18
|
+
/** The action to store the new value */
|
|
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,
|
|
24
|
+
/** If true, it will always retrieve and store the new value */
|
|
25
|
+
alwaysRetrieve) => {
|
|
9
26
|
const dispatch = (0, react_redux_1.useDispatch)();
|
|
10
27
|
const entities = (0, react_redux_1.useSelector)(reduxSelector);
|
|
11
|
-
const setEntities = (value) => dispatch(reduxSetterAction(value));
|
|
28
|
+
const setEntities = (value, retrieverServiceArgs) => dispatch(reduxSetterAction(value, retrieverServiceArgs));
|
|
12
29
|
const setLoading = (0, useLoading_1.default)(`${constants_1.LOADING_TASK_RETRIEVE_CACHED_VALUES}_${entity}`);
|
|
13
|
-
return () => {
|
|
14
|
-
if (alwaysRetrieve ||
|
|
30
|
+
return (retrieverServiceArgs) => {
|
|
31
|
+
if (alwaysRetrieve ||
|
|
32
|
+
!entities ||
|
|
33
|
+
(selectedValuePredicate2Retrieve &&
|
|
34
|
+
selectedValuePredicate2Retrieve(entities, retrieverServiceArgs))) {
|
|
15
35
|
setLoading(true);
|
|
16
|
-
return retrieverService()
|
|
36
|
+
return retrieverService(retrieverServiceArgs)
|
|
17
37
|
.then((e) => {
|
|
18
|
-
setEntities(e);
|
|
38
|
+
setEntities(e, retrieverServiceArgs);
|
|
19
39
|
return e;
|
|
20
40
|
})
|
|
21
41
|
.finally(() => setLoading(false));
|
|
22
42
|
}
|
|
23
43
|
else {
|
|
24
|
-
return new Promise((resolve) => resolve(entities));
|
|
44
|
+
return new Promise((resolve) => resolve(selectedValue2RetrievedValue(entities)));
|
|
25
45
|
}
|
|
26
46
|
};
|
|
27
47
|
};
|
|
48
|
+
exports.useReduxCachedValueTranscoded = useReduxCachedValueTranscoded;
|
|
28
49
|
exports.default = useReduxCachedValue;
|
|
29
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,4BAAsE;AACtE,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,CAAC,OAAO,CAAC,4BAA4B,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;SAClF;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AA5CW,QAAA,6BAA6B,iCA4CxC;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.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/pagopa/selfcare-common-frontend",
|
|
7
7
|
"author": "https://www.pagopa.gov.it",
|