From 6583ebe5d971e377dfade98ea5558f69ad5a8756 Mon Sep 17 00:00:00 2001 From: Salah Aldeen Al Saleh Date: Mon, 27 Jul 2020 20:38:15 +0000 Subject: [PATCH] fix getAppDashboard job in UI --- kotsadm/web/src/components/apps/Dashboard.jsx | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/kotsadm/web/src/components/apps/Dashboard.jsx b/kotsadm/web/src/components/apps/Dashboard.jsx index c1e2496c7a..cbac0a97f7 100644 --- a/kotsadm/web/src/components/apps/Dashboard.jsx +++ b/kotsadm/web/src/components/apps/Dashboard.jsx @@ -56,6 +56,7 @@ class Dashboard extends Component { showUpdateCheckerModal: false, appStatus: null, metrics: [], + getAppDashboardJob: new Repeater(), } toggleConfigureGraphs = () => { @@ -123,6 +124,7 @@ class Dashboard extends Component { const { getAppLicense } = this.props.getAppLicense; this.state.updateChecker.start(this.updateStatus, 1000); + this.state.getAppDashboardJob.start(this.getAppDashboard, 2000); if (app) { this.setWatchState(app); @@ -130,34 +132,36 @@ class Dashboard extends Component { if (getAppLicense) { this.setState({ appLicense: getAppLicense }); } - - this.getAppDashboardJob = new Repeater() - this.getAppDashboardJob.start(this.getAppDashboard, 2000); } componentWillUnmount() { this.state.updateChecker.stop(); + this.state.getAppDashboardJob.stop(); } - getAppDashboard = async () => { - fetch(`${window.env.API_ENDPOINT}/app/${this.props.app?.slug}/cluster/${this.props.cluster?.id}/dashboard`, { - headers: { - "Authorization": Utilities.getToken(), - "Content-Type": "application/json", - }, - method: "GET", - }) - .then(async (res) => { - const response = await res.json(); - this.setState({ - appStatus: response.appStatus, - promValue: response.prometheusAddress, - metrics: response.metrics, - }) + getAppDashboard = () => { + return new Promise((resolve, reject) => { + fetch(`${window.env.API_ENDPOINT}/app/${this.props.app?.slug}/cluster/${this.props.cluster?.id}/dashboard`, { + headers: { + "Authorization": Utilities.getToken(), + "Content-Type": "application/json", + }, + method: "GET", }) - .catch((err) => { - console.log(err); - }); + .then(async (res) => { + const response = await res.json(); + this.setState({ + appStatus: response.appStatus, + promValue: response.prometheusAddress, + metrics: response.metrics, + }); + resolve(); + }) + .catch((err) => { + console.log(err); + reject(err); + }); + }); } onCheckForUpdates = async () => {