From 77fc3f07532c0659cd111e92cd1ff8e09b4b517d Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Wed, 22 May 2024 10:02:52 -0700 Subject: [PATCH] address the comments by fixing minor issues Signed-off-by: Riya Saxena --- public/pages/Dashboard/containers/Dashboard.js | 17 ++++++----------- .../DestinationsList/DestinationsList.js | 16 +++++----------- .../containers/MonitorHistory/MonitorHistory.js | 17 ++++++----------- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/public/pages/Dashboard/containers/Dashboard.js b/public/pages/Dashboard/containers/Dashboard.js index 4a1fcfaa3..7483eb1e1 100644 --- a/public/pages/Dashboard/containers/Dashboard.js +++ b/public/pages/Dashboard/containers/Dashboard.js @@ -184,17 +184,12 @@ export default class Dashboard extends Component { }, }, }; - let response; - if (this.dataSourceQuery) { - response = await httpClient.post('../api/alerting/monitors/_search', { - body: JSON.stringify(params), - query: this.dataSourceQuery?.query, - }); - } else { - response = await httpClient.post('../api/alerting/monitors/_search', { - body: JSON.stringify(params), - }); - } + + const response = await httpClient.post('../api/alerting/monitors/_search', { + body: JSON.stringify(params), + query: this.dataSourceQuery?.query, + }); + if (response.ok) { monitors = _.get(response, 'resp.hits.hits', []); } else { diff --git a/public/pages/Destinations/containers/DestinationsList/DestinationsList.js b/public/pages/Destinations/containers/DestinationsList/DestinationsList.js index e1fd49272..3ccf866b3 100644 --- a/public/pages/Destinations/containers/DestinationsList/DestinationsList.js +++ b/public/pages/Destinations/containers/DestinationsList/DestinationsList.js @@ -139,17 +139,11 @@ class DestinationsList extends React.Component { query: isDeleteAllowedQuery(type, id), index: INDEX.SCHEDULED_JOBS, }; - let resp; - if (this.dataSourceQuery) { - resp = await httpClient.post('../api/alerting/monitors/_search', { - body: JSON.stringify(requestBody), - query: this.dataSourceQuery.query, - }); - } else { - resp = await httpClient.post('../api/alerting/monitors/_search', { - body: JSON.stringify(requestBody), - }); - } + const resp = await httpClient.post('../api/alerting/monitors/_search', { + body: JSON.stringify(requestBody), + query: this.dataSourceQuery.query, + }); + const total = _.get(resp, 'resp.hits.total.value'); return total === 0; }; diff --git a/public/pages/MonitorDetails/containers/MonitorHistory/MonitorHistory.js b/public/pages/MonitorDetails/containers/MonitorHistory/MonitorHistory.js index 98385df7d..d7d533b00 100644 --- a/public/pages/MonitorDetails/containers/MonitorHistory/MonitorHistory.js +++ b/public/pages/MonitorDetails/containers/MonitorHistory/MonitorHistory.js @@ -201,17 +201,12 @@ class MonitorHistory extends PureComponent { ), index: INDEX.ALL_ALERTS, }; - let resp; - if (this.dataSourceQuery) { - resp = await httpClient.post('../api/alerting/monitors/_search', { - body: JSON.stringify(requestBody), - query: this.dataSourceQuery?.query, - }); - } else { - resp = await httpClient.post('../api/alerting/monitors/_search', { - body: JSON.stringify(requestBody), - }); - } + + const resp = await httpClient.post('../api/alerting/monitors/_search', { + body: JSON.stringify(requestBody), + query: this.dataSourceQuery?.query, + }); + if (resp.ok) { const poiData = get(resp, 'resp.aggregations.alerts_over_time.buckets', []).map((item) => ({ x: item.key,