@qoretechnologies/reqraft 0.7.1 → 0.7.2
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/dist/hooks/useStorage/useStorage.js +1 -1
- package/dist/hooks/useStorage/useStorage.js.map +1 -1
- package/dist/hooks/useWhyDidYouUpdate.d.ts +1 -1
- package/dist/hooks/useWhyDidYouUpdate.d.ts.map +1 -1
- package/dist/hooks/useWhyDidYouUpdate.js.map +1 -1
- package/dist/providers/ReqraftProvider.d.ts.map +1 -1
- package/dist/providers/ReqraftProvider.js +1 -1
- package/dist/providers/ReqraftProvider.js.map +1 -1
- package/dist/providers/StorageProvider.d.ts +1 -1
- package/dist/providers/StorageProvider.d.ts.map +1 -1
- package/dist/providers/StorageProvider.js +23 -27
- package/dist/providers/StorageProvider.js.map +1 -1
- package/dist/stores/currentUser/currentUser.d.ts +28 -0
- package/dist/stores/currentUser/currentUser.d.ts.map +1 -0
- package/dist/stores/currentUser/currentUser.js +91 -0
- package/dist/stores/currentUser/currentUser.js.map +1 -0
- package/package.json +4 -2
- package/src/hooks/useStorage/useStorage.stories.tsx +1 -1
- package/src/hooks/useStorage/useStorage.ts +2 -2
- package/src/hooks/useWhyDidYouUpdate.ts +1 -1
- package/src/providers/ReqraftProvider.tsx +6 -8
- package/src/providers/StorageProvider.tsx +53 -48
- package/src/stores/currentUser/currentUser.stories.tsx +48 -0
- package/src/stores/currentUser/currentUser.tsx +70 -0
|
@@ -12,7 +12,7 @@ function useReqraftStorage(path, defaultValue, includeAppPrefix) {
|
|
|
12
12
|
var remover = (0, react_1.useCallback)(function () {
|
|
13
13
|
removeStorageValue(path, includeAppPrefix);
|
|
14
14
|
}, [path, includeAppPrefix, removeStorageValue]);
|
|
15
|
-
return [value, updater, remover];
|
|
15
|
+
return (0, react_1.useMemo)(function () { return [value, updater, remover]; }, [value, updater, remover]);
|
|
16
16
|
}
|
|
17
17
|
exports.useReqraftStorage = useReqraftStorage;
|
|
18
18
|
//# sourceMappingURL=useStorage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStorage.js","sourceRoot":"","sources":["../../../src/hooks/useStorage/useStorage.ts"],"names":[],"mappings":";;;AAAA,+BAAyD;AACzD,gEAAsE;AAStE,SAAgB,iBAAiB,CAC/B,IAAY,EACZ,YAAgB,EAChB,gBAA0B;IAEpB,IAAA,KAAoD,IAAA,kBAAU,EAAC,sCAAqB,CAAC,EAAnF,UAAU,gBAAA,EAAE,aAAa,mBAAA,EAAE,kBAAkB,wBAAsC,CAAC;IAE5F,IAAM,KAAK,GAAG,IAAA,eAAO,EACnB,cAAM,OAAA,UAAU,CAAC,IAAI,EAAE,YAAY,EAAE,gBAAgB,CAAC,EAAhD,CAAgD,EACtD,CAAC,IAAI,EAAE,YAAY,EAAE,gBAAgB,EAAE,UAAU,CAAC,CACnD,CAAC;IAEF,IAAM,OAAO,GAAG,IAAA,mBAAW,EACzB,UAAC,UAAa;QACZ,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;IACpD,CAAC,EACD,CAAC,IAAI,EAAE,gBAAgB,EAAE,aAAa,CAAC,CACxC,CAAC;IAEF,IAAM,OAAO,GAAG,IAAA,mBAAW,EAAC;QAC1B,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;IAC7C,CAAC,EAAE,CAAC,IAAI,EAAE,gBAAgB,EAAE,kBAAkB,CAAC,CAAC,CAAC;IAEjD,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"useStorage.js","sourceRoot":"","sources":["../../../src/hooks/useStorage/useStorage.ts"],"names":[],"mappings":";;;AAAA,+BAAyD;AACzD,gEAAsE;AAStE,SAAgB,iBAAiB,CAC/B,IAAY,EACZ,YAAgB,EAChB,gBAA0B;IAEpB,IAAA,KAAoD,IAAA,kBAAU,EAAC,sCAAqB,CAAC,EAAnF,UAAU,gBAAA,EAAE,aAAa,mBAAA,EAAE,kBAAkB,wBAAsC,CAAC;IAE5F,IAAM,KAAK,GAAG,IAAA,eAAO,EACnB,cAAM,OAAA,UAAU,CAAC,IAAI,EAAE,YAAY,EAAE,gBAAgB,CAAC,EAAhD,CAAgD,EACtD,CAAC,IAAI,EAAE,YAAY,EAAE,gBAAgB,EAAE,UAAU,CAAC,CACnD,CAAC;IAEF,IAAM,OAAO,GAAG,IAAA,mBAAW,EACzB,UAAC,UAAa;QACZ,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;IACpD,CAAC,EACD,CAAC,IAAI,EAAE,gBAAgB,EAAE,aAAa,CAAC,CACxC,CAAC;IAEF,IAAM,OAAO,GAAG,IAAA,mBAAW,EAAC;QAC1B,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC;IAC7C,CAAC,EAAE,CAAC,IAAI,EAAE,gBAAgB,EAAE,kBAAkB,CAAC,CAAC,CAAC;IAEjD,OAAO,IAAA,eAAO,EAAC,cAAM,OAAA,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAzB,CAAyB,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AAC7E,CAAC;AAxBD,8CAwBC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function useWhyDidYouUpdate(name:
|
|
1
|
+
export declare function useWhyDidYouUpdate(name: string, props: Record<any, any>): void;
|
|
2
2
|
//# sourceMappingURL=useWhyDidYouUpdate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWhyDidYouUpdate.d.ts","sourceRoot":"","sources":["../../src/hooks/useWhyDidYouUpdate.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"useWhyDidYouUpdate.d.ts","sourceRoot":"","sources":["../../src/hooks/useWhyDidYouUpdate.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,QA+BvE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWhyDidYouUpdate.js","sourceRoot":"","sources":["../../src/hooks/useWhyDidYouUpdate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+BAA0C;AAE1C,SAAgB,kBAAkB,CAAC,
|
|
1
|
+
{"version":3,"file":"useWhyDidYouUpdate.js","sourceRoot":"","sources":["../../src/hooks/useWhyDidYouUpdate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+BAA0C;AAE1C,SAAgB,kBAAkB,CAAC,IAAY,EAAE,KAAuB;IACtE,wDAAwD;IACxD,+CAA+C;IAC/C,IAAM,aAAa,GAAQ,IAAA,cAAM,GAAE,CAAC;IACpC,IAAA,iBAAS,EAAC;QACR,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;YAClF,IAAI,aAAa,CAAC,OAAO,EAAE,CAAC;gBAC1B,+CAA+C;gBAC/C,IAAM,OAAO,GAAG,MAAM,CAAC,IAAI,uBAAM,aAAa,CAAC,OAAO,GAAK,KAAK,EAAG,CAAC;gBACpE,iDAAiD;gBACjD,IAAM,YAAU,GAAG,EAAE,CAAC;gBACtB,uBAAuB;gBACvB,OAAO,CAAC,OAAO,CAAC,UAAC,GAAG;oBAClB,wCAAwC;oBACxC,IAAI,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;wBAC9C,oBAAoB;wBACpB,YAAU,CAAC,GAAG,CAAC,GAAG;4BAChB,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC;4BAChC,EAAE,EAAE,KAAK,CAAC,GAAG,CAAC;yBACf,CAAC;oBACJ,CAAC;gBACH,CAAC,CAAC,CAAC;gBACH,iDAAiD;gBACjD,IAAI,MAAM,CAAC,IAAI,CAAC,YAAU,CAAC,CAAC,MAAM,EAAE,CAAC;oBACnC,OAAO,CAAC,IAAI,CAAC,UAAG,IAAI,uBAAoB,EAAE,YAAU,CAAC,CAAC;gBACxD,CAAC;YACH,CAAC;YACD,qEAAqE;YACrE,aAAa,CAAC,OAAO,GAAG,KAAK,CAAC;QAChC,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AA/BD,gDA+BC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReqraftProvider.d.ts","sourceRoot":"","sources":["../../src/providers/ReqraftProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAuB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,eAAe,EAAkB,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAc,MAAM,gBAAgB,CAAC;AAIjE,eAAO,MAAM,kBAAkB,aAAoB,CAAC;AAEpD,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D,QAAQ,EAAE,SAAS,CAAC;IACpB,gBAAgB,CAAC,EAAE,WAAW,CAAC;IAI/B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,4BAA4B,CAAC,EAAE,mBAAmB,CAAC,sBAAsB,CAAC,CAAC;CAC5E;AAED,eAAO,MAAM,iBAAiB,YAAa,eAAe,gEAevD,qBAAqB,4CAPvB,CAAC;AAEF,eAAO,MAAM,eAAe,6DAKzB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"ReqraftProvider.d.ts","sourceRoot":"","sources":["../../src/providers/ReqraftProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAuB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,eAAe,EAAkB,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAc,MAAM,gBAAgB,CAAC;AAIjE,eAAO,MAAM,kBAAkB,aAAoB,CAAC;AAEpD,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D,QAAQ,EAAE,SAAS,CAAC;IACpB,gBAAgB,CAAC,EAAE,WAAW,CAAC;IAI/B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,4BAA4B,CAAC,EAAE,mBAAmB,CAAC,sBAAsB,CAAC,CAAC;CAC5E;AAED,eAAO,MAAM,iBAAiB,YAAa,eAAe,gEAevD,qBAAqB,4CAPvB,CAAC;AAEF,eAAO,MAAM,eAAe,6DAKzB,qBAAqB,4CAUvB,CAAC"}
|
|
@@ -19,7 +19,7 @@ var initializeReqraft = function (options) {
|
|
|
19
19
|
exports.initializeReqraft = initializeReqraft;
|
|
20
20
|
var ReqraftProvider = function (_a) {
|
|
21
21
|
var appName = _a.appName, children = _a.children, reactQueryClient = _a.reactQueryClient, _b = _a.waitForStorage, waitForStorage = _b === void 0 ? true : _b;
|
|
22
|
-
return ((0, jsx_runtime_1.jsx)(ReqraftContext_1.ReqraftContext.Provider, { value: { appName: appName }, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: reactQueryClient || exports.ReqraftQueryClient, children: (0, jsx_runtime_1.jsx)(FetchProvider_1.ReqraftFetchProvider, { children: (0, jsx_runtime_1.jsx)(StorageProvider_1.
|
|
22
|
+
return ((0, jsx_runtime_1.jsx)(ReqraftContext_1.ReqraftContext.Provider, { value: { appName: appName }, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: reactQueryClient || exports.ReqraftQueryClient, children: (0, jsx_runtime_1.jsx)(FetchProvider_1.ReqraftFetchProvider, { children: (0, jsx_runtime_1.jsx)(StorageProvider_1.ReqraftUserProvider, { waitForStorage: waitForStorage, children: children }) }) }) }));
|
|
23
23
|
};
|
|
24
24
|
exports.ReqraftProvider = ReqraftProvider;
|
|
25
25
|
//# sourceMappingURL=ReqraftProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReqraftProvider.js","sourceRoot":"","sources":["../../src/providers/ReqraftProvider.tsx"],"names":[],"mappings":";;;;AAAA,qDAAyE;AAEzE,6DAA6E;AAC7E,wCAAiE;AACjE,iDAAuD;AACvD,
|
|
1
|
+
{"version":3,"file":"ReqraftProvider.js","sourceRoot":"","sources":["../../src/providers/ReqraftProvider.tsx"],"names":[],"mappings":";;;;AAAA,qDAAyE;AAEzE,6DAA6E;AAC7E,wCAAiE;AACjE,iDAAuD;AACvD,qDAAwD;AAE3C,QAAA,kBAAkB,GAAG,IAAI,yBAAW,EAAE,CAAC;AAiB7C,IAAM,iBAAiB,GAAG,UAAC,OAAwB;IACxD,IAAA,kBAAU,EAAC;QACT,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,oBAAoB,EAAE,OAAO,CAAC,4BAA4B;KAC3D,CAAC,CAAC;IAEH,OAAO,uBAAe,CAAC;AACzB,CAAC,CAAC;AARW,QAAA,iBAAiB,qBAQ5B;AAEK,IAAM,eAAe,GAAG,UAAC,EAKR;QAJtB,OAAO,aAAA,EACP,QAAQ,cAAA,EACR,gBAAgB,sBAAA,EAChB,sBAAqB,EAArB,cAAc,mBAAG,IAAI,KAAA;IAErB,OAAO,CACL,uBAAC,+BAAc,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,OAAO,SAAA,EAAE,YACzC,uBAAC,iCAAmB,IAAC,MAAM,EAAE,gBAAgB,IAAI,0BAAkB,YACjE,uBAAC,oCAAoB,cACnB,uBAAC,qCAAmB,IAAC,cAAc,EAAE,cAAc,YAAG,QAAQ,GAAuB,GAChE,GACH,GACE,CAC3B,CAAC;AACJ,CAAC,CAAC;AAfW,QAAA,eAAe,mBAe1B"}
|
|
@@ -3,5 +3,5 @@ import { IReqraftProviderProps } from './ReqraftProvider';
|
|
|
3
3
|
export interface IReqraftStorageProviderProps extends Pick<IReqraftProviderProps, 'waitForStorage'> {
|
|
4
4
|
children: ReactNode;
|
|
5
5
|
}
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const ReqraftUserProvider: ({ children, waitForStorage }: IReqraftStorageProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
//# sourceMappingURL=StorageProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageProvider.d.ts","sourceRoot":"","sources":["../../src/providers/StorageProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"StorageProvider.d.ts","sourceRoot":"","sources":["../../src/providers/StorageProvider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAwB,MAAM,OAAO,CAAC;AAQxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,MAAM,WAAW,4BACf,SAAQ,IAAI,CAAC,qBAAqB,EAAE,gBAAgB,CAAC;IACrD,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,eAAO,MAAM,mBAAmB,iCAAkC,4BAA4B,4CAyE7F,CAAC"}
|
|
@@ -1,55 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ReqraftUserProvider = void 0;
|
|
4
4
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
var lodash_1 = require("lodash");
|
|
6
6
|
var react_1 = require("react");
|
|
7
|
+
var react_use_1 = require("react-use");
|
|
7
8
|
var StorageContext_1 = require("../contexts/StorageContext");
|
|
8
9
|
var useFetch_1 = require("../hooks/useFetch/useFetch");
|
|
9
10
|
var useReqraftProperty_1 = require("../hooks/useReqraftProperty");
|
|
10
|
-
var
|
|
11
|
+
var currentUser_1 = require("../stores/currentUser/currentUser");
|
|
12
|
+
var ReqraftUserProvider = function (_a) {
|
|
11
13
|
var children = _a.children, waitForStorage = _a.waitForStorage;
|
|
12
14
|
var appName = (0, useReqraftProperty_1.useReqraftProperty)('appName');
|
|
13
|
-
var _b = (0,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}), data = _b.data, loading = _b.loading;
|
|
15
|
+
var _b = (0, currentUser_1.currentUserStore)(), currentUser = _b.currentUser, updateCurrentUserStorage = _b.updateStorage, loadCurrentUser = _b.load, loading = _b.loading;
|
|
16
|
+
(0, react_use_1.useEffectOnce)(function () {
|
|
17
|
+
loadCurrentUser();
|
|
18
|
+
});
|
|
18
19
|
var load = (0, useFetch_1.useFetch)({
|
|
19
20
|
url: 'users/_current_/',
|
|
20
21
|
method: 'PUT',
|
|
21
22
|
cache: false,
|
|
22
23
|
}).load;
|
|
23
|
-
var
|
|
24
|
-
(0, react_1.useEffect)(function () {
|
|
25
|
-
if (data) {
|
|
26
|
-
setStorage(data);
|
|
27
|
-
}
|
|
28
|
-
}, [JSON.stringify(data)]);
|
|
29
|
-
var getStorage = function (path, defaultValue, includeAppPrefix) {
|
|
24
|
+
var getStorage = (0, react_1.useCallback)(function (path, defaultValue, includeAppPrefix) {
|
|
30
25
|
var _a;
|
|
31
26
|
if (includeAppPrefix === void 0) { includeAppPrefix = true; }
|
|
32
27
|
var _path = includeAppPrefix ? "".concat(appName, ".").concat(path) : path;
|
|
33
|
-
return (_a = (0, lodash_1.get)(storage, _path)) !== null && _a !== void 0 ? _a : defaultValue;
|
|
34
|
-
};
|
|
35
|
-
var updateStorage = function (path, value, includeAppPrefix) {
|
|
28
|
+
return (_a = (0, lodash_1.get)(currentUser === null || currentUser === void 0 ? void 0 : currentUser.storage, _path)) !== null && _a !== void 0 ? _a : defaultValue;
|
|
29
|
+
}, [appName, currentUser === null || currentUser === void 0 ? void 0 : currentUser.storage]);
|
|
30
|
+
var updateStorage = (0, react_1.useCallback)(function (path, value, includeAppPrefix) {
|
|
36
31
|
if (includeAppPrefix === void 0) { includeAppPrefix = true; }
|
|
37
32
|
var _path = includeAppPrefix ? "".concat(appName, ".").concat(path) : path;
|
|
38
|
-
var updatedStorage = (0, lodash_1.set)((0, lodash_1.cloneDeep)(storage), _path, value);
|
|
39
|
-
|
|
33
|
+
var updatedStorage = (0, lodash_1.set)((0, lodash_1.cloneDeep)(currentUser === null || currentUser === void 0 ? void 0 : currentUser.storage), _path, value);
|
|
34
|
+
updateCurrentUserStorage(updatedStorage);
|
|
40
35
|
load({ body: { storage: updatedStorage } });
|
|
41
|
-
};
|
|
42
|
-
var removeStorageValue = function (path, includeAppPrefix) {
|
|
36
|
+
}, [appName, currentUser === null || currentUser === void 0 ? void 0 : currentUser.storage, load, updateCurrentUserStorage]);
|
|
37
|
+
var removeStorageValue = (0, react_1.useCallback)(function (path, includeAppPrefix) {
|
|
43
38
|
if (includeAppPrefix === void 0) { includeAppPrefix = true; }
|
|
44
39
|
var _path = includeAppPrefix ? "".concat(appName, ".").concat(path) : path;
|
|
45
|
-
var updatedStorage = (0, lodash_1.set)((0, lodash_1.cloneDeep)(storage), _path, null);
|
|
46
|
-
|
|
40
|
+
var updatedStorage = (0, lodash_1.set)((0, lodash_1.cloneDeep)(currentUser === null || currentUser === void 0 ? void 0 : currentUser.storage), _path, null);
|
|
41
|
+
updateCurrentUserStorage(updatedStorage);
|
|
47
42
|
load({ body: { storage_path: _path } });
|
|
48
|
-
};
|
|
49
|
-
|
|
43
|
+
}, [appName, currentUser === null || currentUser === void 0 ? void 0 : currentUser.storage, load, updateCurrentUserStorage]);
|
|
44
|
+
var contextValue = (0, react_1.useMemo)(function () { return ({ storage: currentUser === null || currentUser === void 0 ? void 0 : currentUser.storage, getStorage: getStorage, updateStorage: updateStorage, removeStorageValue: removeStorageValue }); }, [currentUser === null || currentUser === void 0 ? void 0 : currentUser.storage, getStorage, updateStorage, removeStorageValue]);
|
|
45
|
+
if (loading && waitForStorage) {
|
|
50
46
|
return null;
|
|
51
47
|
}
|
|
52
|
-
return ((0, jsx_runtime_1.jsx)(StorageContext_1.ReqraftStorageContext.Provider, { value:
|
|
48
|
+
return ((0, jsx_runtime_1.jsx)(StorageContext_1.ReqraftStorageContext.Provider, { value: contextValue, children: children }));
|
|
53
49
|
};
|
|
54
|
-
exports.
|
|
50
|
+
exports.ReqraftUserProvider = ReqraftUserProvider;
|
|
55
51
|
//# sourceMappingURL=StorageProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorageProvider.js","sourceRoot":"","sources":["../../src/providers/StorageProvider.tsx"],"names":[],"mappings":";;;;AAAA,iCAA6C;AAC7C,+
|
|
1
|
+
{"version":3,"file":"StorageProvider.js","sourceRoot":"","sources":["../../src/providers/StorageProvider.tsx"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface ICurrentUser {
|
|
2
|
+
provider: string;
|
|
3
|
+
username: string;
|
|
4
|
+
name: string;
|
|
5
|
+
has_default: boolean;
|
|
6
|
+
roles: string[];
|
|
7
|
+
permissions: string[];
|
|
8
|
+
workflows: string[];
|
|
9
|
+
services: string[];
|
|
10
|
+
jobs: string[];
|
|
11
|
+
mappers: string[];
|
|
12
|
+
vmaps: string[];
|
|
13
|
+
groups: string[];
|
|
14
|
+
fsms: string[];
|
|
15
|
+
oauth2_clients?: Record<string, any>[];
|
|
16
|
+
storage?: Record<string, any>;
|
|
17
|
+
}
|
|
18
|
+
export interface ICurrentUserStore {
|
|
19
|
+
currentUser?: ICurrentUser;
|
|
20
|
+
load: () => Promise<ICurrentUser>;
|
|
21
|
+
loading?: boolean;
|
|
22
|
+
error?: Error;
|
|
23
|
+
errorData?: any;
|
|
24
|
+
hasPermissions: (permissions: string[]) => boolean;
|
|
25
|
+
updateStorage: (storage: Record<string, any>) => void;
|
|
26
|
+
}
|
|
27
|
+
export declare const currentUserStore: import("zustand").UseBoundStore<import("zustand").StoreApi<ICurrentUserStore>>;
|
|
28
|
+
//# sourceMappingURL=currentUser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currentUser.d.ts","sourceRoot":"","sources":["../../../src/stores/currentUser/currentUser.tsx"],"names":[],"mappings":"AAGA,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,iBAAiB;IAChC,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B,IAAI,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,SAAS,CAAC,EAAE,GAAG,CAAC;IAEhB,cAAc,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC;IACnD,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;CACvD;AAED,eAAO,MAAM,gBAAgB,gFAoC1B,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.currentUserStore = void 0;
|
|
51
|
+
var zustand_1 = require("zustand");
|
|
52
|
+
var fetch_1 = require("../../utils/fetch");
|
|
53
|
+
exports.currentUserStore = (0, zustand_1.create)(function (set, get) { return ({
|
|
54
|
+
currentUser: undefined,
|
|
55
|
+
loading: false,
|
|
56
|
+
error: undefined,
|
|
57
|
+
load: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
58
|
+
var response;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
set({ loading: true });
|
|
63
|
+
return [4 /*yield*/, (0, fetch_1.query)({ url: 'users?action=current', cache: false })];
|
|
64
|
+
case 1:
|
|
65
|
+
response = _a.sent();
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
set({
|
|
68
|
+
loading: false,
|
|
69
|
+
error: response.error,
|
|
70
|
+
currentUser: undefined,
|
|
71
|
+
errorData: response.data,
|
|
72
|
+
});
|
|
73
|
+
return [2 /*return*/, Promise.reject(response.error)];
|
|
74
|
+
}
|
|
75
|
+
set({ currentUser: response.data, loading: false, errorData: undefined, error: undefined });
|
|
76
|
+
return [2 /*return*/, response.data];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}); },
|
|
80
|
+
hasPermissions: function (permissions) {
|
|
81
|
+
if (!get().currentUser) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
var currentUser = get().currentUser;
|
|
85
|
+
return permissions.every(function (permission) { var _a; return (_a = currentUser.permissions) === null || _a === void 0 ? void 0 : _a.includes(permission); });
|
|
86
|
+
},
|
|
87
|
+
updateStorage: function (storage) {
|
|
88
|
+
set(function (state) { return ({ currentUser: __assign(__assign({}, state.currentUser), { storage: storage }) }); });
|
|
89
|
+
},
|
|
90
|
+
}); });
|
|
91
|
+
//# sourceMappingURL=currentUser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currentUser.js","sourceRoot":"","sources":["../../../src/stores/currentUser/currentUser.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAiC;AACjC,2CAA0C;AAgC7B,QAAA,gBAAgB,GAAG,IAAA,gBAAM,EAAoB,UAAC,GAAG,EAAE,GAAG,IAAK,OAAA,CAAC;IACvE,WAAW,EAAE,SAAS;IACtB,OAAO,EAAE,KAAK;IACd,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE;;;;;oBACJ,GAAG,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;oBAEN,qBAAM,IAAA,aAAK,EAAe,EAAE,GAAG,EAAE,sBAAsB,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAA;;oBAAnF,QAAQ,GAAG,SAAwE;oBAEzF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;wBACjB,GAAG,CAAC;4BACF,OAAO,EAAE,KAAK;4BACd,KAAK,EAAE,QAAQ,CAAC,KAAK;4BACrB,WAAW,EAAE,SAAS;4BACtB,SAAS,EAAE,QAAQ,CAAC,IAAI;yBACzB,CAAC,CAAC;wBAEH,sBAAO,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAC;oBACxC,CAAC;oBAED,GAAG,CAAC,EAAE,WAAW,EAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;oBAE5F,sBAAO,QAAQ,CAAC,IAAI,EAAC;;;SACtB;IACD,cAAc,EAAE,UAAC,WAAW;QAC1B,IAAI,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC;YACvB,OAAO,KAAK,CAAC;QACf,CAAC;QAEO,IAAA,WAAW,GAAK,GAAG,EAAE,YAAV,CAAW;QAE9B,OAAO,WAAW,CAAC,KAAK,CAAC,UAAC,UAAU,YAAK,OAAA,MAAA,WAAW,CAAC,WAAW,0CAAE,QAAQ,CAAC,UAAU,CAAC,CAAA,EAAA,CAAC,CAAC;IAC1F,CAAC;IACD,aAAa,EAAE,UAAC,OAAO;QACrB,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,CAAC,EAAE,WAAW,wBAAO,KAAK,CAAC,WAAW,KAAE,OAAO,SAAA,GAAE,EAAE,CAAC,EAApD,CAAoD,CAAC,CAAC;IACvE,CAAC;CACF,CAAC,EApCsE,CAoCtE,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qoretechnologies/reqraft",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "ReQraft is a collection of React components and hooks that are used across Qore Technologies' products made using the ReQore component library from Qore.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"build:test": "./node_modules/typescript/bin/tsc --noEmit",
|
|
15
15
|
"build:test:prod": "./node_modules/typescript/bin/tsc --project tsconfig.prod.json --noEmit",
|
|
16
16
|
"lint": "yarn run eslint ./src/",
|
|
17
|
+
"start": "yarn storybook",
|
|
17
18
|
"storybook": "storybook dev -p 6008",
|
|
18
19
|
"update-reqore": "yarn add -D @qoretechnologies/reqore@beta",
|
|
19
20
|
"test-storybook": "DEBUG_PRINT_LIMIT=300 test-storybook --url http://localhost:6008",
|
|
@@ -123,7 +124,8 @@
|
|
|
123
124
|
"shortid": "^2.2.16",
|
|
124
125
|
"styled-components": "^5.3.6",
|
|
125
126
|
"thenby": "^1.3.4",
|
|
126
|
-
"use-context-selector": "^1.4.1"
|
|
127
|
+
"use-context-selector": "^1.4.1",
|
|
128
|
+
"zustand": "^5.0.3"
|
|
127
129
|
},
|
|
128
130
|
"resolutions": {
|
|
129
131
|
"jackspeak": "2.1.1"
|
|
@@ -37,7 +37,7 @@ export const DefaultValue: Story = {
|
|
|
37
37
|
parameters: {
|
|
38
38
|
mockData: [
|
|
39
39
|
{
|
|
40
|
-
url: 'https://hq.qoretechnologies.com:8092/api/latest/users
|
|
40
|
+
url: 'https://hq.qoretechnologies.com:8092/api/latest/users?action=current',
|
|
41
41
|
method: 'GET',
|
|
42
42
|
status: 200,
|
|
43
43
|
response: {},
|
|
@@ -5,7 +5,7 @@ export type TReqraftStorageValue = string | number | boolean | Record<string | n
|
|
|
5
5
|
export type TReqraftUseStorage<T extends TReqraftStorageValue> = [
|
|
6
6
|
T,
|
|
7
7
|
(newStorage: T) => void,
|
|
8
|
-
() => void
|
|
8
|
+
() => void
|
|
9
9
|
];
|
|
10
10
|
|
|
11
11
|
export function useReqraftStorage<T extends TReqraftStorageValue>(
|
|
@@ -31,5 +31,5 @@ export function useReqraftStorage<T extends TReqraftStorageValue>(
|
|
|
31
31
|
removeStorageValue(path, includeAppPrefix);
|
|
32
32
|
}, [path, includeAppPrefix, removeStorageValue]);
|
|
33
33
|
|
|
34
|
-
return [value, updater, remover];
|
|
34
|
+
return useMemo(() => [value, updater, remover], [value, updater, remover]);
|
|
35
35
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
2
|
|
|
3
|
-
export function useWhyDidYouUpdate(name, props) {
|
|
3
|
+
export function useWhyDidYouUpdate(name: string, props: Record<any, any>) {
|
|
4
4
|
// Get a mutable ref object where we can store props ...
|
|
5
5
|
// ... for comparison next time this hook runs.
|
|
6
6
|
const previousProps: any = useRef();
|
|
@@ -3,7 +3,7 @@ import { ReactNode } from 'react';
|
|
|
3
3
|
import { IReqraftContext, ReqraftContext } from '../contexts/ReqraftContext';
|
|
4
4
|
import { IReqraftFetchConfig, setupFetch } from '../utils/fetch';
|
|
5
5
|
import { ReqraftFetchProvider } from './FetchProvider';
|
|
6
|
-
import {
|
|
6
|
+
import { ReqraftUserProvider } from './StorageProvider';
|
|
7
7
|
|
|
8
8
|
export const ReqraftQueryClient = new QueryClient();
|
|
9
9
|
|
|
@@ -11,8 +11,8 @@ export interface IReqraftProviderProps extends IReqraftContext {
|
|
|
11
11
|
children: ReactNode;
|
|
12
12
|
reactQueryClient?: QueryClient;
|
|
13
13
|
/*
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
* If true, the component will wait for the storage to be loaded before rendering the children.
|
|
15
|
+
*/
|
|
16
16
|
waitForStorage?: boolean;
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -22,7 +22,7 @@ export interface IReqraftOptions {
|
|
|
22
22
|
instanceUnauthorizedRedirect?: IReqraftFetchConfig['unauthorizedRedirect'];
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export const initializeReqraft = (options: IReqraftOptions
|
|
25
|
+
export const initializeReqraft = (options: IReqraftOptions) => {
|
|
26
26
|
setupFetch({
|
|
27
27
|
instance: options.instance,
|
|
28
28
|
instanceToken: options.instanceToken,
|
|
@@ -39,12 +39,10 @@ export const ReqraftProvider = ({
|
|
|
39
39
|
waitForStorage = true,
|
|
40
40
|
}: IReqraftProviderProps) => {
|
|
41
41
|
return (
|
|
42
|
-
<ReqraftContext.Provider
|
|
43
|
-
value={{ appName }}
|
|
44
|
-
>
|
|
42
|
+
<ReqraftContext.Provider value={{ appName }}>
|
|
45
43
|
<QueryClientProvider client={reactQueryClient || ReqraftQueryClient}>
|
|
46
44
|
<ReqraftFetchProvider>
|
|
47
|
-
<
|
|
45
|
+
<ReqraftUserProvider waitForStorage={waitForStorage}>{children}</ReqraftUserProvider>
|
|
48
46
|
</ReqraftFetchProvider>
|
|
49
47
|
</QueryClientProvider>
|
|
50
48
|
</ReqraftContext.Provider>
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { cloneDeep, get, set } from 'lodash';
|
|
2
|
-
import { ReactNode,
|
|
2
|
+
import { ReactNode, useCallback, useMemo } from 'react';
|
|
3
|
+
import { useEffectOnce } from 'react-use';
|
|
3
4
|
import type { Get } from 'type-fest';
|
|
4
5
|
import { ReqraftStorageContext, TReqraftStorage } from '../contexts/StorageContext';
|
|
5
6
|
import { useFetch } from '../hooks/useFetch/useFetch';
|
|
6
7
|
import { useReqraftProperty } from '../hooks/useReqraftProperty';
|
|
7
8
|
import { TReqraftStorageValue } from '../hooks/useStorage/useStorage';
|
|
9
|
+
import { currentUserStore } from '../stores/currentUser/currentUser';
|
|
8
10
|
import { IReqraftProviderProps } from './ReqraftProvider';
|
|
9
11
|
|
|
10
12
|
export interface IReqraftStorageProviderProps
|
|
@@ -12,16 +14,17 @@ export interface IReqraftStorageProviderProps
|
|
|
12
14
|
children: ReactNode;
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
export const
|
|
16
|
-
children,
|
|
17
|
-
waitForStorage,
|
|
18
|
-
}: IReqraftStorageProviderProps) => {
|
|
17
|
+
export const ReqraftUserProvider = ({ children, waitForStorage }: IReqraftStorageProviderProps) => {
|
|
19
18
|
const appName = useReqraftProperty('appName');
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
const {
|
|
20
|
+
currentUser,
|
|
21
|
+
updateStorage: updateCurrentUserStorage,
|
|
22
|
+
load: loadCurrentUser,
|
|
23
|
+
loading,
|
|
24
|
+
} = currentUserStore();
|
|
25
|
+
|
|
26
|
+
useEffectOnce(() => {
|
|
27
|
+
loadCurrentUser();
|
|
25
28
|
});
|
|
26
29
|
|
|
27
30
|
const { load } = useFetch({
|
|
@@ -30,56 +33,58 @@ export const ReqraftStorageProvider = ({
|
|
|
30
33
|
cache: false,
|
|
31
34
|
});
|
|
32
35
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
): Get<TReqraftStorage, string> {
|
|
46
|
-
const _path = includeAppPrefix ? `${appName}.${path}` : path;
|
|
36
|
+
const getStorage = useCallback(
|
|
37
|
+
function <T extends TReqraftStorageValue>(
|
|
38
|
+
path: string,
|
|
39
|
+
defaultValue: T,
|
|
40
|
+
includeAppPrefix: boolean = true
|
|
41
|
+
): Get<TReqraftStorage, string> {
|
|
42
|
+
const _path = includeAppPrefix ? `${appName}.${path}` : path;
|
|
43
|
+
|
|
44
|
+
return get(currentUser?.storage, _path) ?? defaultValue;
|
|
45
|
+
},
|
|
46
|
+
[appName, currentUser?.storage]
|
|
47
|
+
);
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
const updateStorage = useCallback(
|
|
50
|
+
function <T extends TReqraftStorageValue>(
|
|
51
|
+
path: string,
|
|
52
|
+
value: T,
|
|
53
|
+
includeAppPrefix: boolean = true
|
|
54
|
+
) {
|
|
55
|
+
const _path = includeAppPrefix ? `${appName}.${path}` : path;
|
|
56
|
+
const updatedStorage = set(cloneDeep(currentUser?.storage), _path, value);
|
|
50
57
|
|
|
51
|
-
|
|
52
|
-
path: string,
|
|
53
|
-
value: T,
|
|
54
|
-
includeAppPrefix: boolean = true
|
|
55
|
-
) {
|
|
56
|
-
const _path = includeAppPrefix ? `${appName}.${path}` : path;
|
|
57
|
-
const updatedStorage = set(cloneDeep(storage), _path, value);
|
|
58
|
+
updateCurrentUserStorage(updatedStorage);
|
|
58
59
|
|
|
59
|
-
|
|
60
|
+
load({ body: { storage: updatedStorage } });
|
|
61
|
+
},
|
|
62
|
+
[appName, currentUser?.storage, load, updateCurrentUserStorage]
|
|
63
|
+
);
|
|
60
64
|
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
const removeStorageValue = useCallback(
|
|
66
|
+
function (path: string, includeAppPrefix: boolean = true) {
|
|
67
|
+
const _path = includeAppPrefix ? `${appName}.${path}` : path;
|
|
63
68
|
|
|
64
|
-
|
|
65
|
-
const _path = includeAppPrefix ? `${appName}.${path}` : path;
|
|
69
|
+
const updatedStorage = set(cloneDeep(currentUser?.storage), _path, null);
|
|
66
70
|
|
|
67
|
-
|
|
71
|
+
updateCurrentUserStorage(updatedStorage);
|
|
68
72
|
|
|
69
|
-
|
|
73
|
+
load({ body: { storage_path: _path } });
|
|
74
|
+
},
|
|
75
|
+
[appName, currentUser?.storage, load, updateCurrentUserStorage]
|
|
76
|
+
);
|
|
70
77
|
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
const contextValue = useMemo(
|
|
79
|
+
() => ({ storage: currentUser?.storage, getStorage, updateStorage, removeStorageValue }),
|
|
80
|
+
[currentUser?.storage, getStorage, updateStorage, removeStorageValue]
|
|
81
|
+
);
|
|
73
82
|
|
|
74
|
-
if (
|
|
83
|
+
if (loading && waitForStorage) {
|
|
75
84
|
return null;
|
|
76
85
|
}
|
|
77
86
|
|
|
78
87
|
return (
|
|
79
|
-
<ReqraftStorageContext.Provider
|
|
80
|
-
value={{ storage, getStorage, updateStorage, removeStorageValue }}
|
|
81
|
-
>
|
|
82
|
-
{children}
|
|
83
|
-
</ReqraftStorageContext.Provider>
|
|
88
|
+
<ReqraftStorageContext.Provider value={contextValue}>{children}</ReqraftStorageContext.Provider>
|
|
84
89
|
);
|
|
85
90
|
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ReqoreP, ReqoreSpinner, ReqoreTree } from '@qoretechnologies/reqore';
|
|
2
|
+
import { StoryObj } from '@storybook/react';
|
|
3
|
+
import { testsWaitForText } from '../../../__tests__/utils';
|
|
4
|
+
import { StoryMeta } from '../../types';
|
|
5
|
+
import { currentUserStore } from './currentUser';
|
|
6
|
+
|
|
7
|
+
const meta = {
|
|
8
|
+
title: 'Stores/Current User',
|
|
9
|
+
render: () => {
|
|
10
|
+
const { load, loading, currentUser = {}, errorData } = currentUserStore();
|
|
11
|
+
|
|
12
|
+
return loading ? (
|
|
13
|
+
<ReqoreSpinner />
|
|
14
|
+
) : (
|
|
15
|
+
<>
|
|
16
|
+
<ReqoreTree
|
|
17
|
+
data={errorData || currentUser}
|
|
18
|
+
bottomActions={[{ label: 'Refetch', onClick: load }]}
|
|
19
|
+
/>
|
|
20
|
+
</>
|
|
21
|
+
);
|
|
22
|
+
},
|
|
23
|
+
} as StoryMeta<any>;
|
|
24
|
+
|
|
25
|
+
export default meta;
|
|
26
|
+
export type Story = StoryObj<typeof meta>;
|
|
27
|
+
|
|
28
|
+
export const currentUserCanBeLoaded: Story = {
|
|
29
|
+
play: async () => {
|
|
30
|
+
await testsWaitForText('"David Nichols"');
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const currentUserHasPermissions: Story = {
|
|
35
|
+
...currentUserCanBeLoaded,
|
|
36
|
+
render: () => {
|
|
37
|
+
const { hasPermissions } = currentUserStore();
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<ReqoreP>
|
|
41
|
+
{hasPermissions(['SERVER-CONTROL']) ? 'Yes, user has "SERVER-CONTROL" permission' : 'No'}
|
|
42
|
+
</ReqoreP>
|
|
43
|
+
);
|
|
44
|
+
},
|
|
45
|
+
play: async () => {
|
|
46
|
+
await testsWaitForText('Yes, user has "SERVER-CONTROL" permission');
|
|
47
|
+
},
|
|
48
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { create } from 'zustand';
|
|
2
|
+
import { query } from '../../utils/fetch';
|
|
3
|
+
|
|
4
|
+
export interface ICurrentUser {
|
|
5
|
+
provider: string;
|
|
6
|
+
username: string;
|
|
7
|
+
name: string;
|
|
8
|
+
has_default: boolean;
|
|
9
|
+
roles: string[];
|
|
10
|
+
permissions: string[];
|
|
11
|
+
workflows: string[];
|
|
12
|
+
services: string[];
|
|
13
|
+
jobs: string[];
|
|
14
|
+
mappers: string[];
|
|
15
|
+
vmaps: string[];
|
|
16
|
+
groups: string[];
|
|
17
|
+
fsms: string[];
|
|
18
|
+
oauth2_clients?: Record<string, any>[];
|
|
19
|
+
storage?: Record<string, any>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ICurrentUserStore {
|
|
23
|
+
currentUser?: ICurrentUser;
|
|
24
|
+
load: () => Promise<ICurrentUser>;
|
|
25
|
+
loading?: boolean;
|
|
26
|
+
|
|
27
|
+
error?: Error;
|
|
28
|
+
errorData?: any;
|
|
29
|
+
|
|
30
|
+
hasPermissions: (permissions: string[]) => boolean;
|
|
31
|
+
updateStorage: (storage: Record<string, any>) => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const currentUserStore = create<ICurrentUserStore>((set, get) => ({
|
|
35
|
+
currentUser: undefined,
|
|
36
|
+
loading: false,
|
|
37
|
+
error: undefined,
|
|
38
|
+
load: async () => {
|
|
39
|
+
set({ loading: true });
|
|
40
|
+
|
|
41
|
+
const response = await query<ICurrentUser>({ url: 'users?action=current', cache: false });
|
|
42
|
+
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
set({
|
|
45
|
+
loading: false,
|
|
46
|
+
error: response.error,
|
|
47
|
+
currentUser: undefined,
|
|
48
|
+
errorData: response.data,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return Promise.reject(response.error);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
set({ currentUser: response.data, loading: false, errorData: undefined, error: undefined });
|
|
55
|
+
|
|
56
|
+
return response.data;
|
|
57
|
+
},
|
|
58
|
+
hasPermissions: (permissions) => {
|
|
59
|
+
if (!get().currentUser) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const { currentUser } = get();
|
|
64
|
+
|
|
65
|
+
return permissions.every((permission) => currentUser.permissions?.includes(permission));
|
|
66
|
+
},
|
|
67
|
+
updateStorage: (storage) => {
|
|
68
|
+
set((state) => ({ currentUser: { ...state.currentUser, storage } }));
|
|
69
|
+
},
|
|
70
|
+
}));
|