Skip to content

Commit f754f44

Browse files
committed
feat: add dismiss health event
1 parent 9f815cd commit f754f44

4 files changed

Lines changed: 73 additions & 7 deletions

File tree

frontend/common/services/useHealthEvents.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ export const healthService = service
66
.enhanceEndpoints({ addTagTypes: ['HealthEvents'] })
77
.injectEndpoints({
88
endpoints: (builder) => ({
9+
dismissHealthEvent: builder.mutation<
10+
Res['healthEvents'],
11+
Req['dismissHealthEvent']
12+
>({
13+
invalidatesTags: [{ id: 'LIST', type: 'HealthEvents' }],
14+
query: (query: Req['dismissHealthEvent']) => ({
15+
method: 'POST',
16+
url: `projects/${query.projectId}/feature-health/events/${query.eventId}/dismiss/`,
17+
}),
18+
}),
19+
920
getHealthEvents: builder.query<
1021
Res['healthEvents'],
1122
Req['getHealthEvents']
@@ -31,9 +42,22 @@ export async function getHealthEvents(
3142
)
3243
}
3344

45+
export async function dismissHealthEvent(
46+
store: any,
47+
data: Req['dismissHealthEvent'],
48+
options?: Parameters<
49+
typeof healthService.endpoints.dismissHealthEvent.initiate
50+
>[1],
51+
) {
52+
return store.dispatch(
53+
healthService.endpoints.dismissHealthEvent.initiate(data, options),
54+
)
55+
}
56+
3457
// END OF FUNCTION_EXPORTS
3558

3659
export const {
60+
useDismissHealthEventMutation,
3761
useGetHealthEventsQuery,
3862
// END OF EXPORTS
3963
} = healthService

frontend/common/types/requests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ export type Req = {
192192
getAvailablePermissions: { level: PermissionLevel }
193193
getTag: { id: string }
194194
getHealthEvents: { projectId: number | string }
195+
dismissHealthEvent: { projectId: number | string; eventId: number }
195196
getHealthProviders: { projectId: number }
196197
createHealthProvider: { projectId: number; name: string }
197198
deleteHealthProvider: { projectId: number; name: string }

frontend/common/types/responses.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ export type HealthEventReason = {
719719
}
720720

721721
export type HealthEvent = {
722+
id: number
722723
created_at: string
723724
environment: number
724725
feature: number

frontend/web/components/modals/FeatureHealthTabContent.tsx

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import React, { useState } from 'react'
1+
import React, { useEffect, useState } from 'react'
22
import Icon from 'components/Icon'
33
import Constants from 'common/constants'
4-
import { useGetHealthEventsQuery } from 'common/services/useHealthEvents'
4+
import {
5+
useDismissHealthEventMutation,
6+
useGetHealthEventsQuery,
7+
} from 'common/services/useHealthEvents'
58
import Button from 'components/base/forms/Button'
69
import moment from 'moment'
710
import Collapse from '@material-ui/core/Collapse'
@@ -113,6 +116,25 @@ const FeatureHealthTabContent: React.FC<FeatureHealthTabContentProps> = ({
113116
{ skip: !projectId },
114117
)
115118

119+
const [dismissHealthEvent, { error: dismissError, isSuccess: isDismissed }] =
120+
useDismissHealthEventMutation()
121+
122+
useEffect(() => {
123+
if (isDismissed) {
124+
toast('Event dismissed')
125+
}
126+
}, [isDismissed])
127+
128+
useEffect(() => {
129+
if (dismissError) {
130+
toast('Failed to dismiss event', 'danger')
131+
}
132+
}, [dismissError])
133+
134+
const handleDismiss = (eventId: number) => {
135+
dismissHealthEvent({ eventId, projectId })
136+
}
137+
116138
if (isLoading) {
117139
return (
118140
<div className='text-center'>
@@ -143,13 +165,31 @@ const FeatureHealthTabContent: React.FC<FeatureHealthTabContentProps> = ({
143165
className='ms-1 mr-1'
144166
icon={warning}
145167
/>
146-
<h6 className='mb-0'>{event.provider_name} Provider</h6>
168+
<div>
169+
<Row>
170+
<h6 className='mb-0'>{event.provider_name} Provider</h6>
171+
<div className='ml-2'>
172+
<Tooltip title={moment(event.created_at).fromNow()}>
173+
{moment(event.created_at).format('Do MMM YYYY HH:mma')}
174+
</Tooltip>
175+
</div>
176+
</Row>
177+
</div>
147178
</div>
148-
<div>
149-
<Tooltip title={moment(event.created_at).fromNow()}>
150-
{moment(event.created_at).format('Do MMM YYYY HH:mma')}
179+
<Row>
180+
<Button
181+
className='mr-1'
182+
size='xSmall'
183+
theme='secondary'
184+
onClick={() => handleDismiss(event.id)}
185+
>
186+
Dismiss
187+
</Button>
188+
<Tooltip title={<Icon width={18} name='info-outlined' />}>
189+
When dismissed, this event will no longer be shown in the
190+
Unhealthy Events list.
151191
</Tooltip>
152-
</div>
192+
</Row>
153193
</div>
154194
<div className='d-flex' style={{ gap: 96 }}>
155195
<EventTextBlocks textBlocks={event?.reason?.text_blocks} />

0 commit comments

Comments
 (0)