@redhat-cloud-services/frontend-components-utilities 3.2.23 → 3.2.24

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/RBAC/RBAC.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { Access } from '@redhat-cloud-services/rbac-client';
2
3
  import type { ChromeAPI } from '@redhat-cloud-services/types';
3
4
  declare global {
@@ -12,6 +13,18 @@ export interface RBAC {
12
13
  permissions: Access[];
13
14
  }
14
15
  export declare function getRBAC(applicationName?: string, disableCache?: boolean): Promise<RBAC>;
15
- export declare function doesHavePermissions(userPermissions: (Access | string)[], permissionList: string[]): boolean;
16
- export declare function hasAllPermissions(userPermissions: (Access | string)[], permissionList: string[]): boolean;
16
+ export declare function doesHavePermissions(userPermissions: (Access | string)[], permissionList: (Access | string)[]): boolean;
17
+ export declare function hasAllPermissions(userPermissions: (Access | string)[], permissionList: (Access | string)[]): boolean;
18
+ export interface UsePermissionsState extends RBAC {
19
+ isLoading: boolean;
20
+ hasAccess?: boolean;
21
+ }
22
+ export interface UsePermissionsContextState {
23
+ isLoading?: boolean;
24
+ isOrgAdmin: boolean;
25
+ permissions: (string | Access)[];
26
+ hasAccess?: (requiredPermissions: string[], checkAll?: boolean) => boolean;
27
+ }
28
+ export declare const initialPermissions: UsePermissionsContextState;
29
+ export declare const RBACContext: import("react").Context<UsePermissionsContextState>;
17
30
  export default getRBAC;
package/RBAC/RBAC.js CHANGED
@@ -36,7 +36,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.hasAllPermissions = exports.doesHavePermissions = exports.getRBAC = void 0;
39
+ exports.RBACContext = exports.initialPermissions = exports.hasAllPermissions = exports.doesHavePermissions = exports.getRBAC = void 0;
40
+ var react_1 = require("react");
40
41
  function getRBAC(applicationName, disableCache) {
41
42
  var _a, _b, _c, _d, _e;
42
43
  if (applicationName === void 0) { applicationName = ''; }
@@ -95,5 +96,11 @@ function hasAllPermissions(userPermissions, permissionList) {
95
96
  });
96
97
  }
97
98
  exports.hasAllPermissions = hasAllPermissions;
99
+ exports.initialPermissions = {
100
+ isLoading: true,
101
+ isOrgAdmin: false,
102
+ permissions: [],
103
+ };
104
+ exports.RBACContext = (0, react_1.createContext)(exports.initialPermissions);
98
105
  exports.default = getRBAC;
99
106
  //# sourceMappingURL=RBAC.js.map
@@ -1,7 +1,9 @@
1
- import { RBAC } from '../RBAC';
2
- export interface UsePermissionsState extends RBAC {
3
- hasAccess: boolean;
4
- isLoading: boolean;
5
- }
1
+ import { UsePermissionsState } from '../RBAC';
6
2
  export declare function usePermissions(appName: string, permissionsList: string[], disableCache?: boolean, checkAll?: boolean): UsePermissionsState;
3
+ export declare const usePermissionsWithContext: (requiredPermissions: string[]) => {
4
+ hasAccess: boolean;
5
+ isLoading?: boolean | undefined;
6
+ isOrgAdmin: boolean;
7
+ permissions: (string | import("@redhat-cloud-services/rbac-client").Access)[];
8
+ };
7
9
  export default usePermissions;
@@ -46,8 +46,19 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
+ var __rest = (this && this.__rest) || function (s, e) {
50
+ var t = {};
51
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
+ t[p] = s[p];
53
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
+ t[p[i]] = s[p[i]];
57
+ }
58
+ return t;
59
+ };
49
60
  Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.usePermissions = void 0;
61
+ exports.usePermissionsWithContext = exports.usePermissions = void 0;
51
62
  var react_1 = require("react");
52
63
  var RBAC_1 = require("../RBAC");
