Files
grafana/public/app/features/alerting/unified/components/rule-viewer/RuleViewerLayout.tsx
Leo 4eea5d5190 Navigation: Use navid and pagnav in alert rules pages (#55722)
* add navid and pagenav to edit/add/view alert rules

* move ruleeditor smaller component to its own file

* fix form alignments with new layout

* fixed broken test

* reuse AlertingPageWrapper
2022-10-04 14:36:36 +02:00

61 lines
1.7 KiB
TypeScript

import { css } from '@emotion/css';
import React from 'react';
import { GrafanaTheme2, NavModelItem } from '@grafana/data';
import { useStyles2 } from '@grafana/ui';
import { Page } from 'app/core/components/Page/Page';
type Props = {
children: React.ReactNode | React.ReactNode[];
title: string;
wrapInContent?: boolean;
};
const defaultPageNav: Partial<NavModelItem> = {
icon: 'bell',
id: 'alert-rule-view',
breadcrumbs: [{ title: 'Alert rules', url: 'alerting/list' }],
};
export function RuleViewerLayout(props: Props): JSX.Element | null {
const { wrapInContent = true, children, title } = props;
const styles = useStyles2(getPageStyles);
return (
<Page pageNav={{ ...defaultPageNav, text: title }} navId="alert-list">
<Page.Contents>
<div className={styles.content}>{wrapInContent ? <RuleViewerLayoutContent {...props} /> : children}</div>
</Page.Contents>
</Page>
);
}
type ContentProps = {
children: React.ReactNode | React.ReactNode[];
padding?: number;
};
export function RuleViewerLayoutContent({ children, padding = 2 }: ContentProps): JSX.Element | null {
const styles = useStyles2(getContentStyles(padding));
return <div className={styles.wrapper}>{children}</div>;
}
const getPageStyles = (theme: GrafanaTheme2) => {
return {
content: css`
max-width: ${theme.breakpoints.values.xxl}px;
`,
};
};
const getContentStyles = (padding: number) => (theme: GrafanaTheme2) => {
return {
wrapper: css`
background: ${theme.colors.background.primary};
border: 1px solid ${theme.colors.border.weak};
border-radius: ${theme.shape.borderRadius()};
padding: ${theme.spacing(padding)};
`,
};
};