@backstage/plugin-permission-react
Advanced tools
Comparing version 0.0.0-nightly-202202022734 to 0.0.0-nightly-20220211021943
# @backstage/plugin-permission-react | ||
## 0.0.0-nightly-202202022734 | ||
## 0.0.0-nightly-20220211021943 | ||
### Patch Changes | ||
- 1ed305728b: Bump `node-fetch` to version 2.6.7 and `cross-fetch` to version 3.1.5 | ||
- Updated dependencies | ||
- @backstage/core-plugin-api@0.0.0-nightly-20220211021943 | ||
- @backstage/plugin-permission-common@0.0.0-nightly-20220211021943 | ||
## 0.3.0 | ||
### Minor Changes | ||
@@ -13,5 +22,5 @@ | ||
- Updated dependencies | ||
- @backstage/plugin-permission-common@0.0.0-nightly-202202022734 | ||
- @backstage/core-plugin-api@0.0.0-nightly-202202022734 | ||
- @backstage/config@0.0.0-nightly-202202022734 | ||
- @backstage/plugin-permission-common@0.4.0 | ||
- @backstage/core-plugin-api@0.6.0 | ||
- @backstage/config@0.1.13 | ||
@@ -18,0 +27,0 @@ ## 0.3.0-next.0 |
@@ -8,4 +8,4 @@ 'use strict'; | ||
var corePluginApi = require('@backstage/core-plugin-api'); | ||
var useAsync = require('react-use/lib/useAsync'); | ||
var pluginPermissionCommon = require('@backstage/plugin-permission-common'); | ||
var useSWR = require('swr'); | ||
@@ -15,3 +15,3 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var React__default = /*#__PURE__*/_interopDefaultLegacy(React); | ||
var useAsync__default = /*#__PURE__*/_interopDefaultLegacy(useAsync); | ||
var useSWR__default = /*#__PURE__*/_interopDefaultLegacy(useSWR); | ||
@@ -40,16 +40,13 @@ const permissionApiRef = corePluginApi.createApiRef({ | ||
const permissionApi = corePluginApi.useApi(permissionApiRef); | ||
const { loading, error, value } = useAsync__default["default"](async () => { | ||
const { result } = await permissionApi.authorize({ | ||
permission, | ||
resourceRef | ||
}); | ||
const { data, error } = useSWR__default["default"]({ permission, resourceRef }, async (args) => { | ||
const { result } = await permissionApi.authorize(args); | ||
return result; | ||
}, [permissionApi, permission, resourceRef]); | ||
if (loading) { | ||
return { loading: true, allowed: false }; | ||
} | ||
}); | ||
if (error) { | ||
return { error, loading: false, allowed: false }; | ||
} | ||
return { loading: false, allowed: value === pluginPermissionCommon.AuthorizeResult.ALLOW }; | ||
if (data === void 0) { | ||
return { loading: true, allowed: false }; | ||
} | ||
return { loading: false, allowed: data === pluginPermissionCommon.AuthorizeResult.ALLOW }; | ||
}; | ||
@@ -56,0 +53,0 @@ |
@@ -26,5 +26,12 @@ import { ComponentProps, ReactElement } from 'react'; | ||
/** | ||
* React hook utlity for authorization. Given a {@link @backstage/plugin-permission-common#Permission} and an optional | ||
* resourceRef, it will return whether or not access is allowed (for the given resource, if resourceRef is provided). See | ||
* {@link @backstage/plugin-permission-common/PermissionClient#authorize} for more details. | ||
* React hook utility for authorization. Given a | ||
* {@link @backstage/plugin-permission-common#Permission} and an optional | ||
* resourceRef, it will return whether or not access is allowed (for the given | ||
* resource, if resourceRef is provided). See | ||
* {@link @backstage/plugin-permission-common/PermissionClient#authorize} for | ||
* more details. | ||
* | ||
* Note: This hook uses stale-while-revalidate to help avoid flicker in UI | ||
* elements that would be conditionally rendered based on the `allowed` result | ||
* of this hook. | ||
* @public | ||
@@ -31,0 +38,0 @@ */ |
import React from 'react'; | ||
import { Route } from 'react-router'; | ||
import { createApiRef, useApi, useApp } from '@backstage/core-plugin-api'; | ||
import useAsync from 'react-use/lib/useAsync'; | ||
import { PermissionClient, AuthorizeResult } from '@backstage/plugin-permission-common'; | ||
import useSWR from 'swr'; | ||
@@ -29,16 +29,13 @@ const permissionApiRef = createApiRef({ | ||
const permissionApi = useApi(permissionApiRef); | ||
const { loading, error, value } = useAsync(async () => { | ||
const { result } = await permissionApi.authorize({ | ||
permission, | ||
resourceRef | ||
}); | ||
const { data, error } = useSWR({ permission, resourceRef }, async (args) => { | ||
const { result } = await permissionApi.authorize(args); | ||
return result; | ||
}, [permissionApi, permission, resourceRef]); | ||
if (loading) { | ||
return { loading: true, allowed: false }; | ||
} | ||
}); | ||
if (error) { | ||
return { error, loading: false, allowed: false }; | ||
} | ||
return { loading: false, allowed: value === AuthorizeResult.ALLOW }; | ||
if (data === void 0) { | ||
return { loading: true, allowed: false }; | ||
} | ||
return { loading: false, allowed: data === AuthorizeResult.ALLOW }; | ||
}; | ||
@@ -45,0 +42,0 @@ |
{ | ||
"name": "@backstage/plugin-permission-react", | ||
"version": "0.0.0-nightly-202202022734", | ||
"version": "0.0.0-nightly-20220211021943", | ||
"main": "dist/index.esm.js", | ||
@@ -30,8 +30,9 @@ "types": "dist/index.d.ts", | ||
"dependencies": { | ||
"@backstage/config": "^0.0.0-nightly-202202022734", | ||
"@backstage/core-plugin-api": "^0.0.0-nightly-202202022734", | ||
"@backstage/plugin-permission-common": "^0.0.0-nightly-202202022734", | ||
"cross-fetch": "^3.0.6", | ||
"@backstage/config": "^0.1.13", | ||
"@backstage/core-plugin-api": "^0.0.0-nightly-20220211021943", | ||
"@backstage/plugin-permission-common": "^0.0.0-nightly-20220211021943", | ||
"cross-fetch": "^3.1.5", | ||
"react-router": "6.0.0-beta.0", | ||
"react-use": "^17.2.4" | ||
"react-use": "^17.2.4", | ||
"swr": "^1.1.2" | ||
}, | ||
@@ -43,4 +44,4 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@backstage/cli": "^0.0.0-nightly-202202022734", | ||
"@backstage/test-utils": "^0.0.0-nightly-202202022734", | ||
"@backstage/cli": "^0.0.0-nightly-20220211021943", | ||
"@backstage/test-utils": "^0.0.0-nightly-20220211021943", | ||
"@testing-library/jest-dom": "^5.10.1", | ||
@@ -47,0 +48,0 @@ "@testing-library/react": "^11.2.5", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
29254
186
9
+ Addedswr@^1.1.2
+ Added@backstage/config@0.1.15(transitive)
+ Added@backstage/core-plugin-api@0.0.0-nightly-20250207023146(transitive)
+ Added@backstage/types@0.1.3(transitive)
+ Added@backstage/version-bridge@0.0.0-nightly-20250207023146(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedstylis@4.3.6(transitive)
+ Addedswr@1.3.0(transitive)
- Removed@backstage/core-plugin-api@0.0.0-nightly-20250131022942(transitive)
- Removedstylis@4.3.5(transitive)
Updated@backstage/config@^0.1.13
Updated@backstage/core-plugin-api@^0.0.0-nightly-20220211021943
Updated@backstage/plugin-permission-common@^0.0.0-nightly-20220211021943
Updatedcross-fetch@^3.1.5