-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix alert groups automatic refresh #4463
Changes from all commits
ed6ee6d
193a557
32fe6cc
60a681a
0c68060
a4a863f
14407b5
a403811
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { ActionKey } from 'models/loader/action-keys'; | ||
import { makeRequest } from 'network/network'; | ||
import { ApiSchemas } from 'network/oncall-api/api.types'; | ||
import { onCallApi } from 'network/oncall-api/http-client'; | ||
import { AutoLoadingState } from 'utils/decorators'; | ||
|
||
import { AlertGroupStore } from './alertgroup'; | ||
|
||
|
@@ -33,6 +35,26 @@ export class AlertGroupHelper { | |
return (await onCallApi().POST('/alertgroups/bulk_action/', { params: {}, body: data })).data; | ||
} | ||
|
||
@AutoLoadingState(ActionKey.INCIDENTS_BULK_UPDATE) | ||
static async updateBulkActionAndRefresh( | ||
data: ApiSchemas['AlertGroupBulkActionRequest'], | ||
alertGroupStore: AlertGroupStore, | ||
onFinally?: () => void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This made more sense to be here rather than in the component, it also accepts |
||
) { | ||
try { | ||
alertGroupStore.setLiveUpdatesPaused(true); | ||
|
||
await AlertGroupHelper.bulkAction(data); | ||
|
||
// pull new data | ||
await alertGroupStore.fetchAlertGroups(); | ||
} finally { | ||
alertGroupStore.setLiveUpdatesPaused(false); | ||
|
||
onFinally?.(); | ||
} | ||
brojd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
static async renderPreview(id: ApiSchemas['AlertGroup']['pk'], template_name: string, template_body: string) { | ||
return ( | ||
await onCallApi().POST('/alertgroups/{id}/preview_template/', { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,7 @@ export class AlertGroupStore { | |
const newAlerts = new Map( | ||
results.map((alert: ApiSchemas['AlertGroup']) => { | ||
const oldAlert = this.alerts.get(alert.pk) || {}; | ||
const mergedAlertData = { ...oldAlert, ...alert, undoAction: alert.undoAction }; | ||
const mergedAlertData = { ...oldAlert, ...alert }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the |
||
return [alert.pk, mergedAlertData]; | ||
}) | ||
); | ||
|
@@ -114,7 +114,8 @@ export class AlertGroupStore { | |
this.rootStore.setPageTitle(`#${alertGroup.inside_organization_number} ${alertGroup.render_for_web.title}`); | ||
} | ||
|
||
async fetchIncidentsAndStats(isPollingJob = false) { | ||
@AutoLoadingState(ActionKey.FETCH_INCIDENTS_AND_STATS) | ||
async fetchIncidentsAndStats(isPollingJob = false): Promise<void> { | ||
await Promise.all([ | ||
this.fetchStats(IncidentStatus.Firing), | ||
this.fetchStats(IncidentStatus.Acknowledged), | ||
|
@@ -218,13 +219,11 @@ export class AlertGroupStore { | |
composeFailureMessageFn, | ||
}) | ||
async resolve(id: ApiSchemas['AlertGroup']['pk']) { | ||
this.setLiveUpdatesPaused(true); | ||
const { data } = await onCallApi({ skipErrorHandling: true }).POST('/alertgroups/{id}/resolve/', { | ||
params: { path: { id } }, | ||
}); | ||
this.updateAlert(id, { | ||
...data, | ||
undoAction: AlertAction.Resolve, | ||
}); | ||
} | ||
|
||
|
@@ -233,11 +232,9 @@ export class AlertGroupStore { | |
composeFailureMessageFn, | ||
}) | ||
async unresolve(id: ApiSchemas['AlertGroup']['pk']) { | ||
this.setLiveUpdatesPaused(true); | ||
const { data } = await onCallApi().POST('/alertgroups/{id}/unresolve/', { params: { path: { id } } }); | ||
this.updateAlert(id, { | ||
...data, | ||
undoAction: AlertAction.unResolve, | ||
}); | ||
} | ||
|
||
|
@@ -246,11 +243,9 @@ export class AlertGroupStore { | |
composeFailureMessageFn, | ||
}) | ||
async acknowledge(id: ApiSchemas['AlertGroup']['pk']) { | ||
this.setLiveUpdatesPaused(true); | ||
const { data } = await onCallApi().POST('/alertgroups/{id}/acknowledge/', { params: { path: { id } } }); | ||
this.updateAlert(id, { | ||
...data, | ||
undoAction: AlertAction.Acknowledge, | ||
}); | ||
} | ||
|
||
|
@@ -259,11 +254,9 @@ export class AlertGroupStore { | |
composeFailureMessageFn, | ||
}) | ||
async unacknowledge(id: ApiSchemas['AlertGroup']['pk']) { | ||
this.setLiveUpdatesPaused(true); | ||
const { data } = await onCallApi().POST('/alertgroups/{id}/unacknowledge/', { params: { path: { id } } }); | ||
this.updateAlert(id, { | ||
...data, | ||
undoAction: AlertAction.unAcknowledge, | ||
}); | ||
} | ||
|
||
|
@@ -272,14 +265,12 @@ export class AlertGroupStore { | |
composeFailureMessageFn, | ||
}) | ||
async silence(id: ApiSchemas['AlertGroup']['pk'], delay: number) { | ||
this.setLiveUpdatesPaused(true); | ||
const { data } = await onCallApi().POST('/alertgroups/{id}/silence/', { | ||
params: { path: { id } }, | ||
body: { delay }, | ||
}); | ||
this.updateAlert(id, { | ||
...data, | ||
undoAction: AlertAction.Silence, | ||
}); | ||
} | ||
|
||
|
@@ -288,11 +279,9 @@ export class AlertGroupStore { | |
composeFailureMessageFn, | ||
}) | ||
async unsilence(id: ApiSchemas['AlertGroup']['pk']) { | ||
this.setLiveUpdatesPaused(true); | ||
const { data } = await onCallApi().POST('/alertgroups/{id}/unsilence/', { params: { path: { id } } }); | ||
this.updateAlert(id, { | ||
...data, | ||
undoAction: AlertAction.unSilence, | ||
}); | ||
} | ||
|
||
|
@@ -305,8 +294,14 @@ export class AlertGroupStore { | |
[AlertAction.Resolve]: this.resolve, | ||
[AlertAction.unResolve]: this.unresolve, | ||
}; | ||
|
||
if (actionToMethodMap[action]) { | ||
await actionToMethodMap[action](id, delay); | ||
try { | ||
this.setLiveUpdatesPaused(true); | ||
await actionToMethodMap[action](id, delay); | ||
} finally { | ||
this.setLiveUpdatesPaused(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Centralizing these 2 calls here rather than in each method |
||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exporting these to have the typing needed in Incidents for now. This might need some additional work as we're missing a lot of typescript on the filters, but it's out of scope for this PR.