feat(frontend-plugin-api): create extension suspense

Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
Camila Belo
2023-10-12 22:08:32 +02:00
parent b2dcb92c36
commit 2610774e4b
2 changed files with 38 additions and 0 deletions
@@ -0,0 +1,33 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React, { ReactNode, Suspense } from 'react';
import { useApp } from '@backstage/core-plugin-api';
/** @public */
export interface ExtensionSuspenseProps {
children: ReactNode;
}
/** @public */
export function ExtensionSuspense(props: ExtensionSuspenseProps) {
const { children } = props;
const app = useApp();
const { Progress } = app.getComponents();
return <Suspense fallback={<Progress />}>{children}</Suspense>;
}
@@ -18,3 +18,8 @@ export {
ExtensionBoundary,
type ExtensionBoundaryProps,
} from './ExtensionBoundary';
export {
ExtensionSuspense,
type ExtensionSuspenseProps,
} from './ExtensionSuspense';