@bigbinary/neeto-commons-frontend 2.0.122 → 2.0.124
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/initializers.cjs.js +1 -3
- package/initializers.cjs.js.map +1 -1
- package/initializers.js +1 -3
- package/initializers.js.map +1 -1
- package/package.json +1 -1
- package/react-utils.cjs.js +34 -14
- package/react-utils.cjs.js.map +1 -1
- package/react-utils.d.ts +50 -2
- package/react-utils.js +35 -16
- 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;
|
|
@@ -67,7 +67,7 @@ var FallbackComponent = function FallbackComponent() {
|
|
|
67
67
|
style: "h2",
|
|
68
68
|
weight: "semibold"
|
|
69
69
|
}, t("neetoCommons.fallbackComponent.somethingWentWrong")), /*#__PURE__*/React__default.createElement(Typography, {
|
|
70
|
-
className: "
|
|
70
|
+
className: "neeto-ui-text-gray-600 mb-8",
|
|
71
71
|
component: "p",
|
|
72
72
|
style: "body1",
|
|
73
73
|
weight: "normal"
|
|
@@ -76,14 +76,12 @@ var FallbackComponent = function FallbackComponent() {
|
|
|
76
76
|
components: {
|
|
77
77
|
reloading: /*#__PURE__*/React__default.createElement(Button, {
|
|
78
78
|
style: "link",
|
|
79
|
-
label: t("neetoCommons.fallbackComponent.reloadingButtonLabel"),
|
|
80
79
|
onClick: function onClick() {
|
|
81
80
|
return window.location.reload();
|
|
82
81
|
}
|
|
83
82
|
}),
|
|
84
83
|
contactus: /*#__PURE__*/React__default.createElement(Button, {
|
|
85
84
|
style: "link",
|
|
86
|
-
label: t("neetoCommons.fallbackComponent.contactusButtonLabel"),
|
|
87
85
|
onClick: function onClick() {
|
|
88
86
|
var _window$NeetoChat, _window$NeetoChat$con, _window$NeetoChat2, _window$NeetoChat2$co;
|
|
89
87
|
(_window$NeetoChat = window.NeetoChat) === null || _window$NeetoChat === void 0 ? void 0 : (_window$NeetoChat$con = _window$NeetoChat.contextualHelp) === null || _window$NeetoChat$con === void 0 ? void 0 : _window$NeetoChat$con.maximizeWidget();
|
|
@@ -93,7 +91,7 @@ var FallbackComponent = function FallbackComponent() {
|
|
|
93
91
|
}
|
|
94
92
|
}))));
|
|
95
93
|
};
|
|
96
|
-
var ignorableErrorsRegex = /(window\.requestAnimationFrame|ResizeObserver|ChunkLoadError)/;
|
|
94
|
+
var ignorableErrorsRegex = /(window\.requestAnimationFrame|ResizeObserver|ChunkLoadError|window\.webkit\.messageHandlers)/;
|
|
97
95
|
var HoneybadgerErrorBoundary = function HoneybadgerErrorBoundary(_ref) {
|
|
98
96
|
var children = _ref.children,
|
|
99
97
|
_ref$ErrorComponent = _ref.ErrorComponent,
|
|
@@ -155,7 +153,7 @@ function _objectWithoutProperties(source, excluded) {
|
|
|
155
153
|
return target;
|
|
156
154
|
}
|
|
157
155
|
|
|
158
|
-
var _excluded = ["condition", "redirectRoute", "errorPage", "permissions"];
|
|
156
|
+
var _excluded$1 = ["condition", "redirectRoute", "errorPage", "permissions"];
|
|
159
157
|
var PrivateRoute = function PrivateRoute(_ref) {
|
|
160
158
|
var _ref$condition = _ref.condition,
|
|
161
159
|
condition = _ref$condition === void 0 ? globalProps.authenticated : _ref$condition,
|
|
@@ -165,7 +163,7 @@ var PrivateRoute = function PrivateRoute(_ref) {
|
|
|
165
163
|
errorPage = _ref$errorPage === void 0 ? undefined : _ref$errorPage,
|
|
166
164
|
_ref$permissions = _ref.permissions,
|
|
167
165
|
permissions = _ref$permissions === void 0 ? undefined : _ref$permissions,
|
|
168
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
166
|
+
props = _objectWithoutProperties(_ref, _excluded$1);
|
|
169
167
|
if (condition) {
|
|
170
168
|
if (permissions) {
|
|
171
169
|
return globalProps.permissions.some(includes(__, permissions)) ? /*#__PURE__*/React__default.createElement(Route, props) : errorPage || /*#__PURE__*/React__default.createElement(ErrorPage, {
|
|
@@ -241,12 +239,12 @@ var QUERY_KEYS = {
|
|
|
241
239
|
var QUERY_CACHE_NAME_SPACE = "queryCache";
|
|
242
240
|
var NEETO_APPS_LIST_STALE_TIME = 30 * 24 * 60 * 60 * 1000; // 30 days
|
|
243
241
|
|
|
244
|
-
function ownKeys$
|
|
245
|
-
function _objectSpread$
|
|
242
|
+
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; }
|
|
243
|
+
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
244
|
var localStorageQueryCache = {
|
|
247
245
|
set: function set(key, data) {
|
|
248
246
|
var cache = localStorageQueryCache.getAll();
|
|
249
|
-
var newCache = _objectSpread$
|
|
247
|
+
var newCache = _objectSpread$2(_objectSpread$2({}, cache), {}, _defineProperty({}, key, {
|
|
250
248
|
data: data,
|
|
251
249
|
modifiedAt: Date.now()
|
|
252
250
|
}));
|
|
@@ -274,20 +272,20 @@ var usePersistedQuery = function usePersistedQuery(queryKey, fetch, options) {
|
|
|
274
272
|
localStorageQueryCache.set(queryKey, queryResult.data);
|
|
275
273
|
}, [queryKey, queryResult.data, queryResult.isSuccess]);
|
|
276
274
|
if (isOutdated(localCache, options === null || options === void 0 ? void 0 : options.staleTime)) {
|
|
277
|
-
return _objectSpread$
|
|
275
|
+
return _objectSpread$2(_objectSpread$2({}, queryResult), {}, {
|
|
278
276
|
isFreshLoading: queryResult.isLoading
|
|
279
277
|
});
|
|
280
278
|
}
|
|
281
|
-
return _objectSpread$
|
|
279
|
+
return _objectSpread$2(_objectSpread$2({}, queryResult), {}, {
|
|
282
280
|
data: queryResult.data || localCache.data,
|
|
283
281
|
isFreshLoading: false
|
|
284
282
|
});
|
|
285
283
|
};
|
|
286
284
|
|
|
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; }
|
|
285
|
+
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; }
|
|
286
|
+
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
287
|
var useFetchNeetoApps = function useFetchNeetoApps(options) {
|
|
290
|
-
return usePersistedQuery(QUERY_KEYS.NEETO_APPS_LIST, neetoAppsApi.fetch, _objectSpread({
|
|
288
|
+
return usePersistedQuery(QUERY_KEYS.NEETO_APPS_LIST, neetoAppsApi.fetch, _objectSpread$1({
|
|
291
289
|
staleTime: NEETO_APPS_LIST_STALE_TIME
|
|
292
290
|
}, options));
|
|
293
291
|
};
|
|
@@ -3540,6 +3538,27 @@ var useLocalStorage = function useLocalStorage(key, defaultValue) {
|
|
|
3540
3538
|
return [storedValue, setValue];
|
|
3541
3539
|
};
|
|
3542
3540
|
|
|
3541
|
+
var _excluded = ["keysToInvalidate"],
|
|
3542
|
+
_excluded2 = ["onSuccess"];
|
|
3543
|
+
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; }
|
|
3544
|
+
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; }
|
|
3545
|
+
var useMutationWithInvalidation = function useMutationWithInvalidation(mutationFn, _ref) {
|
|
3546
|
+
var keysToInvalidate = _ref.keysToInvalidate,
|
|
3547
|
+
options = _objectWithoutProperties(_ref, _excluded);
|
|
3548
|
+
var queryClient = useQueryClient();
|
|
3549
|
+
var _onSuccess = options.onSuccess,
|
|
3550
|
+
otherOptions = _objectWithoutProperties(options, _excluded2);
|
|
3551
|
+
return useMutation(mutationFn, _objectSpread({
|
|
3552
|
+
onSuccess: function onSuccess(data, variables, context) {
|
|
3553
|
+
keysToInvalidate.forEach(function (key) {
|
|
3554
|
+
var keyToInvalidate = typeof key === "function" ? key(data, variables, context) : key;
|
|
3555
|
+
queryClient.invalidateQueries(keyToInvalidate);
|
|
3556
|
+
});
|
|
3557
|
+
_onSuccess === null || _onSuccess === void 0 ? void 0 : _onSuccess(data, variables, context);
|
|
3558
|
+
}
|
|
3559
|
+
}, otherOptions));
|
|
3560
|
+
};
|
|
3561
|
+
|
|
3543
3562
|
var useOnClickOutside = function useOnClickOutside(ref, handler) {
|
|
3544
3563
|
useEffect(function () {
|
|
3545
3564
|
var listener = function listener(event) {
|
|
@@ -4788,5 +4807,5 @@ var useUpdateEffect = function useUpdateEffect(callback) {
|
|
|
4788
4807
|
}, dependencies);
|
|
4789
4808
|
};
|
|
4790
4809
|
|
|
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 };
|
|
4810
|
+
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
4811
|
//# sourceMappingURL=react-utils.js.map
|