From cb3246ef89247d51c8d2b35c669da1b2061a7e8b Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sun, 5 Dec 2021 18:58:24 +0100 Subject: [PATCH] core-components: lazy load log viewer Signed-off-by: Patrik Oldsberg --- .../components/LogViewer/LazyLogViewer.tsx | 32 +++++++++++++++++++ .../src/components/LogViewer/index.ts | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 packages/core-components/src/components/LogViewer/LazyLogViewer.tsx diff --git a/packages/core-components/src/components/LogViewer/LazyLogViewer.tsx b/packages/core-components/src/components/LogViewer/LazyLogViewer.tsx new file mode 100644 index 0000000000..fb765bbbc4 --- /dev/null +++ b/packages/core-components/src/components/LogViewer/LazyLogViewer.tsx @@ -0,0 +1,32 @@ +/* + * Copyright 2021 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, { lazy, Suspense } from 'react'; +import { useApp } from '@backstage/core-plugin-api'; +import { LogViewerProps } from './LogViewer'; + +const LogViewer = lazy(() => + import('./LogViewer').then(m => ({ default: m.LogViewer })), +); + +export function LazyLogViewer(props: LogViewerProps) { + const { Progress } = useApp().getComponents(); + return ( + }> + + + ); +} diff --git a/packages/core-components/src/components/LogViewer/index.ts b/packages/core-components/src/components/LogViewer/index.ts index 839f34f81e..aba2e8ea16 100644 --- a/packages/core-components/src/components/LogViewer/index.ts +++ b/packages/core-components/src/components/LogViewer/index.ts @@ -14,5 +14,5 @@ * limitations under the License. */ -export { LogViewer } from './LogViewer'; +export { LazyLogViewer as LogViewer } from './LazyLogViewer'; export type { LogViewerProps } from './LogViewer';