From ed6ee6d7de9e8ca12856b17e0de8a7105687eeb1 Mon Sep 17 00:00:00 2001 From: Rares Mardare Date: Wed, 5 Jun 2024 12:10:05 +0300 Subject: [PATCH 1/7] fixed polling in AG --- .../src/models/alertgroup/alertgroup.ts | 14 ++++---- .../src/pages/incidents/Incidents.tsx | 36 ++++++++++++------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/grafana-plugin/src/models/alertgroup/alertgroup.ts b/grafana-plugin/src/models/alertgroup/alertgroup.ts index f3c9397202..13782b7541 100644 --- a/grafana-plugin/src/models/alertgroup/alertgroup.ts +++ b/grafana-plugin/src/models/alertgroup/alertgroup.ts @@ -218,7 +218,6 @@ 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 } }, }); @@ -233,7 +232,6 @@ 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, @@ -246,7 +244,6 @@ 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, @@ -259,7 +256,6 @@ 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, @@ -272,7 +268,6 @@ 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 }, @@ -288,7 +283,6 @@ 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, @@ -305,8 +299,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); + } } } diff --git a/grafana-plugin/src/pages/incidents/Incidents.tsx b/grafana-plugin/src/pages/incidents/Incidents.tsx index 1924e014c4..3acef04a2b 100644 --- a/grafana-plugin/src/pages/incidents/Incidents.tsx +++ b/grafana-plugin/src/pages/incidents/Incidents.tsx @@ -942,12 +942,25 @@ class _IncidentsPage extends React.Component { const { selectedIncidentIds, affectedRows } = this.state; - const { store } = this.props; - - this.setPollingInterval(); + const { + store: { alertGroupStore }, + } = this.props; - store.alertGroupStore.setLiveUpdatesPaused(true); const delay = typeof event === 'number' ? event : 0; + const onStateUpdate = async () => { + this.setPollingInterval(); + + try { + alertGroupStore.setLiveUpdatesPaused(true); + await AlertGroupHelper.bulkAction({ + action, + alert_group_pks: selectedIncidentIds, + delay, + }); + } finally { + alertGroupStore.setLiveUpdatesPaused(false); + } + }; this.setState( { @@ -960,13 +973,7 @@ class _IncidentsPage extends React.Component { - AlertGroupHelper.bulkAction({ - action, - alert_group_pks: selectedIncidentIds, - delay, - }); - } + onStateUpdate ); }; @@ -988,13 +995,15 @@ class _IncidentsPage extends React.Component { const isBrowserWindowInactive = document.hidden; + const { liveUpdatesPaused } = this.props.store.alertGroupStore; + if ( + !liveUpdatesPaused && !isBrowserWindowInactive && !LoaderHelper.isLoading(this.props.store.loaderStore, [ ActionKey.FETCH_INCIDENTS, ActionKey.FETCH_INCIDENTS_POLLING, - ]) && - !this.props.store.alertGroupStore.liveUpdatesPaused + ]) ) { await this.props.store.alertGroupStore.fetchIncidentsAndStats(true); } @@ -1002,6 +1011,7 @@ class _IncidentsPage extends React.Component Date: Wed, 5 Jun 2024 14:08:22 +0300 Subject: [PATCH 2/7] ag reload fixes --- .../models/alertgroup/alertgroup.helpers.ts | 22 +++++ .../src/models/alertgroup/alertgroup.ts | 8 +- .../src/models/loader/action-keys.ts | 2 + .../types-generator/custom-schemas.ts | 3 - .../src/pages/incidents/Incidents.tsx | 89 ++++++------------- 5 files changed, 54 insertions(+), 70 deletions(-) diff --git a/grafana-plugin/src/models/alertgroup/alertgroup.helpers.ts b/grafana-plugin/src/models/alertgroup/alertgroup.helpers.ts index 0aa4c69283..542d6f2fe1 100644 --- a/grafana-plugin/src/models/alertgroup/alertgroup.helpers.ts +++ b/grafana-plugin/src/models/alertgroup/alertgroup.helpers.ts @@ -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 + ) { + try { + alertGroupStore.setLiveUpdatesPaused(true); + + await AlertGroupHelper.bulkAction(data); + + // pull new data + await alertGroupStore.fetchAlertGroups(); + } finally { + alertGroupStore.setLiveUpdatesPaused(false); + + onFinally?.(); + } + } + static async renderPreview(id: ApiSchemas['AlertGroup']['pk'], template_name: string, template_body: string) { return ( await onCallApi().POST('/alertgroups/{id}/preview_template/', { diff --git a/grafana-plugin/src/models/alertgroup/alertgroup.ts b/grafana-plugin/src/models/alertgroup/alertgroup.ts index 13782b7541..8cc90d6415 100644 --- a/grafana-plugin/src/models/alertgroup/alertgroup.ts +++ b/grafana-plugin/src/models/alertgroup/alertgroup.ts @@ -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 }; return [alert.pk, mergedAlertData]; }) ); @@ -223,7 +223,6 @@ export class AlertGroupStore { }); this.updateAlert(id, { ...data, - undoAction: AlertAction.Resolve, }); } @@ -235,7 +234,6 @@ export class AlertGroupStore { const { data } = await onCallApi().POST('/alertgroups/{id}/unresolve/', { params: { path: { id } } }); this.updateAlert(id, { ...data, - undoAction: AlertAction.unResolve, }); } @@ -247,7 +245,6 @@ export class AlertGroupStore { const { data } = await onCallApi().POST('/alertgroups/{id}/acknowledge/', { params: { path: { id } } }); this.updateAlert(id, { ...data, - undoAction: AlertAction.Acknowledge, }); } @@ -259,7 +256,6 @@ export class AlertGroupStore { const { data } = await onCallApi().POST('/alertgroups/{id}/unacknowledge/', { params: { path: { id } } }); this.updateAlert(id, { ...data, - undoAction: AlertAction.unAcknowledge, }); } @@ -274,7 +270,6 @@ export class AlertGroupStore { }); this.updateAlert(id, { ...data, - undoAction: AlertAction.Silence, }); } @@ -286,7 +281,6 @@ export class AlertGroupStore { const { data } = await onCallApi().POST('/alertgroups/{id}/unsilence/', { params: { path: { id } } }); this.updateAlert(id, { ...data, - undoAction: AlertAction.unSilence, }); } diff --git a/grafana-plugin/src/models/loader/action-keys.ts b/grafana-plugin/src/models/loader/action-keys.ts index 0b093adb53..ba8ac1760f 100644 --- a/grafana-plugin/src/models/loader/action-keys.ts +++ b/grafana-plugin/src/models/loader/action-keys.ts @@ -8,6 +8,8 @@ export enum ActionKey { FETCH_INCIDENTS = 'FETCH_INCIDENTS', FETCH_INCIDENTS_POLLING = 'FETCH_INCIDENTS_POLLING', FETCH_INCIDENTS_AND_STATS = 'FETCH_INCIDENTS_AND_STATS', + INCIDENTS_BULK_UPDATE = 'INCIDENTS_BULK_UPDATE', + UPDATE_FILTERS_AND_FETCH_INCIDENTS = 'UPDATE_FILTERS_AND_FETCH_INCIDENTS', UPDATE_SERVICENOW_TOKEN = 'UPDATE_SERVICENOW_TOKEN', FETCH_INTEGRATIONS = 'FETCH_INTEGRATIONS', diff --git a/grafana-plugin/src/network/oncall-api/types-generator/custom-schemas.ts b/grafana-plugin/src/network/oncall-api/types-generator/custom-schemas.ts index 193d65b86a..67eb8858e9 100644 --- a/grafana-plugin/src/network/oncall-api/types-generator/custom-schemas.ts +++ b/grafana-plugin/src/network/oncall-api/types-generator/custom-schemas.ts @@ -1,5 +1,3 @@ -import { AlertAction } from 'models/alertgroup/alertgroup.types'; - // Custom properties not exposed by OpenAPI schema should be defined here export type CustomApiSchemas = { Webhook: { @@ -15,7 +13,6 @@ export type CustomApiSchemas = { }; }; AlertGroup: { - undoAction: AlertAction; loading?: boolean; created_at?: string; }; diff --git a/grafana-plugin/src/pages/incidents/Incidents.tsx b/grafana-plugin/src/pages/incidents/Incidents.tsx index 3acef04a2b..f5c268c2e9 100644 --- a/grafana-plugin/src/pages/incidents/Incidents.tsx +++ b/grafana-plugin/src/pages/incidents/Incidents.tsx @@ -73,7 +73,6 @@ interface IncidentsPageProps extends WithStoreProps, PageProps, RouteComponentPr interface IncidentsPageState { selectedIncidentIds: Array; - affectedRows: { [key: string]: boolean }; filters?: Record; pagination: Pagination; showAddAlertGroupForm: boolean; @@ -128,7 +127,6 @@ class _IncidentsPage extends React.Component { - const { selectedIncidentIds, affectedRows, isHorizontalScrolling } = this.state; + const { selectedIncidentIds, isHorizontalScrolling } = this.state; const { store, theme } = this.props; if (!store.alertGroupStore.bulkActions) { return null; } - const { results } = AlertGroupHelper.getAlertSearchResult(store.alertGroupStore); - const hasSelected = selectedIncidentIds.length > 0; - const isLoading = LoaderHelper.isLoading(store.loaderStore, ActionKey.FETCH_INCIDENTS); - const hasInvalidatedAlert = Boolean( - (results && results.some((alert: ApiSchemas['AlertGroup']) => alert.undoAction)) || - Object.keys(affectedRows).length - ); + const isLoading = LoaderHelper.isLoading(store.loaderStore, [ + ActionKey.FETCH_INCIDENTS, + ActionKey.FETCH_INCIDENTS_POLLING, + ActionKey.FETCH_INCIDENTS_AND_STATS, + ActionKey.INCIDENTS_BULK_UPDATE, + ]); const styles = getStyles(theme); + const isBulkUpdate = LoaderHelper.isLoading(store.loaderStore, ActionKey.INCIDENTS_BULK_UPDATE); return (
@@ -453,9 +450,9 @@ class _IncidentsPage extends React.Component @@ -464,9 +461,9 @@ class _IncidentsPage extends React.Component @@ -475,9 +472,9 @@ class _IncidentsPage extends React.Component @@ -486,8 +483,8 @@ class _IncidentsPage extends React.Component this.getBulkActionClickHandler('silence', ev)} + disabled={!hasSelected || isBulkUpdate} + onSelect={(ev) => this.onBulkActionClick('silence', ev)} /> )} @@ -499,15 +496,6 @@ class _IncidentsPage extends React.Component
- - - Results out of date - - - - @@ -940,49 +928,30 @@ class _IncidentsPage extends React.Component { - const { selectedIncidentIds, affectedRows } = this.state; - const { - store: { alertGroupStore }, - } = this.props; + onBulkActionClick = async (action: ApiSchemas['AlertGroupBulkActionRequest']['action'], event?: any) => { + const { selectedIncidentIds } = this.state; + const { alertGroupStore } = this.props.store; const delay = typeof event === 'number' ? event : 0; - const onStateUpdate = async () => { - this.setPollingInterval(); - - try { - alertGroupStore.setLiveUpdatesPaused(true); - await AlertGroupHelper.bulkAction({ - action, - alert_group_pks: selectedIncidentIds, - delay, - }); - } finally { - alertGroupStore.setLiveUpdatesPaused(false); - } - }; - this.setState( + this.setPollingInterval(); + + await AlertGroupHelper.updateBulkActionAndRefresh( { - selectedIncidentIds: [], - affectedRows: selectedIncidentIds.reduce( - (acc, incidentId: ApiSchemas['AlertGroup']['pk']) => ({ - ...acc, - [incidentId]: true, - }), - affectedRows - ), + action, + alert_group_pks: selectedIncidentIds, + delay, }, - onStateUpdate + alertGroupStore, + // clear selected incident on finally + () => this.setState({ selectedIncidentIds: [] }) ); }; onIncidentsUpdateClick = () => { const { store } = this.props; - this.setState({ affectedRows: {} }, () => { - store.alertGroupStore.fetchIncidentsAndStats(); - }); + store.alertGroupStore.fetchIncidentsAndStats(); }; clearPollingInterval() { From 32fe6cc42758416824f4b19a4a99d1a1a6449853 Mon Sep 17 00:00:00 2001 From: Rares Mardare Date: Wed, 5 Jun 2024 14:26:15 +0300 Subject: [PATCH 3/7] tweaks --- .../RemoteFilters/RemoteFilters.tsx | 2 +- .../src/models/alertgroup/alertgroup.ts | 3 +- .../src/pages/incidents/Incidents.tsx | 32 +++++++++---------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.tsx b/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.tsx index a7ec0582c9..e79edd3568 100644 --- a/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.tsx +++ b/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.tsx @@ -48,7 +48,7 @@ interface RemoteFiltersProps extends WithStoreProps { grafanaTeamStore: GrafanaTeamStore; skipFilterOptionFn?: (filterOption: FilterOption) => boolean; } -interface RemoteFiltersState { +export interface RemoteFiltersState { filterOptions?: FilterOption[]; filters: FilterOption[]; values: Record; diff --git a/grafana-plugin/src/models/alertgroup/alertgroup.ts b/grafana-plugin/src/models/alertgroup/alertgroup.ts index 8cc90d6415..d050eec30b 100644 --- a/grafana-plugin/src/models/alertgroup/alertgroup.ts +++ b/grafana-plugin/src/models/alertgroup/alertgroup.ts @@ -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 { await Promise.all([ this.fetchStats(IncidentStatus.Firing), this.fetchStats(IncidentStatus.Acknowledged), diff --git a/grafana-plugin/src/pages/incidents/Incidents.tsx b/grafana-plugin/src/pages/incidents/Incidents.tsx index f5c268c2e9..634c46e19a 100644 --- a/grafana-plugin/src/pages/incidents/Incidents.tsx +++ b/grafana-plugin/src/pages/incidents/Incidents.tsx @@ -34,7 +34,7 @@ import { Tutorial } from 'components/Tutorial/Tutorial'; import { TutorialStep } from 'components/Tutorial/Tutorial.types'; import { ColumnsSelectorWrapper } from 'containers/ColumnsSelectorWrapper/ColumnsSelectorWrapper'; import { IncidentsFiltersType } from 'containers/IncidentsFilters/IncidentFilters.types'; -import { RemoteFilters } from 'containers/RemoteFilters/RemoteFilters'; +import { RemoteFilters, RemoteFiltersState } from 'containers/RemoteFilters/RemoteFilters'; import { TeamName } from 'containers/TeamName/TeamName'; import { WithPermissionControlTooltip } from 'containers/WithPermissionControl/WithPermissionControlTooltip'; import { AlertReceiveChannelHelper } from 'models/alert_receive_channel/alert_receive_channel.helpers'; @@ -200,10 +200,17 @@ class _IncidentsPage extends React.Component void) => void, + filtersOnFiltersValueChange: (status: string, newStatuses: string[]) => void, + store: RootStore, + theme: GrafanaTheme2 + ) { const { values } = filtersState; const { stats } = store.alertGroupStore; + const status = values.status || []; const styles = getStyles(theme); @@ -218,7 +225,7 @@ class _IncidentsPage extends React.Component @@ -232,7 +239,7 @@ class _IncidentsPage extends React.Component @@ -246,7 +253,7 @@ class _IncidentsPage extends React.Component @@ -260,7 +267,7 @@ class _IncidentsPage extends React.Component @@ -271,13 +278,12 @@ class _IncidentsPage extends React.Component void) => void, + filtersOnFiltersValueChange: (status: string, newStatuses: string[]) => void ) => { return (selected: boolean) => { const { values } = filtersState; - const { status: statusFilter = [] } = values; let newStatuses = [...statusFilter]; @@ -948,12 +954,6 @@ class _IncidentsPage extends React.Component { - const { store } = this.props; - - store.alertGroupStore.fetchIncidentsAndStats(); - }; - clearPollingInterval() { clearInterval(this.pollingIntervalId); this.pollingIntervalId = null; From 60a681ac6c72ba9c928970d7c705aaaa063ca71e Mon Sep 17 00:00:00 2001 From: Rares Mardare Date: Wed, 5 Jun 2024 14:38:19 +0300 Subject: [PATCH 4/7] lint --- grafana-plugin/src/pages/incidents/Incidents.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/grafana-plugin/src/pages/incidents/Incidents.tsx b/grafana-plugin/src/pages/incidents/Incidents.tsx index 634c46e19a..df58af6e8c 100644 --- a/grafana-plugin/src/pages/incidents/Incidents.tsx +++ b/grafana-plugin/src/pages/incidents/Incidents.tsx @@ -210,7 +210,6 @@ class _IncidentsPage extends React.Component Date: Wed, 5 Jun 2024 17:05:48 +0300 Subject: [PATCH 5/7] pr feedback --- grafana-plugin/src/pages/incidents/Incidents.tsx | 13 +++++++++++-- .../pages/incidents/parts/IncidentSilenceModal.tsx | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/grafana-plugin/src/pages/incidents/Incidents.tsx b/grafana-plugin/src/pages/incidents/Incidents.tsx index df58af6e8c..dce61413c4 100644 --- a/grafana-plugin/src/pages/incidents/Incidents.tsx +++ b/grafana-plugin/src/pages/incidents/Incidents.tsx @@ -938,6 +938,12 @@ class _IncidentsPage extends React.Component this.setState({ selectedIncidentIds: [] }) + async () => { + // clear selected incident on finally and update incident stats + await alertGroupStore.fetchStats(mapActionToStatus[action]); + this.setState({ selectedIncidentIds: [] }); + } ); }; diff --git a/grafana-plugin/src/pages/incidents/parts/IncidentSilenceModal.tsx b/grafana-plugin/src/pages/incidents/parts/IncidentSilenceModal.tsx index c959d2663e..96b3a196a1 100644 --- a/grafana-plugin/src/pages/incidents/parts/IncidentSilenceModal.tsx +++ b/grafana-plugin/src/pages/incidents/parts/IncidentSilenceModal.tsx @@ -66,7 +66,7 @@ const IncidentSilenceModal: React.FC = ({ type="primary" className={cx(utilStyles.overflowChild, bem(utilStyles.overflowChild, 'line-1'))} > - Silence alert group #${alertGroupID} ${alertGroupName} + Silence alert group #{alertGroupID} ${alertGroupName} } className={styles.root} From a4a863fe64c84b8765dfa6c4769b6139e58faeff Mon Sep 17 00:00:00 2001 From: Rares Mardare Date: Wed, 5 Jun 2024 17:25:03 +0300 Subject: [PATCH 6/7] pr feedback --- grafana-plugin/src/pages/incidents/Incidents.tsx | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/grafana-plugin/src/pages/incidents/Incidents.tsx b/grafana-plugin/src/pages/incidents/Incidents.tsx index dce61413c4..ff06ba679d 100644 --- a/grafana-plugin/src/pages/incidents/Incidents.tsx +++ b/grafana-plugin/src/pages/incidents/Incidents.tsx @@ -908,10 +908,11 @@ class _IncidentsPage extends React.Component Promise) => { const { store } = this.props; - return (e: SyntheticEvent) => { + return async (e: SyntheticEvent) => { e.stopPropagation(); - return store.alertGroupStore.doIncidentAction(incidentId, action); + await store.alertGroupStore.doIncidentAction(incidentId, action); + await store.alertGroupStore.fetchIncidentsAndStats(); }; }; @@ -938,12 +939,6 @@ class _IncidentsPage extends React.Component { // clear selected incident on finally and update incident stats - await alertGroupStore.fetchStats(mapActionToStatus[action]); this.setState({ selectedIncidentIds: [] }); + + await alertGroupStore.fetchIncidentsAndStats(); } ); }; From a4038118a6b1575a1079b6c665de9d42e16d07db Mon Sep 17 00:00:00 2001 From: Rares Mardare Date: Thu, 6 Jun 2024 11:15:14 +0300 Subject: [PATCH 7/7] remove delay of settimeout --- .../src/pages/incidents/Incidents.tsx | 46 +++++++++---------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/grafana-plugin/src/pages/incidents/Incidents.tsx b/grafana-plugin/src/pages/incidents/Incidents.tsx index ff06ba679d..2416392bb0 100644 --- a/grafana-plugin/src/pages/incidents/Incidents.tsx +++ b/grafana-plugin/src/pages/incidents/Incidents.tsx @@ -940,8 +940,6 @@ class _IncidentsPage extends React.Component { // clear selected incident on finally and update incident stats this.setState({ selectedIncidentIds: [] }); + this.setPollingInterval(); await alertGroupStore.fetchIncidentsAndStats(); } @@ -964,31 +963,28 @@ class _IncidentsPage extends React.Component { - this.pollingIntervalId = setTimeout( - async () => { - const isBrowserWindowInactive = document.hidden; - const { liveUpdatesPaused } = this.props.store.alertGroupStore; - - if ( - !liveUpdatesPaused && - !isBrowserWindowInactive && - !LoaderHelper.isLoading(this.props.store.loaderStore, [ - ActionKey.FETCH_INCIDENTS, - ActionKey.FETCH_INCIDENTS_POLLING, - ]) - ) { - await this.props.store.alertGroupStore.fetchIncidentsAndStats(true); - } + const startPolling = () => { + this.pollingIntervalId = setTimeout(async () => { + const isBrowserWindowInactive = document.hidden; + const { liveUpdatesPaused } = this.props.store.alertGroupStore; + + if ( + !liveUpdatesPaused && + !isBrowserWindowInactive && + !LoaderHelper.isLoading(this.props.store.loaderStore, [ + ActionKey.FETCH_INCIDENTS, + ActionKey.FETCH_INCIDENTS_POLLING, + ]) + ) { + await this.props.store.alertGroupStore.fetchIncidentsAndStats(true); + } - if (this.pollingIntervalId === null) { - return; - } + if (this.pollingIntervalId === null) { + return; + } - startPolling(isBrowserWindowInactive); - }, - delayed ? 60 * 1000 : POLLING_NUM_SECONDS * 1000 - ); + startPolling(); + }, POLLING_NUM_SECONDS * 1000); }; startPolling();