diff --git a/public/app/features/alerting/unified/components/receivers/PayloadEditor.test.tsx b/public/app/features/alerting/unified/components/receivers/PayloadEditor.test.tsx index 6c38193111b..bb7a52fb4fd 100644 --- a/public/app/features/alerting/unified/components/receivers/PayloadEditor.test.tsx +++ b/public/app/features/alerting/unified/components/receivers/PayloadEditor.test.tsx @@ -2,6 +2,7 @@ import { render, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { default as React, useState } from 'react'; import { Provider } from 'react-redux'; +import { AutoSizerProps } from 'react-virtualized-auto-sizer'; import { configureStore } from 'app/store/configureStore'; @@ -28,6 +29,10 @@ jest.mock('@grafana/ui', () => ({ }, })); +jest.mock('react-virtualized-auto-sizer', () => { + return ({ children }: AutoSizerProps) => children({ height: 1, width: 1 }); +}); + const PayloadEditorWithState = () => { const [payload, setPayload] = useState(DEFAULT_PAYLOAD); return ( diff --git a/public/app/features/alerting/unified/components/receivers/PayloadEditor.tsx b/public/app/features/alerting/unified/components/receivers/PayloadEditor.tsx index 2194fbcb7a1..a306daf7b5f 100644 --- a/public/app/features/alerting/unified/components/receivers/PayloadEditor.tsx +++ b/public/app/features/alerting/unified/components/receivers/PayloadEditor.tsx @@ -1,5 +1,6 @@ import { css } from '@emotion/css'; import React, { useState } from 'react'; +import AutoSizer from 'react-virtualized-auto-sizer'; import { GrafanaTheme2 } from '@grafana/data'; import { Badge, Button, CodeEditor, Icon, Tooltip, useStyles2 } from '@grafana/ui'; @@ -86,17 +87,22 @@ export function PayloadEditor({ - - + + {({ width }) => ( +
+ +
+ )} +
+ )} + {!loading && ( + + )} + + Cancel + +
+ + ) : ( + - - -
- {loading && ( - )} - {!loading && ( - - )} - - Cancel - -
- - ) : ( - - )} + + )} + {isGrafanaAlertManager && ( @@ -237,7 +245,7 @@ export const TemplateForm = ({ existing, alertManagerSourceName, config, provena onPayloadError={onPayloadError} /> )} - + @@ -348,11 +356,13 @@ export function TemplatePreview({ templateName, payloadFormatError, setPayloadFormatError, + width, }: { payload: string; templateName: string; payloadFormatError: string | null; setPayloadFormatError: (value: React.SetStateAction) => void; + width: number; }) { const styles = useStyles2(getStyles); @@ -378,36 +388,41 @@ export function TemplatePreview({ useEffect(() => onPreview(), [onPreview]); return ( - - - {isLoading && ( - <> - Loading preview... - - )} -
-          {previewToRender}
-        
- -
-
+
+ {isLoading && ( + <> + Loading preview... + + )} +
+        {previewToRender}
+      
+ +
); } const getStyles = (theme: GrafanaTheme2) => ({ contentContainer: css` - display: flex; - padding-top: 10px; - gap: ${theme.spacing(2)}; - flex-direction: row; - align-items: flex-start; - flex-wrap: wrap; - ${theme.breakpoints.up('xxl')} { - flex-wrap: nowrap; - } + flex: 1; + margin-bottom: ${theme.spacing(6)}; `, + contentContainerEditor: css` + flex:1; + display: flex; + padding-top: 10px; + gap: ${theme.spacing(2)}; + flex-direction: row; + align-items: flex-start; + flex-wrap: wrap; + ${theme.breakpoints.up('xxl')} { + flex - wrap: nowrap; + } + min-width: 450px; + height: 363px; + `, snippets: css` margin-top: ${theme.spacing(2)}; font-size: ${theme.typography.bodySmall.fontSize}; @@ -417,6 +432,7 @@ const getStyles = (theme: GrafanaTheme2) => ({ font-weight: ${theme.typography.fontWeightBold}; `, buttons: css` + display: flex; & > * + * { margin-left: ${theme.spacing(1)}; } @@ -426,43 +442,39 @@ const getStyles = (theme: GrafanaTheme2) => ({ max-width: 758px; `, editWrapper: css` - display: block; - position: relative; - width: 640px; - height: 363px; - `, - toggle: css({ - color: theme.colors.text.secondary, - marginRight: `${theme.spacing(1)}`, - }), - previewHeader: css({ - display: 'flex', - cursor: 'pointer', - alignItems: 'baseline', - color: theme.colors.text.primary, - '&:hover': { - background: theme.colors.emphasize(theme.colors.background.primary, 0.03), - }, - }), - previewHeaderTitle: css({ - flexGrow: 1, - overflow: 'hidden', - fontSize: theme.typography.h4.fontSize, - fontWeight: theme.typography.fontWeightMedium, - margin: 0, - }), + display: flex; + width: 100% + heigth:100%; + position: relative; + `, + toggle: css` + color: theme.colors.text.secondary, + marginRight: ${theme.spacing(1)}`, preview: { + wrapper: css` + display: flex; + width: 100% + heigth:100%; + position: relative; + flex-direction: column; + `, result: css` - width: 640px; + width: 100%; height: 363px; `, button: css` flex: none; width: fit-content; - margin-top: ${theme.spacing(-3)}; + margin-top: -6px; `, }, collapsableSection: css` width: fit-content; `, + editorsWrapper: css` + display: flex; + flex: 1; + flex-wrap: wrap; + gap: ${theme.spacing(1)}; + `, }); diff --git a/public/app/features/alerting/unified/components/receivers/TemplatePreview.test.tsx b/public/app/features/alerting/unified/components/receivers/TemplatePreview.test.tsx index def4b0edaa3..02b0bd6fba3 100644 --- a/public/app/features/alerting/unified/components/receivers/TemplatePreview.test.tsx +++ b/public/app/features/alerting/unified/components/receivers/TemplatePreview.test.tsx @@ -45,6 +45,7 @@ describe('TemplatePreview component', () => { it('Should render error if payload has wrong format', async () => { render( { const setError = jest.fn(); render( { it('Should render error if payload has wrong format rendering the preview', async () => { render( { mockPreviewTemplateResponseRejected(server); render( { mockPreviewTemplateResponse(server, response); render( { mockPreviewTemplateResponse(server, response); render(