Skip to content

Instantly share code, notes, and snippets.

@mckn
Created November 6, 2025 20:43
Show Gist options
  • Select an option

  • Save mckn/f40d699b602b6fb3554f90bb8da40105 to your computer and use it in GitHub Desktop.

Select an option

Save mckn/f40d699b602b6fb3554f90bb8da40105 to your computer and use it in GitHub Desktop.
Use Grafana sidebar from plugins
import React, { Suspense, lazy, memo } from 'react';
import { AppPlugin, type AppRootProps } from '@grafana/data';
import { LoadingPlaceholder } from '@grafana/ui';
import type { AppConfigProps } from './components/AppConfig/AppConfig';
const LazyApp = lazy(() => import('./components/App/App'));
const LazyAppConfig = lazy(() => import('./components/AppConfig/AppConfig'));
const App = (props: AppRootProps) => (
<Suspense fallback={<LoadingPlaceholder text="" />}>
<LazyApp {...props} />
</Suspense>
);
const AppConfig = (props: AppConfigProps) => (
<Suspense fallback={<LoadingPlaceholder text="" />}>
<LazyAppConfig {...props} />
</Suspense>
);
const sidebar = 'sidebartest';
function SidebarComponent() {
console.log('rendered');
return <div>Hello World</div>;
}
export const plugin = new AppPlugin<{}>()
.setRootPage(App)
.addConfigPage({
title: 'Configuration',
icon: 'cog',
body: AppConfig,
id: 'configuration',
})
.addComponent({
targets: 'grafana/extension-sidebar/v0-alpha',
title: sidebar,
description: sidebar,
component: memo(SidebarComponent),
})
.addLink({
targets: 'grafana/extension-sidebar/v0-alpha',
title: sidebar,
description: sidebar,
onClick: () => {
console.log('clicked');
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment