catalog-react: require CatalogEntityPermission in useEntityPermission

Now that we have stricter typing for permissions, we can restrict the
useEntityPermission hook to only be used with permissions of type
`CatalogEntityPermission`.

Signed-off-by: Mike Lewis <mtlewis@users.noreply.github.com>
This commit is contained in:
Mike Lewis
2022-03-07 17:38:17 +00:00
committed by Joe Porpeglia
parent 8c8bee47f4
commit 0ffd88a90e
4 changed files with 11 additions and 5 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-react': patch
---
Prevent permissions with types other than `CatalogEntityPermission` from being used with the `useEntityPermission` hook.
+2 -2
View File
@@ -8,6 +8,7 @@
import { ApiRef } from '@backstage/core-plugin-api';
import { CATALOG_FILTER_EXISTS } from '@backstage/catalog-client';
import { CatalogApi } from '@backstage/catalog-client';
import { CatalogEntityPermission } from '@backstage/plugin-catalog-common';
import { ComponentEntity } from '@backstage/catalog-model';
import { ComponentProps } from 'react';
import { CompoundEntityRef } from '@backstage/catalog-model';
@@ -16,7 +17,6 @@ import { IconButton } from '@material-ui/core';
import { LinkProps } from '@backstage/core-components';
import { Observable } from '@backstage/types';
import { Overrides } from '@material-ui/core/styles/overrides';
import { Permission } from '@backstage/plugin-permission-common';
import { PropsWithChildren } from 'react';
import { default as React_2 } from 'react';
import { ReactNode } from 'react';
@@ -489,7 +489,7 @@ export function useEntityOwnership(): {
};
// @alpha
export function useEntityPermission(permission: Permission): {
export function useEntityPermission(permission: CatalogEntityPermission): {
loading: boolean;
allowed: boolean;
error?: Error;
+1
View File
@@ -40,6 +40,7 @@
"@backstage/core-plugin-api": "^1.0.0",
"@backstage/errors": "^1.0.0",
"@backstage/integration": "^1.0.1-next.0",
"@backstage/plugin-catalog-common": "^1.0.1-next.0",
"@backstage/plugin-permission-common": "^0.5.3",
"@backstage/plugin-permission-react": "^0.3.4",
"@backstage/theme": "^0.2.15",
@@ -15,7 +15,7 @@
*/
import { stringifyEntityRef } from '@backstage/catalog-model';
import { Permission } from '@backstage/plugin-permission-common';
import { CatalogEntityPermission } from '@backstage/plugin-catalog-common';
import { usePermission } from '@backstage/plugin-permission-react';
import { useAsyncEntity } from './useEntity';
@@ -23,14 +23,14 @@ import { useAsyncEntity } from './useEntity';
* A thin wrapper around the
* {@link @backstage/plugin-permission-react#usePermission} hook which uses the
* current entity in context to make an authorization request for the given
* permission.
* {@link @backstage/plugin-catalog-common#CatalogEntityPermission}.
*
* Note: this hook blocks the permission request until the entity has loaded in
* context. If you have the entityRef and need concurrent requests, use the
* `usePermission` hook directly.
* @alpha
*/
export function useEntityPermission(permission: Permission): {
export function useEntityPermission(permission: CatalogEntityPermission): {
loading: boolean;
allowed: boolean;
error?: Error;