11import React , { ReactElement , useEffect } from 'react'
2- import { Button , ConfirmModal , FieldSet , LegacyForms , Switch , Tab , TabContent , TabsBar } from '@grafana/ui'
2+ import { Button , Modal , ConfirmModal , FieldSet , LegacyForms , Switch , Tab , TabContent , TabsBar , Icon } from '@grafana/ui'
33import type { EditorProps } from './types'
44import { useChangeSecureOptions } from './useChangeSecureOptions'
55import { useResetSecureOptions } from './useResetSecureOptions'
@@ -48,6 +48,10 @@ export function ConfigEditor(props: EditorProps): ReactElement {
4848 } , [ ] ) ;
4949
5050 const [ openConfirm , setOpenConfirm ] = React . useState ( false ) ;
51+
52+ const [ openAlert , setOpenAlert ] = React . useState ( false ) ;
53+
54+ const [ openAlertMessage , setOpenAlertMessage ] = React . useState ( "" ) ;
5155 /**
5256 * Here is the cleaning of alarm rules.
5357 * When executing the onConfirm method, the testDatasource() function will be called,making it difficult to distinguish whether to delete or add.
@@ -57,9 +61,11 @@ export function ConfigEditor(props: EditorProps): ReactElement {
5761 updateLoadStatus ( false ) ;
5862 setOpenConfirm ( false ) ;
5963 deleteAlerts ( props . options . uid ) . then ( ( ) => {
60- console . info ( "alert deleted!" ) ;
64+ return ;
6165 } ) . catch ( ( e : any ) => {
62- alert ( "Failed to delete alarm rules, reason: " + e . message )
66+ setOpenAlert ( true ) ;
67+ setOpenAlertMessage ( "Failed to delete alarm rules, reason: " + e . message )
68+ throw e ;
6369 } ) ;
6470
6571 } ;
@@ -203,6 +209,12 @@ export function ConfigEditor(props: EditorProps): ReactElement {
203209 onConfirm = { ( ) => setOpenConfirm ( false ) }
204210 onDismiss = { ( ) => clearAlertRules ( ) }
205211 />
212+
213+ < Modal isOpen = { openAlert } title = { < div > < Icon name = 'x' color = 'red' size = 'xxl' /> < label style = { { color : 'red' , fontSize : '16px' } } > Failed to delete rules</ label > </ div > } onDismiss = { ( ) => setOpenAlert ( false ) } >
214+ < p style = { { fontSize : '16px' } } > { openAlertMessage } </ p >
215+ </ Modal >
216+
217+
206218 </ FieldSet >
207219 ) }
208220 </ div >
0 commit comments