Merge pull request #8405 from backstage/freben/nounpack
Do not unpack arguments directly on exported items 🧹
This commit is contained in:
@@ -6,12 +6,13 @@
|
||||
import { ApiRef } from '@backstage/core-plugin-api';
|
||||
import { AuthorizeRequest } from '@backstage/plugin-permission-common';
|
||||
import { AuthorizeResponse } from '@backstage/plugin-permission-common';
|
||||
import { ComponentProps } from 'react';
|
||||
import { Config } from '@backstage/config';
|
||||
import { DiscoveryApi } from '@backstage/core-plugin-api';
|
||||
import { IdentityApi } from '@backstage/core-plugin-api';
|
||||
import { Permission } from '@backstage/plugin-permission-common';
|
||||
import { default as React_2 } from 'react';
|
||||
import { RouteProps } from 'react-router';
|
||||
import { ReactElement } from 'react';
|
||||
import { Route } from 'react-router';
|
||||
|
||||
// @public (undocumented)
|
||||
export type AsyncPermissionResult = {
|
||||
@@ -25,11 +26,7 @@ export class IdentityPermissionApi implements PermissionApi {
|
||||
// (undocumented)
|
||||
authorize(request: AuthorizeRequest): Promise<AuthorizeResponse>;
|
||||
// (undocumented)
|
||||
static create({
|
||||
configApi,
|
||||
discoveryApi,
|
||||
identityApi,
|
||||
}: {
|
||||
static create(options: {
|
||||
configApi: Config;
|
||||
discoveryApi: DiscoveryApi;
|
||||
identityApi: IdentityApi;
|
||||
@@ -45,19 +42,13 @@ export type PermissionApi = {
|
||||
export const permissionApiRef: ApiRef<PermissionApi>;
|
||||
|
||||
// @public
|
||||
export const PermissionedRoute: ({
|
||||
permission,
|
||||
resourceRef,
|
||||
errorComponent,
|
||||
...props
|
||||
}: RouteProps & {
|
||||
permission: Permission;
|
||||
resourceRef?: string | undefined;
|
||||
errorComponent?:
|
||||
| React_2.ReactElement<any, string | React_2.JSXElementConstructor<any>>
|
||||
| null
|
||||
| undefined;
|
||||
}) => JSX.Element;
|
||||
export const PermissionedRoute: (
|
||||
props: ComponentProps<typeof Route> & {
|
||||
permission: Permission;
|
||||
resourceRef?: string;
|
||||
errorComponent?: ReactElement | null;
|
||||
},
|
||||
) => JSX.Element;
|
||||
|
||||
// @public
|
||||
export const usePermission: (
|
||||
|
||||
@@ -34,15 +34,12 @@ export class IdentityPermissionApi implements PermissionApi {
|
||||
private readonly identityApi: IdentityApi,
|
||||
) {}
|
||||
|
||||
static create({
|
||||
configApi,
|
||||
discoveryApi,
|
||||
identityApi,
|
||||
}: {
|
||||
static create(options: {
|
||||
configApi: Config;
|
||||
discoveryApi: DiscoveryApi;
|
||||
identityApi: IdentityApi;
|
||||
}) {
|
||||
const { configApi, discoveryApi, identityApi } = options;
|
||||
const permissionClient = new PermissionClient({ discoveryApi, configApi });
|
||||
return new IdentityPermissionApi(permissionClient, identityApi);
|
||||
}
|
||||
|
||||
@@ -21,20 +21,19 @@ import { usePermission } from '../hooks';
|
||||
import { Permission } from '@backstage/plugin-permission-common';
|
||||
|
||||
/**
|
||||
* Returns a React Router Route which only renders the element when authorized. If unathorized, the Route will render a
|
||||
* Returns a React Router Route which only renders the element when authorized. If unauthorized, the Route will render a
|
||||
* NotFoundErrorPage (see {@link @backstage/core-app-api#AppComponents}).
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const PermissionedRoute = ({
|
||||
permission,
|
||||
resourceRef,
|
||||
errorComponent,
|
||||
...props
|
||||
}: ComponentProps<typeof Route> & {
|
||||
permission: Permission;
|
||||
resourceRef?: string;
|
||||
errorComponent?: ReactElement | null;
|
||||
}) => {
|
||||
export const PermissionedRoute = (
|
||||
props: ComponentProps<typeof Route> & {
|
||||
permission: Permission;
|
||||
resourceRef?: string;
|
||||
errorComponent?: ReactElement | null;
|
||||
},
|
||||
) => {
|
||||
const { permission, resourceRef, errorComponent, ...otherProps } = props;
|
||||
const permissionResult = usePermission(permission, resourceRef);
|
||||
const app = useApp();
|
||||
const { NotFoundErrorPage } = app.getComponents();
|
||||
@@ -48,5 +47,5 @@ export const PermissionedRoute = ({
|
||||
shownElement = props.element;
|
||||
}
|
||||
|
||||
return <Route {...props} element={shownElement} />;
|
||||
return <Route {...otherProps} element={shownElement} />;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user