@j2inn/resolvable-ui-elements 0.0.2-beta.4 → 0.0.2-beta.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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/resolvableElements/Resolver.d.ts +4 -1
- package/dist/resolvableElements/Resolver.js +5 -2
- package/dist/resolvableElements/Resolver.js.map +1 -1
- package/dist/resolvableElements/elements/UiElement.js +4 -4
- package/dist/resolvableElements/elements/UiElement.js.map +1 -1
- package/dist/resolvableElements/react/SectionChecker.d.ts +27 -0
- package/dist/resolvableElements/react/SectionChecker.jsx +31 -0
- package/dist/resolvableElements/react/SectionChecker.jsx.map +1 -0
- package/dist/resolvableElements/react/useResolverContext.d.ts +5 -1
- package/dist/resolvableElements/react/useResolverContext.jsx +4 -4
- package/dist/resolvableElements/react/useResolverContext.jsx.map +1 -1
- package/dist_es/index.d.ts +1 -0
- package/dist_es/index.js +1 -0
- package/dist_es/index.js.map +1 -1
- package/dist_es/resolvableElements/Resolver.d.ts +4 -1
- package/dist_es/resolvableElements/Resolver.js +4 -1
- package/dist_es/resolvableElements/Resolver.js.map +1 -1
- package/dist_es/resolvableElements/elements/UiElement.js +4 -4
- package/dist_es/resolvableElements/elements/UiElement.js.map +1 -1
- package/dist_es/resolvableElements/react/SectionChecker.d.ts +27 -0
- package/dist_es/resolvableElements/react/SectionChecker.jsx +24 -0
- package/dist_es/resolvableElements/react/SectionChecker.jsx.map +1 -0
- package/dist_es/resolvableElements/react/useResolverContext.d.ts +5 -1
- package/dist_es/resolvableElements/react/useResolverContext.jsx +4 -4
- package/dist_es/resolvableElements/react/useResolverContext.jsx.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { type FunctionResult } from './resolvableElements/elements/function/FunctionElement';
|
|
2
2
|
export { isSectionData, type ParametersOfSection, type ResolvedSection, } from './resolvableElements/elements/section/SectionElementMeta';
|
|
3
3
|
export { type UiElementData } from './resolvableElements/elements/UiElement';
|
|
4
|
+
export * from './resolvableElements/react/SectionChecker';
|
|
4
5
|
export * from './resolvableElements/react/useResolverContext';
|
|
5
6
|
export * from './resolvableElements/react/useResolveSection';
|
|
6
7
|
export * from './useCurrentUser';
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ Object.defineProperty(exports, "isSectionData", { enumerable: true, get: functio
|
|
|
23
23
|
//////////////////////////////////////////////////////////////////////////
|
|
24
24
|
// React
|
|
25
25
|
//////////////////////////////////////////////////////////////////////////
|
|
26
|
+
__exportStar(require("./resolvableElements/react/SectionChecker"), exports);
|
|
26
27
|
__exportStar(require("./resolvableElements/react/useResolverContext"), exports);
|
|
27
28
|
__exportStar(require("./resolvableElements/react/useResolveSection"), exports);
|
|
28
29
|
//////////////////////////////////////////////////////////////////////////
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;AAMH,+FAIiE;AAHhE,mHAAA,aAAa,OAAA;AAKd,0EAA0E;AAC1E,QAAQ;AACR,0EAA0E;AAC1E,gFAA6D;AAC7D,+EAA4D;AAC5D,0EAA0E;AAC1E,QAAQ;AACR,0EAA0E;AAC1E,mDAAgC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;AAMH,+FAIiE;AAHhE,mHAAA,aAAa,OAAA;AAKd,0EAA0E;AAC1E,QAAQ;AACR,0EAA0E;AAC1E,4EAAyD;AACzD,gFAA6D;AAC7D,+EAA4D;AAC5D,0EAA0E;AAC1E,QAAQ;AACR,0EAA0E;AAC1E,mDAAgC"}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { HDict, HGrid } from 'haystack-core';
|
|
2
2
|
import { Client, Watch } from 'haystack-nclient';
|
|
3
|
+
export declare const DEFAULT_USER_ROLE_TAG_NAME = "uiElementPermissions";
|
|
3
4
|
export interface ResolverData {
|
|
4
5
|
client: Client;
|
|
5
6
|
user?: HDict;
|
|
7
|
+
userRoleTagName?: string;
|
|
6
8
|
}
|
|
7
9
|
/**
|
|
8
10
|
* Resolver is a mediator for the network interactions during the resolution process,
|
|
9
11
|
* in order to enable future optimizations.
|
|
10
12
|
*/
|
|
11
13
|
export declare class Resolver {
|
|
12
|
-
constructor({ client, user }: ResolverData);
|
|
14
|
+
constructor({ client, user, userRoleTagName, }: ResolverData);
|
|
13
15
|
client: Client;
|
|
14
16
|
user?: HDict;
|
|
17
|
+
userRoleTagName?: string;
|
|
15
18
|
read(filter: string): Promise<HGrid<HDict>>;
|
|
16
19
|
makeWatch(dis: string, grid: HGrid<HDict>): Promise<Watch>;
|
|
17
20
|
eval(expr: string): Promise<HGrid<HDict>>;
|
|
@@ -3,18 +3,21 @@
|
|
|
3
3
|
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Resolver = void 0;
|
|
6
|
+
exports.Resolver = exports.DEFAULT_USER_ROLE_TAG_NAME = void 0;
|
|
7
|
+
exports.DEFAULT_USER_ROLE_TAG_NAME = 'uiElementPermissions';
|
|
7
8
|
/**
|
|
8
9
|
* Resolver is a mediator for the network interactions during the resolution process,
|
|
9
10
|
* in order to enable future optimizations.
|
|
10
11
|
*/
|
|
11
12
|
class Resolver {
|
|
12
|
-
constructor({ client, user }) {
|
|
13
|
+
constructor({ client, user, userRoleTagName = exports.DEFAULT_USER_ROLE_TAG_NAME, }) {
|
|
13
14
|
this.client = client;
|
|
14
15
|
this.user = user;
|
|
16
|
+
this.userRoleTagName = userRoleTagName;
|
|
15
17
|
}
|
|
16
18
|
client;
|
|
17
19
|
user;
|
|
20
|
+
userRoleTagName;
|
|
18
21
|
async read(filter) {
|
|
19
22
|
return this.client.ext.read(filter);
|
|
20
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Resolver.js","sourceRoot":"","sources":["../../src/resolvableElements/Resolver.ts"],"names":[],"mappings":";AAAA;;GAEG;;;
|
|
1
|
+
{"version":3,"file":"Resolver.js","sourceRoot":"","sources":["../../src/resolvableElements/Resolver.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAKU,QAAA,0BAA0B,GAAG,sBAAsB,CAAA;AAQhE;;;GAGG;AACH,MAAa,QAAQ;IACpB,YAAY,EACX,MAAM,EACN,IAAI,EACJ,eAAe,GAAG,kCAA0B,GAC9B;QACd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;IACvC,CAAC;IAED,MAAM,CAAQ;IACd,IAAI,CAAQ;IACZ,eAAe,CAAS;IAExB,KAAK,CAAC,IAAI,CAAC,MAAc;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACpC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,GAAW,EAAE,IAAkB;QAC9C,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAC7C,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAY;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC;CACD;AA1BD,4BA0BC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.UiElement = void 0;
|
|
7
|
-
const
|
|
7
|
+
const Resolver_1 = require("../Resolver");
|
|
8
8
|
/**
|
|
9
9
|
* Base UiElement class
|
|
10
10
|
*/
|
|
@@ -25,7 +25,7 @@ class UiElement {
|
|
|
25
25
|
console.log(this);
|
|
26
26
|
}
|
|
27
27
|
isAccessAllowed(meta) {
|
|
28
|
-
return UiElement.#isElementAccessible(meta, this.resolver.user);
|
|
28
|
+
return UiElement.#isElementAccessible(meta, this.resolver.user, this.resolver.userRoleTagName);
|
|
29
29
|
}
|
|
30
30
|
_value;
|
|
31
31
|
get value() {
|
|
@@ -36,11 +36,11 @@ class UiElement {
|
|
|
36
36
|
this.onUpdate(value);
|
|
37
37
|
}
|
|
38
38
|
onUpdate;
|
|
39
|
-
static #isElementAccessible(meta, user) {
|
|
39
|
+
static #isElementAccessible(meta, user, userRoleTagName = Resolver_1.DEFAULT_USER_ROLE_TAG_NAME) {
|
|
40
40
|
if (!meta || !meta.access || UiElement.#isSuperuser(user)) {
|
|
41
41
|
return true;
|
|
42
42
|
}
|
|
43
|
-
const userRole = user?.get(
|
|
43
|
+
const userRole = user?.get(userRoleTagName);
|
|
44
44
|
if (userRole && meta.access.includes(userRole.value)) {
|
|
45
45
|
return true;
|
|
46
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UiElement.js","sourceRoot":"","sources":["../../../src/resolvableElements/elements/UiElement.ts"],"names":[],"mappings":";AAAA;;GAEG;;;
|
|
1
|
+
{"version":3,"file":"UiElement.js","sourceRoot":"","sources":["../../../src/resolvableElements/elements/UiElement.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAGH,0CAAkE;AAiBlE;;GAEG;AACH,MAAsB,SAAS;IAC9B,YAAY,EACX,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,QAAQ,GACqB;QAC7B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,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AAC,WAAW,CAAC,GAAG,MAA8B;QACnD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACvD,CAAC;CACD;AArED,8BAqEC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { UiElementData } from 'resolvableElements/elements/UiElement';
|
|
3
|
+
/**
|
|
4
|
+
* An utility type that allows a component to accept props with or without a 'section' property.
|
|
5
|
+
*/
|
|
6
|
+
export declare type OptionalSection<P> = P | (Omit<P, 'section'> & {
|
|
7
|
+
section?: undefined;
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Higher-Order Component that takes a section based component as an argument and returns a new component
|
|
11
|
+
* that checks if the 'section' prop is defined before rendering the SectionComponent.
|
|
12
|
+
* If the 'section' prop is undefined, it returns an empty element.
|
|
13
|
+
*
|
|
14
|
+
*
|
|
15
|
+
*
|
|
16
|
+
* @template P - Props of the original SectionComponent
|
|
17
|
+
* @param {React.FC<P>} SectionComponent - The original component that will be wrapped
|
|
18
|
+
* @returns {React.FC<P | (Omit<P, 'section'> & { section?: undefined })>} - The wrapped component
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const CheckedComponent = SectionChecker(({section, ...props}) => {
|
|
22
|
+
* return <div>{section.title}</div>
|
|
23
|
+
* })
|
|
24
|
+
*/
|
|
25
|
+
export declare const SectionChecker: <P extends {
|
|
26
|
+
section: UiElementData;
|
|
27
|
+
}>(SectionComponent: React.FC<P>) => (props: OptionalSection<P>) => JSX.Element;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SectionChecker = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
/**
|
|
9
|
+
* Higher-Order Component that takes a section based component as an argument and returns a new component
|
|
10
|
+
* that checks if the 'section' prop is defined before rendering the SectionComponent.
|
|
11
|
+
* If the 'section' prop is undefined, it returns an empty element.
|
|
12
|
+
*
|
|
13
|
+
*
|
|
14
|
+
*
|
|
15
|
+
* @template P - Props of the original SectionComponent
|
|
16
|
+
* @param {React.FC<P>} SectionComponent - The original component that will be wrapped
|
|
17
|
+
* @returns {React.FC<P | (Omit<P, 'section'> & { section?: undefined })>} - The wrapped component
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const CheckedComponent = SectionChecker(({section, ...props}) => {
|
|
21
|
+
* return <div>{section.title}</div>
|
|
22
|
+
* })
|
|
23
|
+
*/
|
|
24
|
+
const SectionChecker = (SectionComponent) => {
|
|
25
|
+
const CheckedSectionComponent = (props) => {
|
|
26
|
+
return !props.section ? <></> : <SectionComponent {...props}/>;
|
|
27
|
+
};
|
|
28
|
+
return CheckedSectionComponent;
|
|
29
|
+
};
|
|
30
|
+
exports.SectionChecker = SectionChecker;
|
|
31
|
+
//# sourceMappingURL=SectionChecker.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SectionChecker.jsx","sourceRoot":"","sources":["../../../src/resolvableElements/react/SectionChecker.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AAUzB;;;;;;;;;;;;;;;GAeG;AACI,MAAM,cAAc,GAAG,CAC7B,gBAA6B,EAC5B,EAAE;IACH,MAAM,uBAAuB,GAAG,CAAC,KAAyB,EAAE,EAAE;QAC7D,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,EAAG,CAAA;IAChE,CAAC,CAAA;IAED,OAAO,uBAAuB,CAAA;AAC/B,CAAC,CAAA;AARY,QAAA,cAAc,kBAQ1B"}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from 'react';
|
|
2
2
|
import { Resolver } from '../Resolver';
|
|
3
3
|
export declare function useResolverContext(): Resolver;
|
|
4
|
-
|
|
4
|
+
interface ResolverProviderProps extends PropsWithChildren {
|
|
5
|
+
userRoleTagName?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const ResolverProvider: React.FC<ResolverProviderProps>;
|
|
8
|
+
export {};
|
|
@@ -42,13 +42,13 @@ function useResolverContext() {
|
|
|
42
42
|
return (0, react_1.useContext)(ResolverContext);
|
|
43
43
|
}
|
|
44
44
|
exports.useResolverContext = useResolverContext;
|
|
45
|
-
const ResolverProvider = ({ children }) => {
|
|
45
|
+
const ResolverProvider = ({ userRoleTagName, children, }) => {
|
|
46
46
|
const client = (0, haystack_react_1.useClient)();
|
|
47
47
|
const user = (0, useCurrentUser_1.useCurrentUser)();
|
|
48
|
-
const [resolver, setResolver] = (0, react_1.useState)(() => new Resolver_1.Resolver({ client, user }));
|
|
48
|
+
const [resolver, setResolver] = (0, react_1.useState)(() => new Resolver_1.Resolver({ client, user, userRoleTagName }));
|
|
49
49
|
(0, react_1.useEffect)(() => {
|
|
50
|
-
setResolver(new Resolver_1.Resolver({ client, user }));
|
|
51
|
-
}, [client, user]);
|
|
50
|
+
setResolver(new Resolver_1.Resolver({ client, user, userRoleTagName }));
|
|
51
|
+
}, [client, user, userRoleTagName]);
|
|
52
52
|
return (<ResolverContext.Provider value={resolver}>
|
|
53
53
|
{children}
|
|
54
54
|
</ResolverContext.Provider>);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useResolverContext.jsx","sourceRoot":"","sources":["../../../src/resolvableElements/react/useResolverContext.tsx"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uDAAyC;AACzC,mDAA0C;AAC1C,+CAKc;AACd,yDAAqD;AACrD,0CAAsC;AAEtC,MA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Ae,EAAE,CAAC,CACrD,CAAA;IAED,IAAA,iBAAS,EAAC,GAAG,EAAE;QACd,WAAW,CAAC,IAAI,mBAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC,CAAC,CAAA;IAC7D,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC,CAAA;IAEnC,OAAO,CACN,CAAC,eAAe,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CACzC;GAAA,CAAC,QAAQ,CACV;EAAA,EAAE,eAAe,CAAC,QAAQ,CAAC,CAC3B,CAAA;AACF,CAAC,CAAA;AApBY,QAAA,gBAAgB,oBAoB5B"}
|
package/dist_es/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { type FunctionResult } from './resolvableElements/elements/function/FunctionElement';
|
|
2
2
|
export { isSectionData, type ParametersOfSection, type ResolvedSection, } from './resolvableElements/elements/section/SectionElementMeta';
|
|
3
3
|
export { type UiElementData } from './resolvableElements/elements/UiElement';
|
|
4
|
+
export * from './resolvableElements/react/SectionChecker';
|
|
4
5
|
export * from './resolvableElements/react/useResolverContext';
|
|
5
6
|
export * from './resolvableElements/react/useResolveSection';
|
|
6
7
|
export * from './useCurrentUser';
|
package/dist_es/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export { isSectionData, } from './resolvableElements/elements/section/SectionEle
|
|
|
5
5
|
//////////////////////////////////////////////////////////////////////////
|
|
6
6
|
// React
|
|
7
7
|
//////////////////////////////////////////////////////////////////////////
|
|
8
|
+
export * from './resolvableElements/react/SectionChecker';
|
|
8
9
|
export * from './resolvableElements/react/useResolverContext';
|
|
9
10
|
export * from './resolvableElements/react/useResolveSection';
|
|
10
11
|
//////////////////////////////////////////////////////////////////////////
|
package/dist_es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EACN,aAAa,GAGb,MAAM,0DAA0D,CAAA;AAEjE,0EAA0E;AAC1E,QAAQ;AACR,0EAA0E;AAC1E,cAAc,+CAA+C,CAAA;AAC7D,cAAc,8CAA8C,CAAA;AAC5D,0EAA0E;AAC1E,QAAQ;AACR,0EAA0E;AAC1E,cAAc,kBAAkB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EACN,aAAa,GAGb,MAAM,0DAA0D,CAAA;AAEjE,0EAA0E;AAC1E,QAAQ;AACR,0EAA0E;AAC1E,cAAc,2CAA2C,CAAA;AACzD,cAAc,+CAA+C,CAAA;AAC7D,cAAc,8CAA8C,CAAA;AAC5D,0EAA0E;AAC1E,QAAQ;AACR,0EAA0E;AAC1E,cAAc,kBAAkB,CAAA"}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { HDict, HGrid } from 'haystack-core';
|
|
2
2
|
import { Client, Watch } from 'haystack-nclient';
|
|
3
|
+
export declare const DEFAULT_USER_ROLE_TAG_NAME = "uiElementPermissions";
|
|
3
4
|
export interface ResolverData {
|
|
4
5
|
client: Client;
|
|
5
6
|
user?: HDict;
|
|
7
|
+
userRoleTagName?: string;
|
|
6
8
|
}
|
|
7
9
|
/**
|
|
8
10
|
* Resolver is a mediator for the network interactions during the resolution process,
|
|
9
11
|
* in order to enable future optimizations.
|
|
10
12
|
*/
|
|
11
13
|
export declare class Resolver {
|
|
12
|
-
constructor({ client, user }: ResolverData);
|
|
14
|
+
constructor({ client, user, userRoleTagName, }: ResolverData);
|
|
13
15
|
client: Client;
|
|
14
16
|
user?: HDict;
|
|
17
|
+
userRoleTagName?: string;
|
|
15
18
|
read(filter: string): Promise<HGrid<HDict>>;
|
|
16
19
|
makeWatch(dis: string, grid: HGrid<HDict>): Promise<Watch>;
|
|
17
20
|
eval(expr: string): Promise<HGrid<HDict>>;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
|
|
3
3
|
*/
|
|
4
|
+
export const DEFAULT_USER_ROLE_TAG_NAME = 'uiElementPermissions';
|
|
4
5
|
/**
|
|
5
6
|
* Resolver is a mediator for the network interactions during the resolution process,
|
|
6
7
|
* in order to enable future optimizations.
|
|
7
8
|
*/
|
|
8
9
|
export class Resolver {
|
|
9
|
-
constructor({ client, user }) {
|
|
10
|
+
constructor({ client, user, userRoleTagName = DEFAULT_USER_ROLE_TAG_NAME, }) {
|
|
10
11
|
this.client = client;
|
|
11
12
|
this.user = user;
|
|
13
|
+
this.userRoleTagName = userRoleTagName;
|
|
12
14
|
}
|
|
13
15
|
client;
|
|
14
16
|
user;
|
|
17
|
+
userRoleTagName;
|
|
15
18
|
async read(filter) {
|
|
16
19
|
return this.client.ext.read(filter);
|
|
17
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Resolver.js","sourceRoot":"","sources":["../../src/resolvableElements/Resolver.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"Resolver.js","sourceRoot":"","sources":["../../src/resolvableElements/Resolver.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,MAAM,CAAC,MAAM,0BAA0B,GAAG,sBAAsB,CAAA;AAQhE;;;GAGG;AACH,MAAM,OAAO,QAAQ;IACpB,YAAY,EACX,MAAM,EACN,IAAI,EACJ,eAAe,GAAG,0BAA0B,GAC9B;QACd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;IACvC,CAAC;IAED,MAAM,CAAQ;IACd,IAAI,CAAQ;IACZ,eAAe,CAAS;IAExB,KAAK,CAAC,IAAI,CAAC,MAAc;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACpC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,GAAW,EAAE,IAAkB;QAC9C,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAC7C,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAY;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC;CACD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Copyright (c) 2022, J2 Innovations. All Rights Reserved
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
import { DEFAULT_USER_ROLE_TAG_NAME } from '../Resolver';
|
|
5
5
|
/**
|
|
6
6
|
* Base UiElement class
|
|
7
7
|
*/
|
|
@@ -22,7 +22,7 @@ export class UiElement {
|
|
|
22
22
|
console.log(this);
|
|
23
23
|
}
|
|
24
24
|
isAccessAllowed(meta) {
|
|
25
|
-
return UiElement.#isElementAccessible(meta, this.resolver.user);
|
|
25
|
+
return UiElement.#isElementAccessible(meta, this.resolver.user, this.resolver.userRoleTagName);
|
|
26
26
|
}
|
|
27
27
|
_value;
|
|
28
28
|
get value() {
|
|
@@ -33,11 +33,11 @@ export class UiElement {
|
|
|
33
33
|
this.onUpdate(value);
|
|
34
34
|
}
|
|
35
35
|
onUpdate;
|
|
36
|
-
static #isElementAccessible(meta, user) {
|
|
36
|
+
static #isElementAccessible(meta, user, userRoleTagName = DEFAULT_USER_ROLE_TAG_NAME) {
|
|
37
37
|
if (!meta || !meta.access || UiElement.#isSuperuser(user)) {
|
|
38
38
|
return true;
|
|
39
39
|
}
|
|
40
|
-
const userRole = user?.get(
|
|
40
|
+
const userRole = user?.get(userRoleTagName);
|
|
41
41
|
if (userRole && meta.access.includes(userRole.value)) {
|
|
42
42
|
return true;
|
|
43
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UiElement.js","sourceRoot":"","sources":["../../../src/resolvableElements/elements/UiElement.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"UiElement.js","sourceRoot":"","sources":["../../../src/resolvableElements/elements/UiElement.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,0BAA0B,EAAY,MAAM,aAAa,CAAA;AAiBlE;;GAEG;AACH,MAAM,OAAgB,SAAS;IAC9B,YAAY,EACX,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,QAAQ,GACqB;QAC7B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IACzB,CAAC;IACD,QAAQ,CAAU;IAElB,KAAK,CAAgB;IAErB,IAAI,CAAS;IAEb,MAAM;QACL,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAA;IAC7B,CAAC;IACD,OAAO;QACN,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAClB,CAAC;IAED,eAAe,CAAC,IAAoB;QACnC,OAAO,SAAS,CAAC,oBAAoB,CACpC,IAAI,EACJ,IAAI,CAAC,QAAQ,CAAC,IAAI,EAClB,IAAI,CAAC,QAAQ,CAAC,eAAe,CAC7B,CAAA;IACF,CAAC;IAES,MAAM,CAAU;IAE1B,IAAI,KAAK;QACR,OAAO,IAAI,CAAC,MAAM,CAAA;IACnB,CAAC;IAED,IAAI,KAAK,CAAC,KAA0B;QACnC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IACrB,CAAC;IACD,QAAQ,CAAsC;IAE9C,MAAM,CAAC,oBAAoB,CAC1B,IAAoB,EACpB,IAAY,EACZ,eAAe,GAAG,0BAA0B;QAE5C,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE;YAC1D,OAAO,IAAI,CAAA;SACX;QAED,MAAM,QAAQ,GAAG,IAAI,EAAE,GAAG,CAAO,eAAe,CAAC,CAAA;QACjD,IAAI,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;YACrD,OAAO,IAAI,CAAA;SACX;QAED,OAAO,KAAK,CAAA;IACb,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,IAAY;QAC/B,OAAO,IAAI,EAAE,GAAG,CAAO,UAAU,CAAC,EAAE,KAAK,KAAK,IAAI,CAAA;IACnD,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,GAAG,MAA8B;QACnD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACvD,CAAC;CACD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { UiElementData } from 'resolvableElements/elements/UiElement';
|
|
3
|
+
/**
|
|
4
|
+
* An utility type that allows a component to accept props with or without a 'section' property.
|
|
5
|
+
*/
|
|
6
|
+
export declare type OptionalSection<P> = P | (Omit<P, 'section'> & {
|
|
7
|
+
section?: undefined;
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Higher-Order Component that takes a section based component as an argument and returns a new component
|
|
11
|
+
* that checks if the 'section' prop is defined before rendering the SectionComponent.
|
|
12
|
+
* If the 'section' prop is undefined, it returns an empty element.
|
|
13
|
+
*
|
|
14
|
+
*
|
|
15
|
+
*
|
|
16
|
+
* @template P - Props of the original SectionComponent
|
|
17
|
+
* @param {React.FC<P>} SectionComponent - The original component that will be wrapped
|
|
18
|
+
* @returns {React.FC<P | (Omit<P, 'section'> & { section?: undefined })>} - The wrapped component
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const CheckedComponent = SectionChecker(({section, ...props}) => {
|
|
22
|
+
* return <div>{section.title}</div>
|
|
23
|
+
* })
|
|
24
|
+
*/
|
|
25
|
+
export declare const SectionChecker: <P extends {
|
|
26
|
+
section: UiElementData;
|
|
27
|
+
}>(SectionComponent: React.FC<P>) => (props: OptionalSection<P>) => JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Higher-Order Component that takes a section based component as an argument and returns a new component
|
|
4
|
+
* that checks if the 'section' prop is defined before rendering the SectionComponent.
|
|
5
|
+
* If the 'section' prop is undefined, it returns an empty element.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
*
|
|
9
|
+
* @template P - Props of the original SectionComponent
|
|
10
|
+
* @param {React.FC<P>} SectionComponent - The original component that will be wrapped
|
|
11
|
+
* @returns {React.FC<P | (Omit<P, 'section'> & { section?: undefined })>} - The wrapped component
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const CheckedComponent = SectionChecker(({section, ...props}) => {
|
|
15
|
+
* return <div>{section.title}</div>
|
|
16
|
+
* })
|
|
17
|
+
*/
|
|
18
|
+
export const SectionChecker = (SectionComponent) => {
|
|
19
|
+
const CheckedSectionComponent = (props) => {
|
|
20
|
+
return !props.section ? <></> : <SectionComponent {...props}/>;
|
|
21
|
+
};
|
|
22
|
+
return CheckedSectionComponent;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=SectionChecker.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SectionChecker.jsx","sourceRoot":"","sources":["../../../src/resolvableElements/react/SectionChecker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAUzB;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC7B,gBAA6B,EAC5B,EAAE;IACH,MAAM,uBAAuB,GAAG,CAAC,KAAyB,EAAE,EAAE;QAC7D,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,EAAG,CAAA;IAChE,CAAC,CAAA;IAED,OAAO,uBAAuB,CAAA;AAC/B,CAAC,CAAA"}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from 'react';
|
|
2
2
|
import { Resolver } from '../Resolver';
|
|
3
3
|
export declare function useResolverContext(): Resolver;
|
|
4
|
-
|
|
4
|
+
interface ResolverProviderProps extends PropsWithChildren {
|
|
5
|
+
userRoleTagName?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const ResolverProvider: React.FC<ResolverProviderProps>;
|
|
8
|
+
export {};
|
|
@@ -15,13 +15,13 @@ ResolverContext.displayName = 'ResolverContext';
|
|
|
15
15
|
export function useResolverContext() {
|
|
16
16
|
return useContext(ResolverContext);
|
|
17
17
|
}
|
|
18
|
-
export const ResolverProvider = ({ children }) => {
|
|
18
|
+
export const ResolverProvider = ({ userRoleTagName, children, }) => {
|
|
19
19
|
const client = useClient();
|
|
20
20
|
const user = useCurrentUser();
|
|
21
|
-
const [resolver, setResolver] = useState(() => new Resolver({ client, user }));
|
|
21
|
+
const [resolver, setResolver] = useState(() => new Resolver({ client, user, userRoleTagName }));
|
|
22
22
|
useEffect(() => {
|
|
23
|
-
setResolver(new Resolver({ client, user }));
|
|
24
|
-
}, [client, user]);
|
|
23
|
+
setResolver(new Resolver({ client, user, userRoleTagName }));
|
|
24
|
+
}, [client, user, userRoleTagName]);
|
|
25
25
|
return (<ResolverContext.Provider value={resolver}>
|
|
26
26
|
{children}
|
|
27
27
|
</ResolverContext.Provider>);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useResolverContext.jsx","sourceRoot":"","sources":["../../../src/resolvableElements/react/useResolverContext.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,EAAE,EAEb,UAAU,EACV,SAAS,EACT,QAAQ,GACR,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,MAAM,eAAe,GAAG,KAAK,CAAC,aAAa,CAC1C,IAAI,QAAQ,CAAC;IACZ,MAAM,EAAE,IAAI,MAAM,CAAC;QAClB,IAAI,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;KACnC,CAAC;CACF,CAAC,CACF,CAAA;AAED,eAAe,CAAC,WAAW,GAAG,iBAAiB,CAAA;AAE/C,MAAM,UAAU,kBAAkB;IACjC,OAAO,UAAU,CAAC,eAAe,CAAC,CAAA;AACnC,CAAC;
|
|
1
|
+
{"version":3,"file":"useResolverContext.jsx","sourceRoot":"","sources":["../../../src/resolvableElements/react/useResolverContext.tsx"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,EAAE,EAEb,UAAU,EACV,SAAS,EACT,QAAQ,GACR,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,MAAM,eAAe,GAAG,KAAK,CAAC,aAAa,CAC1C,IAAI,QAAQ,CAAC;IACZ,MAAM,EAAE,IAAI,MAAM,CAAC;QAClB,IAAI,EAAE,IA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