The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/plugins/components/AppPluginLoader.tsx

44 lines
1.4 KiB

import React, { useState } from 'react';
import { useLocation, useParams } from 'react-router-dom';
import { NavModel } from '@grafana/data';
import { getWarningNav } from 'app/angular/services/nav_model_srv';
import { Page } from 'app/core/components/Page/Page';
import PageLoader from 'app/core/components/PageLoader/PageLoader';
import { useImportAppPlugin } from '../hooks/useImportAppPlugin';
type AppPluginLoaderProps = {
// The id of the app plugin to be loaded
id: string;
// The base URL path - defaults to the current path
basePath?: string;
};
// This component can be used to render an app-plugin based on its plugin ID.
export const AppPluginLoader = ({ id, basePath }: AppPluginLoaderProps) => {
const [nav, setNav] = useState<NavModel | null>(null);
const { value: plugin, error, loading } = useImportAppPlugin(id);
const queryParams = useParams();
const { pathname } = useLocation();
if (error) {
return <Page.Header navItem={getWarningNav(error.message, error.stack).main} />;
}
return (
<>
{loading && <PageLoader />}
{nav && <Page.Header navItem={nav.main} />}
{!loading && plugin && plugin.root && (
<plugin.root
meta={plugin.meta}
basename={basePath || pathname}
onNavChanged={setNav}
query={queryParams}
path={pathname}
/>
)}
</>
);
};