@redhat-cloud-services/frontend-components-utilities 3.2.21 → 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.
@@ -1,4 +1,4 @@
1
- import { Dispatch, AnyAction } from 'redux';
1
+ import { AnyAction, Dispatch } from 'redux';
2
2
  export declare type Listener<T = any> = {
3
3
  callback: (data: {
4
4
  data: T;
package/RBAC/RBAC.d.ts CHANGED
@@ -1,9 +1,30 @@
1
+ /// <reference types="react" />
1
2
  import { Access } from '@redhat-cloud-services/rbac-client';
3
+ import type { ChromeAPI } from '@redhat-cloud-services/types';
4
+ declare global {
5
+ interface Window {
6
+ insights: {
7
+ chrome: ChromeAPI;
8
+ };
9
+ }
10
+ }
2
11
  export interface RBAC {
3
12
  isOrgAdmin: boolean;
4
13
  permissions: Access[];
5
14
  }
6
15
  export declare function getRBAC(applicationName?: string, disableCache?: boolean): Promise<RBAC>;
7
- export declare function doesHavePermissions(userPermissions: (Access | string)[], permissionList: string[]): boolean;
8
- 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>;
9
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) {
@@ -59,6 +70,7 @@ function usePermissions(appName, permissionsList, disableCache, checkAll) {
59
70
  permissions: [],
60
71
  }), permissions = _a[0], setPermissions = _a[1];
61
72
  (0, react_1.useEffect)(function () {
73
+ var ignore = false;
62
74
  setPermissions(function (prev) { return (__assign(__assign({}, prev), { isLoading: true })); });
63
75
  (function () { return __awaiter(_this, void 0, void 0, function () {
64
76
  var _a, isOrgAdmin, userPermissions;
@@ -67,19 +79,28 @@ function usePermissions(appName, permissionsList, disableCache, checkAll) {
67
79
  case 0: return [4, (0, RBAC_1.getRBAC)(appName, disableCache)];
68
80
  case 1:
69
81
  _a = _b.sent(), isOrgAdmin = _a.isOrgAdmin, userPermissions = _a.permissions;
70
- setPermissions({
71
- isLoading: false,
72
- isOrgAdmin: isOrgAdmin,
73
- permissions: userPermissions,
74
- hasAccess: checkAll ? (0, RBAC_1.hasAllPermissions)(userPermissions, permissionsList) : (0, RBAC_1.doesHavePermissions)(userPermissions, permissionsList),
75
- });
82
+ !ignore &&
83
+ setPermissions({
84
+ isLoading: false,
85
+ isOrgAdmin: isOrgAdmin,
86
+ permissions: userPermissions,
87
+ hasAccess: checkAll ? (0, RBAC_1.hasAllPermissions)(userPermissions, permissionsList) : (0, RBAC_1.doesHavePermissions)(userPermissions, permissionsList),
88
+ });
76
89
  return [2];
77
90
  }
78
91
  });
79
92
  }); })();
93
+ return function () {
94
+ ignore = true;
95
+ };
80
96
  }, [appName, disableCache]);
81
97
  return permissions;
82
98
  }
83
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;
84
105
  exports.default = usePermissions;
85
106
  //# sourceMappingURL=RBACHook.js.map
@@ -1,4 +1,4 @@
1
- import { compose, ActionCreator, Store, Reducer, Middleware } from 'redux';
1
+ import { ActionCreator, Middleware, Reducer, Store, compose } from 'redux';
2
2
  export declare function applyReducerHash(reducerHash: any, initialState?: Record<string, unknown>): (state: Record<string, unknown> | undefined, action: {
3
3
  type: PropertyKey;
4
4
  }) => any;
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 { useState, useEffect } from 'react';
49
- import { getRBAC, doesHavePermissions, 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({
@@ -56,6 +67,7 @@ export function usePermissions(appName, permissionsList, disableCache, checkAll)
56
67
  permissions: [],
57
68
  }), permissions = _a[0], setPermissions = _a[1];
58
69
  useEffect(function () {
70
+ var ignore = false;
59
71
  setPermissions(function (prev) { return (__assign(__assign({}, prev), { isLoading: true })); });
60
72
  (function () { return __awaiter(_this, void 0, void 0, function () {
61
73
  var _a, isOrgAdmin, userPermissions;
@@ -64,18 +76,26 @@ export function usePermissions(appName, permissionsList, disableCache, checkAll)
64
76
  case 0: return [4, getRBAC(appName, disableCache)];
65
77
  case 1:
66
78
  _a = _b.sent(), isOrgAdmin = _a.isOrgAdmin, userPermissions = _a.permissions;
67
- setPermissions({
68
- isLoading: false,
69
- isOrgAdmin: isOrgAdmin,
70
- permissions: userPermissions,
71
- hasAccess: checkAll ? hasAllPermissions(userPermissions, permissionsList) : doesHavePermissions(userPermissions, permissionsList),
72
- });
79
+ !ignore &&
80
+ setPermissions({
81
+ isLoading: false,
82
+ isOrgAdmin: isOrgAdmin,
83
+ permissions: userPermissions,
84
+ hasAccess: checkAll ? hasAllPermissions(userPermissions, permissionsList) : doesHavePermissions(userPermissions, permissionsList),
85
+ });
73
86
  return [2];
74
87
  }
75
88
  });
76
89
  }); })();
