1- import React , { useState } from 'react'
1+ import React , { useEffect , useState } from 'react'
22import Icon from 'components/Icon'
33import Constants from 'common/constants'
4- import { useGetHealthEventsQuery } from 'common/services/useHealthEvents'
4+ import {
5+ useDismissHealthEventMutation ,
6+ useGetHealthEventsQuery ,
7+ } from 'common/services/useHealthEvents'
58import Button from 'components/base/forms/Button'
69import moment from 'moment'
710import Collapse from '@material-ui/core/Collapse'
@@ -11,9 +14,11 @@ import {
1114 FeatureHealthEventReasonTextBlock ,
1215 FeatureHealthEventReasonUrlBlock ,
1316} from 'common/types/responses'
17+ import AppActions from 'common/dispatcher/app-actions'
1418
1519type FeatureHealthTabContentProps = {
1620 projectId : number
21+ environmentId : number
1722}
1823
1924const EventTextBlocks = ( {
@@ -106,13 +111,34 @@ const EventURLBlocks = ({
106111}
107112
108113const FeatureHealthTabContent : React . FC < FeatureHealthTabContentProps > = ( {
114+ environmentId,
109115 projectId,
110116} ) => {
111117 const { data : healthEvents , isLoading } = useGetHealthEventsQuery (
112118 { projectId : String ( projectId ) } ,
113119 { skip : ! projectId } ,
114120 )
115121
122+ const [ dismissHealthEvent , { error : dismissError , isSuccess : isDismissed } ] =
123+ useDismissHealthEventMutation ( )
124+
125+ useEffect ( ( ) => {
126+ if ( isDismissed ) {
127+ toast ( 'Event dismissed' )
128+ AppActions . refreshFeatures ( projectId , environmentId )
129+ }
130+ } , [ isDismissed , projectId , environmentId ] )
131+
132+ useEffect ( ( ) => {
133+ if ( dismissError ) {
134+ toast ( 'Failed to dismiss event' , 'danger' )
135+ }
136+ } , [ dismissError ] )
137+
138+ const handleDismiss = ( eventId : number ) => {
139+ dismissHealthEvent ( { eventId, projectId } )
140+ }
141+
116142 if ( isLoading ) {
117143 return (
118144 < div className = 'text-center' >
@@ -143,13 +169,31 @@ const FeatureHealthTabContent: React.FC<FeatureHealthTabContentProps> = ({
143169 className = 'ms-1 mr-1'
144170 icon = { warning }
145171 />
146- < h6 className = 'mb-0' > { event . provider_name } Provider</ h6 >
172+ < div >
173+ < Row >
174+ < h6 className = 'mb-0' > { event . provider_name } Provider</ h6 >
175+ < div className = 'ml-2' >
176+ < Tooltip title = { moment ( event . created_at ) . fromNow ( ) } >
177+ { moment ( event . created_at ) . format ( 'Do MMM YYYY HH:mma' ) }
178+ </ Tooltip >
179+ </ div >
180+ </ Row >
181+ </ div >
147182 </ div >
148- < div >
149- < Tooltip title = { moment ( event . created_at ) . fromNow ( ) } >
150- { moment ( event . created_at ) . format ( 'Do MMM YYYY HH:mma' ) }
183+ < Row >
184+ < Button
185+ className = 'mr-1'
186+ size = 'xSmall'
187+ theme = 'secondary'
188+ onClick = { ( ) => handleDismiss ( event . id ) }
189+ >
190+ Dismiss
191+ </ Button >
192+ < Tooltip title = { < Icon width = { 18 } name = 'info-outlined' /> } >
193+ When dismissed, this event will no longer be shown in the
194+ Unhealthy Events list.
151195 </ Tooltip >
152- </ div >
196+ </ Row >
153197 </ div >
154198 < div className = 'd-flex' style = { { gap : 96 } } >
155199 < EventTextBlocks textBlocks = { event ?. reason ?. text_blocks } />
0 commit comments