permission-react: inline parameter type to clean up the api report a bit

Signed-off-by: MT Lewis <mtlewis@users.noreply.github.com>
This commit is contained in:
MT Lewis
2022-03-17 12:16:35 +00:00
committed by Joe Porpeglia
parent 91703e8086
commit 8c6129d3e0
2 changed files with 19 additions and 16 deletions
+9 -3
View File
@@ -60,9 +60,15 @@ export const PermissionedRoute: (
// @public
export function usePermission(
...[permission, resourceRef]:
| [ResourcePermission, string | undefined]
| [Exclude<Permission, ResourcePermission>]
input:
| {
permission: Exclude<Permission, ResourcePermission>;
resourceRef?: never;
}
| {
permission: ResourcePermission;
resourceRef: string | undefined;
},
): AsyncPermissionResult;
// (No @packageDocumentation comment for this package)
@@ -32,17 +32,6 @@ export type AsyncPermissionResult = {
error?: Error;
};
/** @public */
export type UsePermissionProps =
| {
permission: Exclude<Permission, ResourcePermission>;
resourceRef?: never;
}
| {
permission: ResourcePermission;
resourceRef: string | undefined;
};
/**
* React hook utility for authorization. Given either a non-resource
* {@link @backstage/plugin-permission-common#Permission} or a
@@ -62,10 +51,18 @@ export type UsePermissionProps =
* @public
*/
export function usePermission(
props: UsePermissionProps,
input:
| {
permission: Exclude<Permission, ResourcePermission>;
resourceRef?: never;
}
| {
permission: ResourcePermission;
resourceRef: string | undefined;
},
): AsyncPermissionResult {
const permissionApi = useApi(permissionApiRef);
const { data, error } = useSWR(props, async (args: UsePermissionProps) => {
const { data, error } = useSWR(input, async (args: typeof input) => {
// We could make the resourceRef parameter required to avoid this check, but
// it would make using this hook difficult in situations where the entity
// must be asynchronously loaded, so instead we short-circuit to a deny when