From 97802e44a6877482dff93bc37d2938c433cf2218 Mon Sep 17 00:00:00 2001
From: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com>
Date: Mon, 8 May 2023 11:32:46 +0200
Subject: [PATCH] Alerting: Make two boxes in template form adaptative to the
screen (#67967)
Make two boxes in template form adaptative to the screen width to be align in the same line when possible
---
.../receivers/PayloadEditor.test.tsx | 5 +
.../components/receivers/PayloadEditor.tsx | 45 ++--
.../components/receivers/TemplateForm.tsx | 200 ++++++++++--------
.../receivers/TemplatePreview.test.tsx | 6 +
4 files changed, 148 insertions(+), 108 deletions(-)
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 }) => (
+
+
+
+ )}
+