From f0aee6e57dddfadcaa600f5cc5b8f4ed63d12e7a Mon Sep 17 00:00:00 2001 From: Yulia Shanyrova Date: Tue, 13 Jun 2023 17:06:32 +0200 Subject: [PATCH] result showing improving (#2214) result showing improving --- .../TemplatePreview/TemplatePreview.tsx | 56 ++++++++++++------- .../pages/integrations_2/Integrations2.tsx | 4 +- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/grafana-plugin/src/containers/TemplatePreview/TemplatePreview.tsx b/grafana-plugin/src/containers/TemplatePreview/TemplatePreview.tsx index e268ef25..15aeff41 100644 --- a/grafana-plugin/src/containers/TemplatePreview/TemplatePreview.tsx +++ b/grafana-plugin/src/containers/TemplatePreview/TemplatePreview.tsx @@ -26,13 +26,16 @@ interface TemplatePreviewProps { active?: boolean; onResult?: (result) => void; } +interface ConditionalResult { + isResult?: boolean; + value?: string; +} const TemplatePreview = observer((props: TemplatePreviewProps) => { const { templateName, templateBody, payload, alertReceiveChannelId, alertGroupId } = props; const [result, setResult] = useState<{ preview: string | null } | undefined>(undefined); - const [isCondition, setIsCondition] = useState(false); - // const [conditionalResult, setConditionalResult] = useState() + const [conditionalResult, setConditionalResult] = useState({}); const store = useStore(); const { alertReceiveChannelStore, alertGroupStore } = store; @@ -45,9 +48,11 @@ const TemplatePreview = observer((props: TemplatePreviewProps) => { .then((data) => { setResult(data); if (data?.preview === 'True') { - setIsCondition(true); + setConditionalResult({ isResult: true, value: 'True' }); + } else if (data?.preview === 'False') { + setConditionalResult({ isResult: true, value: 'False' }); } else { - setIsCondition(false); + setConditionalResult({ isResult: false, value: undefined }); } }) .catch((err) => { @@ -61,18 +66,34 @@ const TemplatePreview = observer((props: TemplatePreviewProps) => { useEffect(handleTemplateBodyChange, [templateBody, payload]); + const conditionalMessage = (success: boolean) => { + if (templateName.includes('route')) { + return ( + + Selected alert will {!success && not} be matched with this route + + ); + } else { + return ( + + Selected alert will {!success && not}{' '} + {`${templateName.substring(0, templateName.indexOf('_'))} alert group`} + + ); + } + }; + return result ? ( <> - {templateName.includes('condition_template') ? ( - - {isCondition ? ( - <> - True - {`Selected alert will ${templateName.substring( - 0, - templateName.indexOf('_') - )} alert group`} - + {conditionalResult?.isResult ? ( + + {conditionalResult.isResult ? ( + + + {conditionalResult.value} + + {conditionalMessage(conditionalResult.value === 'True')} + ) : ( @@ -84,10 +105,7 @@ const TemplatePreview = observer((props: TemplatePreviewProps) => { }} /> - {`Selected alert will not ${templateName.substring( - 0, - templateName.indexOf('_') - )} alert group`} + {conditionalMessage(conditionalResult.value === 'True')} )} @@ -101,7 +119,7 @@ const TemplatePreview = observer((props: TemplatePreviewProps) => {
') || ''), + __html: sanitize(result.preview?.replace(/\n/g, '
') || ''), }} /> )} diff --git a/grafana-plugin/src/pages/integrations_2/Integrations2.tsx b/grafana-plugin/src/pages/integrations_2/Integrations2.tsx index 746d8aa3..03d907aa 100644 --- a/grafana-plugin/src/pages/integrations_2/Integrations2.tsx +++ b/grafana-plugin/src/pages/integrations_2/Integrations2.tsx @@ -276,8 +276,8 @@ class Integrations extends React.Component MAX_LINE_LENGTH - ? item.verbal_name.substring(0, MAX_LINE_LENGTH) + '...' + item.verbal_name?.length > MAX_LINE_LENGTH + ? item.verbal_name?.substring(0, MAX_LINE_LENGTH) + '...' : item.verbal_name } />