From 8c6129d3e09f168a035d092bdc1107d7408b101c Mon Sep 17 00:00:00 2001 From: MT Lewis Date: Thu, 17 Mar 2022 12:16:35 +0000 Subject: [PATCH] permission-react: inline parameter type to clean up the api report a bit Signed-off-by: MT Lewis --- plugins/permission-react/api-report.md | 12 +++++++--- .../src/hooks/usePermission.ts | 23 ++++++++----------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/plugins/permission-react/api-report.md b/plugins/permission-react/api-report.md index 81d9e09743..6b66376cb7 100644 --- a/plugins/permission-react/api-report.md +++ b/plugins/permission-react/api-report.md @@ -60,9 +60,15 @@ export const PermissionedRoute: ( // @public export function usePermission( - ...[permission, resourceRef]: - | [ResourcePermission, string | undefined] - | [Exclude] + input: + | { + permission: Exclude; + resourceRef?: never; + } + | { + permission: ResourcePermission; + resourceRef: string | undefined; + }, ): AsyncPermissionResult; // (No @packageDocumentation comment for this package) diff --git a/plugins/permission-react/src/hooks/usePermission.ts b/plugins/permission-react/src/hooks/usePermission.ts index 6a00e07663..1e7f45129d 100644 --- a/plugins/permission-react/src/hooks/usePermission.ts +++ b/plugins/permission-react/src/hooks/usePermission.ts @@ -32,17 +32,6 @@ export type AsyncPermissionResult = { error?: Error; }; -/** @public */ -export type UsePermissionProps = - | { - permission: Exclude; - 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; + 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