mirror of https://github.com/grafana/grafana
Alerting: Add plugins extension point to alerting home page (#85725)
* Add basic extension point to alerting home page * Remove home page scenes app. Improve plugins styles * Remove unused code * Fix home page rendering when no plugins registered * Add row-based integrations component * Add missing margins * Rollback the Box component changes * Remove unused importpull/86684/head
parent
686c8013c3
commit
7caa30bc2e
@ -1,74 +1,54 @@ |
|||||||
import React, { useState } from 'react'; |
import React, { useState } from 'react'; |
||||||
|
|
||||||
import { config } from '@grafana/runtime'; |
import { config } from '@grafana/runtime'; |
||||||
import { SceneApp, SceneAppPage } from '@grafana/scenes'; |
import { Box, Stack, Tab, TabContent, TabsBar } from '@grafana/ui'; |
||||||
import { usePageNav } from 'app/core/components/Page/usePageNav'; |
|
||||||
import { PluginPageContext, PluginPageContextType } from 'app/features/plugins/components/PluginPageContext'; |
|
||||||
|
|
||||||
|
import { AlertingPageWrapper } from '../components/AlertingPageWrapper'; |
||||||
import { isLocalDevEnv, isOpenSourceEdition } from '../utils/misc'; |
import { isLocalDevEnv, isOpenSourceEdition } from '../utils/misc'; |
||||||
|
|
||||||
import { getOverviewScene, WelcomeHeader } from './GettingStarted'; |
import GettingStarted, { WelcomeHeader } from './GettingStarted'; |
||||||
import { getInsightsScenes } from './Insights'; |
import { getInsightsScenes } from './Insights'; |
||||||
|
import { PluginIntegrations } from './PluginIntegrations'; |
||||||
let homeApp: SceneApp | undefined; |
|
||||||
|
|
||||||
export function getHomeApp(insightsEnabled: boolean) { |
|
||||||
if (homeApp) { |
|
||||||
return homeApp; |
|
||||||
} |
|
||||||
|
|
||||||
if (insightsEnabled) { |
|
||||||
homeApp = new SceneApp({ |
|
||||||
pages: [ |
|
||||||
new SceneAppPage({ |
|
||||||
title: 'Alerting', |
|
||||||
subTitle: <WelcomeHeader />, |
|
||||||
url: '/alerting', |
|
||||||
hideFromBreadcrumbs: true, |
|
||||||
tabs: [ |
|
||||||
new SceneAppPage({ |
|
||||||
title: 'Insights', |
|
||||||
url: '/alerting/home/insights', |
|
||||||
getScene: getInsightsScenes, |
|
||||||
}), |
|
||||||
new SceneAppPage({ |
|
||||||
title: 'Get started', |
|
||||||
url: '/alerting/home/overview', |
|
||||||
getScene: getOverviewScene, |
|
||||||
}), |
|
||||||
], |
|
||||||
}), |
|
||||||
], |
|
||||||
}); |
|
||||||
} else { |
|
||||||
homeApp = new SceneApp({ |
|
||||||
pages: [ |
|
||||||
new SceneAppPage({ |
|
||||||
title: 'Alerting', |
|
||||||
subTitle: <WelcomeHeader />, |
|
||||||
url: '/alerting', |
|
||||||
hideFromBreadcrumbs: true, |
|
||||||
getScene: getOverviewScene, |
|
||||||
}), |
|
||||||
], |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
return homeApp; |
|
||||||
} |
|
||||||
|
|
||||||
export default function Home() { |
export default function Home() { |
||||||
const insightsEnabled = |
const insightsEnabled = |
||||||
(!isOpenSourceEdition() || isLocalDevEnv()) && Boolean(config.featureToggles.alertingInsights); |
(!isOpenSourceEdition() || isLocalDevEnv()) && Boolean(config.featureToggles.alertingInsights); |
||||||
|
|
||||||
const appScene = getHomeApp(insightsEnabled); |
const [activeTab, setActiveTab] = useState<'insights' | 'overview'>(insightsEnabled ? 'insights' : 'overview'); |
||||||
|
const insightsScene = getInsightsScenes(); |
||||||
const sectionNav = usePageNav('alerting')!; |
|
||||||
const [pluginContext] = useState<PluginPageContextType>({ sectionNav }); |
|
||||||
|
|
||||||
return ( |
return ( |
||||||
<PluginPageContext.Provider value={pluginContext}> |
<AlertingPageWrapper |
||||||
<appScene.Component model={appScene} /> |
title="Alerting" |
||||||
</PluginPageContext.Provider> |
subTitle="Learn about problems in your systems moments after they occur" |
||||||
|
navId="alerting" |
||||||
|
> |
||||||
|
<Stack gap={2} direction="column"> |
||||||
|
<WelcomeHeader /> |
||||||
|
<PluginIntegrations /> |
||||||
|
</Stack> |
||||||
|
<Box marginTop={{ lg: 2, md: 0, xs: 0 }}> |
||||||
|
<TabsBar> |
||||||
|
{insightsEnabled && ( |
||||||
|
<Tab |
||||||
|
key="insights" |
||||||
|
label="Insights" |
||||||
|
active={activeTab === 'insights'} |
||||||
|
onChangeTab={() => setActiveTab('insights')} |
||||||
|
/> |
||||||
|
)} |
||||||
|
<Tab |
||||||
|
key="overview" |
||||||
|
label="Get started" |
||||||
|
active={activeTab === 'overview'} |
||||||
|
onChangeTab={() => setActiveTab('overview')} |
||||||
|
/> |
||||||
|
</TabsBar> |
||||||
|
<TabContent> |
||||||
|
{activeTab === 'insights' && <insightsScene.Component model={insightsScene} />} |
||||||
|
{activeTab === 'overview' && <GettingStarted />} |
||||||
|
</TabContent> |
||||||
|
</Box> |
||||||
|
</AlertingPageWrapper> |
||||||
); |
); |
||||||
} |
} |
||||||
|
|||||||
@ -0,0 +1,45 @@ |
|||||||
|
import { css } from '@emotion/css'; |
||||||
|
import React from 'react'; |
||||||
|
|
||||||
|
import { PluginExtensionPoints } from '@grafana/data'; |
||||||
|
import { GrafanaTheme2 } from '@grafana/data/'; |
||||||
|
import { getPluginComponentExtensions } from '@grafana/runtime'; |
||||||
|
import { Stack, Text } from '@grafana/ui'; |
||||||
|
import { useStyles2 } from '@grafana/ui/'; |
||||||
|
|
||||||
|
export function PluginIntegrations() { |
||||||
|
const styles = useStyles2(getStyles); |
||||||
|
|
||||||
|
const { extensions } = getPluginComponentExtensions({ |
||||||
|
extensionPointId: PluginExtensionPoints.AlertingHomePage, |
||||||
|
limitPerPlugin: 1, |
||||||
|
}); |
||||||
|
|
||||||
|
if (extensions.length === 0) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
return ( |
||||||
|
<Stack direction="column" gap={2}> |
||||||
|
<Text element="h3" variant="h4"> |
||||||
|
Speed up your alerts creation now by using one of our tailored apps |
||||||
|
</Text> |
||||||
|
<Stack gap={2} wrap="wrap" direction="row"> |
||||||
|
{extensions.map((extension) => ( |
||||||
|
<div key={extension.id} className={styles.box}> |
||||||
|
<extension.component /> |
||||||
|
</div> |
||||||
|
))} |
||||||
|
</Stack> |
||||||
|
</Stack> |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
const getStyles = (theme: GrafanaTheme2) => ({ |
||||||
|
box: css({ |
||||||
|
padding: theme.spacing(2), |
||||||
|
flex: 1, |
||||||
|
backgroundColor: theme.colors.background.secondary, |
||||||
|
maxWidth: '460px', |
||||||
|
}), |
||||||
|
}); |
||||||
Loading…
Reference in new issue