From faab2bde5994b8b09b78f85feda9c29b01545319 Mon Sep 17 00:00:00 2001 From: Brent Bovenzi Date: Tue, 22 Feb 2022 11:41:39 -0500 Subject: [PATCH] Fix graph autorefresh on page load (#21736) * fix auto refresh check on page load * minor code cleanup * remove new line (cherry picked from commit b2c0a921c155e82d1140029e6495594061945025) --- airflow/www/static/js/graph.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/airflow/www/static/js/graph.js b/airflow/www/static/js/graph.js index 2d3b22e136cb4..615e238d329e7 100644 --- a/airflow/www/static/js/graph.js +++ b/airflow/www/static/js/graph.js @@ -57,6 +57,13 @@ const stateFocusMap = { deferred: false, no_status: false, }; + +const checkRunState = () => { + const states = Object.values(taskInstances).map((ti) => ti.state); + return !states.some((state) => ( + ['success', 'failed', 'upstream_failed', 'skipped', 'removed'].indexOf(state) === -1)); +}; + const taskTip = d3.tip() .attr('class', 'tooltip d3-tip') .html((toolTipHtml) => toolTipHtml); @@ -362,13 +369,11 @@ function handleRefresh() { if (prevTis !== tis) { // eslint-disable-next-line no-global-assign taskInstances = JSON.parse(tis); - const states = Object.values(taskInstances).map((ti) => ti.state); updateNodesStates(taskInstances); // end refresh if all states are final - if (!states.some((state) => ( - ['success', 'failed', 'upstream_failed', 'skipped', 'removed'].indexOf(state) === -1)) - ) { + const isFinal = checkRunState(); + if (isFinal) { $('#auto_refresh').prop('checked', false); clearInterval(refreshInterval); } @@ -410,9 +415,9 @@ $('#auto_refresh').change(() => { }); function initRefresh() { - if (localStorage.getItem('disableAutoRefresh')) { - $('#auto_refresh').prop('checked', false); - } + const isDisabled = localStorage.getItem('disableAutoRefresh'); + const isFinal = checkRunState(); + $('#auto_refresh').prop('checked', !(isDisabled || isFinal)); startOrStopRefresh(); d3.select('#refresh_button').on('click', () => handleRefresh()); }