53
64
  function usePermissions(appName, permissionsList, disableCache, checkAll) {
@@ -86,5 +97,10 @@ function usePermissions(appName, permissionsList, disableCache, checkAll) {
86
97
  return permissions;
87
98
  }
88
99
  exports.usePermissions = usePermissions;
100
+ var usePermissionsWithContext = function (requiredPermissions) {
101
+ var _a = (0, react_1.useContext)(RBAC_1.RBACContext), hasAccess = _a.hasAccess, permissionState = __rest(_a, ["hasAccess"]);
102
+ return __assign(__assign({}, permissionState), { hasAccess: (hasAccess === null || hasAccess === void 0 ? void 0 : hasAccess(requiredPermissions)) || false });
103
+ };
104
+ exports.usePermissionsWithContext = usePermissionsWithContext;
89
105
  exports.default = usePermissions;
90
106
  //# sourceMappingURL=RBACHook.js.map
package/esm/RBAC/RBAC.js CHANGED
@@ -34,6 +34,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
+ import { createContext } from 'react';
37
38
  export function getRBAC(applicationName, disableCache) {
38
39
  var _a, _b, _c, _d, _e;
39
40
  if (applicationName === void 0) { applicationName = ''; }
@@ -89,5 +90,11 @@ export function hasAllPermissions(userPermissions, permissionList) {
89
90
  });
90
91
  });
91
92
  }
93
+ export var initialPermissions = {
94
+ isLoading: true,
95
+ isOrgAdmin: false,
96
+ permissions: [],
97
+ };
98
+ export var RBACContext = createContext(initialPermissions);
92
99
  export default getRBAC;
93
100
  //# sourceMappingURL=RBAC.js.map
@@ -45,8 +45,19 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
- import { useEffect, useState } from 'react';
49
- import { doesHavePermissions, getRBAC, hasAllPermissions } from '../RBAC';
48
+ var __rest = (this && this.__rest) || function (s, e) {
49
+ var t = {};
50
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
51
+ t[p] = s[p];
52
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
53
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
54
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
55
+ t[p[i]] = s[p[i]];
56
+ }
57
+ return t;
58
+ };
59
+ import { useContext, useEffect, useState } from 'react';
60
+ import { RBACContext, doesHavePermissions, getRBAC, hasAllPermissions } from '../RBAC';
50
61
  export function usePermissions(appName, permissionsList, disableCache, checkAll) {
51
62
  var _this = this;
52
63
  var _a = useState({
@@ -82,5 +93,9 @@ export function usePermissions(appName, permissionsList, disableCache, checkAll)
82
93
  }, [appName, disableCache]);
83
94
  return permissions;
84
95
  }
96
+ export var usePermissionsWithContext = function (requiredPermissions) {
97
+ var _a = useContext(RBACContext), hasAccess = _a.hasAccess, permissionState = __rest(_a, ["hasAccess"]);
98
+ return __assign(__assign({}, permissionState), { hasAccess: (hasAccess === null || hasAccess === void 0 ? void 0 : hasAccess(requiredPermissions)) || false });
99
+ };
85
100
  export default usePermissions;
86
101
  //# sourceMappingURL=RBACHook.js.map
@@ -103,7 +103,7 @@ import { ToolbarContent } from "@patternfly/react-core/dist/esm/components/Toolb
103
103
  import { ToolbarGroup } from "@patternfly/react-core/dist/esm/components/Toolbar/ToolbarGroup";
104
104
  import { TextInput } from "@patternfly/react-core/dist/esm/components/TextInput/TextInput";
105
105
  import { ChipGroup } from "@patternfly/react-core/dist/esm/components/ChipGroup/ChipGroup";
106
- import { Chip } from "@patternfly/react-core/dist/esm/components/ChipGroup/Chip";
106
+ import { Chip } from "@patternfly/react-core/dist/esm/components/Chip/Chip";
107
107
  import { DropdownToggleCheckbox } from "@patternfly/react-core/dist/esm/components/Dropdown/DropdownToggleCheckbox";
108
108
  import { Select } from "@patternfly/react-core/dist/esm/components/Select/Select";
109
109
  import { SelectOption } from "@patternfly/react-core/dist/esm/components/Select/SelectOption";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redhat-cloud-services/frontend-components-utilities",
3
- "version": "3.2.23",
3
+ "version": "3.2.24",
4
4
  "description": "Util functions for RedHat Cloud Services project.",
5
5
  "main": "index.js",
6
6
  "module": "esm/index.js",