@bigbinary/neeto-commons-frontend 2.0.121 → 2.0.123
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/README.md +1 -0
- package/cypress-utils.cjs.js +2 -0
- package/cypress-utils.cjs.js.map +1 -1
- package/cypress-utils.js +2 -0
- package/cypress-utils.js.map +1 -1
- package/package.json +1 -1
- package/react-utils.cjs.js +32 -10
- package/react-utils.cjs.js.map +1 -1
- package/react-utils.d.ts +50 -2
- package/react-utils.js +33 -12
- package/react-utils.js.map +1 -1
package/react-utils.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { RouteProps } from "react-router-dom";
|
|
|
3
3
|
import { Notice } from "@honeybadger-io/js/dist/server/types/core/types";
|
|
4
4
|
import { History } from "history";
|
|
5
5
|
import { StoreApi, UseBoundStore } from "zustand";
|
|
6
|
-
import { UseQueryOptions, UseQueryResult } from "react-query";
|
|
6
|
+
import { UseQueryOptions, UseQueryResult, UseMutationOptions, UseMutationResult } from "react-query";
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
9
9
|
* ErrorBoundary which reports frontend errors to HoneyBadger
|
|
@@ -763,4 +763,52 @@ export const withT: <Props extends {
|
|
|
763
763
|
[key: string]: any;
|
|
764
764
|
}>(Component: React.ComponentType<Props & {
|
|
765
765
|
t: TFunction;
|
|
766
|
-
}>) => React.ComponentType<Props>;
|
|
766
|
+
}>) => React.ComponentType<Props>;
|
|
767
|
+
/**
|
|
768
|
+
*
|
|
769
|
+
* useMutationWithInvalidation is a wrapper function around the useMutation
|
|
770
|
+
*
|
|
771
|
+
* hook from react-query. It returns all the props from the useMutation hook and
|
|
772
|
+
*
|
|
773
|
+
* additionally, invalidates a list of query keys on mutation success.
|
|
774
|
+
*
|
|
775
|
+
* @example
|
|
776
|
+
*
|
|
777
|
+
* // useQuestionsApi
|
|
778
|
+
* //Invalidate any query with query key starting with "QUESTIONS"
|
|
779
|
+
* const useUpdateQuestions = () =>
|
|
780
|
+
* useMutationWithInvalidation(questionsApi.update, {
|
|
781
|
+
* keysToInvalidate: ["QUESTIONS"],
|
|
782
|
+
* onSuccess: data => queryClient.setQueryData(["RESPONSES"], data),
|
|
783
|
+
* });
|
|
784
|
+
*
|
|
785
|
+
* //Invalidate any query with query key starting with ["FORM", "QUESTIONS"]
|
|
786
|
+
* const useUpdateQuestions = options =>
|
|
787
|
+
* useMutationWithInvalidation(questionsApi.update, {
|
|
788
|
+
* keysToInvalidate: [["FORM", "QUESTIONS"]],
|
|
789
|
+
* ...options,
|
|
790
|
+
* });
|
|
791
|
+
*
|
|
792
|
+
* //Invalidate any query with query key starting with "FORM" or starting with "QUESTIONS"
|
|
793
|
+
* const useUpdateQuestions = options =>
|
|
794
|
+
* useMutationWithInvalidation(questionsApi.update, {
|
|
795
|
+
* keysToInvalidate: ["FORM", "QUESTIONS"],
|
|
796
|
+
* ...options,
|
|
797
|
+
* });
|
|
798
|
+
*
|
|
799
|
+
* //Invalidate any query with query key starting with ["QUESTION", id]
|
|
800
|
+
* const useUpdateQuestions = options =>
|
|
801
|
+
* useMutationWithInvalidation(questionsApi.update, {
|
|
802
|
+
* keysToInvalidate: [(_, { id }) => ["QUESTION", id]],
|
|
803
|
+
* ...options,
|
|
804
|
+
* });
|
|
805
|
+
*
|
|
806
|
+
* // Update question component
|
|
807
|
+
* const { mutate: updateQuestions, isLoading } = useUpdateQuestions({
|
|
808
|
+
* onError: e => logger.error(e),
|
|
809
|
+
* });
|
|
810
|
+
* @endexample
|
|
811
|
+
*/
|
|
812
|
+
export function useMutationWithInvalidation(mutationFn: () => Promise<T>, options: {
|
|
813
|
+
keysToInvalidate: Array<string | string[] | (() => string | string[])>;
|
|
814
|
+
} & UseMutationOptions): UseMutationResult<T>;
|
package/react-utils.js
CHANGED
|
@@ -7,7 +7,7 @@ import { useTranslation, Trans, withTranslation } from 'react-i18next';
|
|
|
7
7
|
import ErrorPage from '@bigbinary/neeto-molecules/ErrorPage';
|
|
8
8
|
import { Route, Redirect } from 'react-router-dom';
|
|
9
9
|
import axios from 'axios';
|
|
10
|
-
import { useQuery } from 'react-query';
|
|
10
|
+
import { useQuery, useQueryClient, useMutation } from 'react-query';
|
|
11
11
|
import { Helmet } from 'react-helmet';
|
|
12
12
|
|
|
13
13
|
var _path, _path2, _path3, _path4, _path5, _path6;
|
|
@@ -155,7 +155,7 @@ function _objectWithoutProperties(source, excluded) {
|
|
|
155
155
|
return target;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
var _excluded = ["condition", "redirectRoute", "errorPage", "permissions"];
|
|
158
|
+
var _excluded$1 = ["condition", "redirectRoute", "errorPage", "permissions"];
|
|
159
159
|
var PrivateRoute = function PrivateRoute(_ref) {
|
|
160
160
|
var _ref$condition = _ref.condition,
|
|
161
161
|
condition = _ref$condition === void 0 ? globalProps.authenticated : _ref$condition,
|
|
@@ -165,7 +165,7 @@ var PrivateRoute = function PrivateRoute(_ref) {
|
|
|
165
165
|
errorPage = _ref$errorPage === void 0 ? undefined : _ref$errorPage,
|
|
166
166
|
_ref$permissions = _ref.permissions,
|
|
167
167
|
permissions = _ref$permissions === void 0 ? undefined : _ref$permissions,
|
|
168
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
168
|
+
props = _objectWithoutProperties(_ref, _excluded$1);
|
|
169
169
|
if (condition) {
|
|
170
170
|
if (permissions) {
|
|
171
171
|
return globalProps.permissions.some(includes(__, permissions)) ? /*#__PURE__*/React__default.createElement(Route, props) : errorPage || /*#__PURE__*/React__default.createElement(ErrorPage, {
|
|
@@ -241,12 +241,12 @@ var QUERY_KEYS = {
|
|
|
241
241
|
var QUERY_CACHE_NAME_SPACE = "queryCache";
|
|
242
242
|
var NEETO_APPS_LIST_STALE_TIME = 30 * 24 * 60 * 60 * 1000; // 30 days
|
|
243
243
|
|
|
244
|
-
function ownKeys$
|
|
245
|
-
function _objectSpread$
|
|
244
|
+
function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
245
|
+
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$2(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
246
246
|
var localStorageQueryCache = {
|
|
247
247
|
set: function set(key, data) {
|
|
248
248
|
var cache = localStorageQueryCache.getAll();
|
|
249
|
-
var newCache = _objectSpread$
|
|
249
|
+
var newCache = _objectSpread$2(_objectSpread$2({}, cache), {}, _defineProperty({}, key, {
|
|
250
250
|
data: data,
|
|
251
251
|
modifiedAt: Date.now()
|
|
252
252
|
}));
|
|
@@ -274,20 +274,20 @@ var usePersistedQuery = function usePersistedQuery(queryKey, fetch, options) {
|
|
|
274
274
|
localStorageQueryCache.set(queryKey, queryResult.data);
|
|
275
275
|
}, [queryKey, queryResult.data, queryResult.isSuccess]);
|
|
276
276
|
if (isOutdated(localCache, options === null || options === void 0 ? void 0 : options.staleTime)) {
|
|
277
|
-
return _objectSpread$
|
|
277
|
+
return _objectSpread$2(_objectSpread$2({}, queryResult), {}, {
|
|
278
278
|
isFreshLoading: queryResult.isLoading
|
|
279
279
|
});
|
|
280
280
|
}
|
|
281
|
-
return _objectSpread$
|
|
281
|
+
return _objectSpread$2(_objectSpread$2({}, queryResult), {}, {
|
|
282
282
|
data: queryResult.data || localCache.data,
|
|
283
283
|
isFreshLoading: false
|
|
284
284
|
});
|
|
285
285
|
};
|
|
286
286
|
|
|
287
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
288
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
287
|
+
function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
288
|
+
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
289
289
|
var useFetchNeetoApps = function useFetchNeetoApps(options) {
|
|
290
|
-
return usePersistedQuery(QUERY_KEYS.NEETO_APPS_LIST, neetoAppsApi.fetch, _objectSpread({
|
|
290
|
+
return usePersistedQuery(QUERY_KEYS.NEETO_APPS_LIST, neetoAppsApi.fetch, _objectSpread$1({
|
|
291
291
|
staleTime: NEETO_APPS_LIST_STALE_TIME
|
|
292
292
|
}, options));
|
|
293
293
|
};
|
|
@@ -3540,6 +3540,27 @@ var useLocalStorage = function useLocalStorage(key, defaultValue) {
|
|
|
3540
3540
|
return [storedValue, setValue];
|
|
3541
3541
|
};
|
|
3542
3542
|
|
|
3543
|
+
var _excluded = ["keysToInvalidate"],
|
|
3544
|
+
_excluded2 = ["onSuccess"];
|
|
3545
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3546
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3547
|
+
var useMutationWithInvalidation = function useMutationWithInvalidation(mutationFn, _ref) {
|
|
3548
|
+
var keysToInvalidate = _ref.keysToInvalidate,
|
|
3549
|
+
options = _objectWithoutProperties(_ref, _excluded);
|
|
3550
|
+
var queryClient = useQueryClient();
|
|
3551
|
+
var _onSuccess = options.onSuccess,
|
|
3552
|
+
otherOptions = _objectWithoutProperties(options, _excluded2);
|
|
3553
|
+
return useMutation(mutationFn, _objectSpread({
|
|
3554
|
+
onSuccess: function onSuccess(data, variables, context) {
|
|
3555
|
+
keysToInvalidate.forEach(function (key) {
|
|
3556
|
+
var keyToInvalidate = typeof key === "function" ? key(data, variables, context) : key;
|
|
3557
|
+
queryClient.invalidateQueries(keyToInvalidate);
|
|
3558
|
+
});
|
|
3559
|
+
_onSuccess === null || _onSuccess === void 0 ? void 0 : _onSuccess(data, variables, context);
|
|
3560
|
+
}
|
|
3561
|
+
}, otherOptions));
|
|
3562
|
+
};
|
|
3563
|
+
|
|
3543
3564
|
var useOnClickOutside = function useOnClickOutside(ref, handler) {
|
|
3544
3565
|
useEffect(function () {
|
|
3545
3566
|
var listener = function listener(event) {
|
|
@@ -4788,5 +4809,5 @@ var useUpdateEffect = function useUpdateEffect(callback) {
|
|
|
4788
4809
|
}, dependencies);
|
|
4789
4810
|
};
|
|
4790
4811
|
|
|
4791
|
-
export { HoneybadgerErrorBoundary, PrivateRoute, destroyBrowserSubscription, handleMetaClick, isMetaKeyPressed, registerBrowserNotifications, useDebounce, useDisplayErrorPage, useErrorDisplayStore, useFetchNeetoApps, useFuncDebounce, useHotKeys, useIsElementVisibleInDom, useKeyboardShortcutsPaneState, useLocalStorage, useNavigationCheckpoints, useOnClickOutside, usePersistedQuery, usePrevious, useRegisterNavigationCheckpoint, useStateWithDependency, useTimer, useUpdateEffect, withImmutableActions, withT, withTitle };
|
|
4812
|
+
export { HoneybadgerErrorBoundary, PrivateRoute, destroyBrowserSubscription, handleMetaClick, isMetaKeyPressed, registerBrowserNotifications, useDebounce, useDisplayErrorPage, useErrorDisplayStore, useFetchNeetoApps, useFuncDebounce, useHotKeys, useIsElementVisibleInDom, useKeyboardShortcutsPaneState, useLocalStorage, useMutationWithInvalidation, useNavigationCheckpoints, useOnClickOutside, usePersistedQuery, usePrevious, useRegisterNavigationCheckpoint, useStateWithDependency, useTimer, useUpdateEffect, withImmutableActions, withT, withTitle };
|
|
4792
4813
|
//# sourceMappingURL=react-utils.js.map
|