90
+ return function () {
91
+ ignore = true;
92
+ };
77
93
  }, [appName, disableCache]);
78
94
  return permissions;
79
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
+ };
80
100
  export default usePermissions;
81
101
  //# sourceMappingURL=RBACHook.js.map
@@ -9,7 +9,7 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { applyMiddleware, combineReducers, createStore, compose } from 'redux';
12
+ import { applyMiddleware, combineReducers, compose, createStore } from 'redux';
13
13
  export function applyReducerHash(reducerHash, initialState) {
14
14
  if (initialState === void 0) { initialState = {}; }
15
15
  return function (state, action) {
@@ -37,7 +37,7 @@ var __rest = (this && this.__rest) || function (s, e) {
37
37
  };
38
38
  import React from 'react';
39
39
  import PropTypes from 'prop-types';
40
- import { withRouter, matchPath } from 'react-router-dom';
40
+ import { matchPath, withRouter } from 'react-router-dom';
41
41
  import { connect } from 'react-redux';
42
42
  import isEqual from 'lodash/isEqual';
43
43
  var RouterParams = (function (_super) {
@@ -61,7 +61,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
61
61
  }
62
62
  };
63
63
  import axios from 'axios';
64
- import { configureScope, captureException } from '@sentry/browser';
64
+ import { captureException, configureScope } from '@sentry/browser';
65
65
  var HttpError = (function (_super) {
66
66
  __extends(HttpError, _super);
67
67
  function HttpError(description) {
@@ -1,4 +1,4 @@
1
- import { Badge, Bullseye, Button, Checkbox, ClipboardCopy, Dropdown, DropdownItem, DropdownPosition, DropdownToggle, DropdownToggleCheckbox, TextInput, Grid, GridItem, Tab, Tabs, Switch, Form, FormGroup, FormSelect, FormSelectOption, Label, EmptyState, EmptyStateBody, EmptyStateIcon, EmptyStateVariant, Select, SelectOption, SelectVariant, SelectGroup, Radio, ChipGroup, Chip, Title, Split, SplitItem, Spinner, Flex, FlexItem, Pagination, PaginationVariant, Tooltip, Modal, Stack, StackItem, Level, LevelItem, KebabToggle, Toolbar, ToolbarItem, ToolbarContent, ToolbarGroup, Drawer, DrawerPanelContent, DrawerContent, DrawerContentBody, DrawerPanelBody, DrawerActions, DrawerHead, DrawerCloseButton, } from '@patternfly/react-core';
1
+ import { Badge, Bullseye, Button, Checkbox, Chip, ChipGroup, ClipboardCopy, Drawer, DrawerActions, DrawerCloseButton, DrawerContent, DrawerContentBody, DrawerHead, DrawerPanelBody, DrawerPanelContent, Dropdown, DropdownItem, DropdownPosition, DropdownToggle, DropdownToggleCheckbox, EmptyState, EmptyStateBody, EmptyStateIcon, EmptyStateVariant, Flex, FlexItem, Form, FormGroup, FormSelect, FormSelectOption, Grid, GridItem, KebabToggle, Label, Level, LevelItem, Modal, Pagination, PaginationVariant, Radio, Select, SelectGroup, SelectOption, SelectVariant, Spinner, Split, SplitItem, Stack, StackItem, Switch, Tab, Tabs, TextInput, Title, Toolbar, ToolbarContent, ToolbarGroup, ToolbarItem, Tooltip, } from '@patternfly/react-core';
2
2
  import { CubesIcon, ExclamationTriangleIcon } from '@patternfly/react-icons';
3
3
  export var reactIcons = {
4
4
  CubesIcon: CubesIcon,
@@ -45,9 +45,9 @@ 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 { useState, useEffect } from 'react';
48
+ import { useEffect, useState } from 'react';
49
49
  import * as reactRouterDom from 'react-router-dom';
50
- import { Table as PfTable, TableBody, TableHeader, TableGridBreakpoint, cellWidth, TableVariant, sortable, expandable, SortByDirection, } from '@patternfly/react-table';
50
+ import { Table as PfTable, SortByDirection, TableBody, TableGridBreakpoint, TableHeader, TableVariant, cellWidth, expandable, sortable, } from '@patternfly/react-table';
51
51
  console.error('"useInventory" hook is deprecated and will be removed in v4. Please use Chrome 2.0 compatible Inventory version.');
52
52
  export var useInventory = function (_a) {
53
53
  var store = _a.store, tableReducer = _a.tableReducer, detailReducer = _a.detailReducer, getRegistry = _a.getRegistry;
@@ -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.21",
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",