Skip to content

Commit 7ef35f9

Browse files
tiagoapoloZaimwa9
andauthored
feat: adds dismiss health event (#5863)
Co-authored-by: Zaimwa9 <wadii.zaim@flagsmith.com>
1 parent c1a7c10 commit 7ef35f9

5 files changed

Lines changed: 78 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/CreateFlag.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,7 @@ const CreateFlag = class extends Component {
19341934
>
19351935
<FeatureHealthTabContent
19361936
projectId={projectFlag.project}
1937+
environmentId={this.props.environmentId}
19371938
/>
19381939
</TabItem>
19391940
)}

frontend/web/components/modals/FeatureHealthTabContent.tsx

Lines changed: 51 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'
@@ -11,9 +14,11 @@ import {
1114
FeatureHealthEventReasonTextBlock,
1215
FeatureHealthEventReasonUrlBlock,
1316
} from 'common/types/responses'
17+
import AppActions from 'common/dispatcher/app-actions'
1418

1519
type FeatureHealthTabContentProps = {
1620
projectId: number
21+
environmentId: number
1722
}
1823

1924
const EventTextBlocks = ({
@@ -106,13 +111,34 @@ const EventURLBlocks = ({
106111
}
107112

108113
const 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

Comments
 (0)