From e61e3cb0a65060caddc7d2a40a4aa49cc7fd755e Mon Sep 17 00:00:00 2001 From: Brent Bovenzi Date: Sun, 20 Feb 2022 12:46:01 -0500 Subject: [PATCH 1/3] fix auto refresh check on page load --- airflow/www/static/js/graph.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/airflow/www/static/js/graph.js b/airflow/www/static/js/graph.js index 2e0522cf09aac..1bf4b96967ce2 100644 --- a/airflow/www/static/js/graph.js +++ b/airflow/www/static/js/graph.js @@ -58,6 +58,15 @@ const stateFocusMap = { deferred: false, no_status: false, }; + +const isFinal = () => { + const states = Object.values(taskInstances).map((ti) => ti.state); + + // end refresh if all states are final + 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); @@ -363,13 +372,10 @@ 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)) - ) { + if (isFinal()) { $('#auto_refresh').prop('checked', false); clearInterval(refreshInterval); } @@ -411,9 +417,8 @@ $('#auto_refresh').change(() => { }); function initRefresh() { - if (localStorage.getItem('disableAutoRefresh')) { - $('#auto_refresh').prop('checked', false); - } + const isDisabled = localStorage.getItem('disableAutoRefresh'); + $('#auto_refresh').prop('checked', !(isDisabled || isFinal())); startOrStopRefresh(); d3.select('#refresh_button').on('click', () => handleRefresh()); } @@ -472,14 +477,15 @@ function groupTooltip(node, tis) { // Initiating the tooltips function updateNodesStates(tis) { g.nodes().forEach((nodeId) => { - const { elem } = g.node(nodeId); + const node = g.node(nodeId); + const { elem } = node; + const taskId = nodeId; + if (elem) { const classes = `node enter ${getNodeState(nodeId, tis)}`; elem.setAttribute('class', classes); elem.setAttribute('data-toggle', 'tooltip'); - const taskId = nodeId; - const node = g.node(nodeId); elem.onmouseover = (evt) => { let tt; if (taskId in tis) { From 4733c3ef668ee89f9071ab18a974fcc3f2034118 Mon Sep 17 00:00:00 2001 From: Brent Bovenzi Date: Tue, 22 Feb 2022 11:05:48 -0500 Subject: [PATCH 2/3] minor code cleanup --- airflow/www/static/js/graph.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/airflow/www/static/js/graph.js b/airflow/www/static/js/graph.js index 1bf4b96967ce2..55c6b306f1736 100644 --- a/airflow/www/static/js/graph.js +++ b/airflow/www/static/js/graph.js @@ -59,10 +59,8 @@ const stateFocusMap = { no_status: false, }; -const isFinal = () => { +const checkRunState = () => { const states = Object.values(taskInstances).map((ti) => ti.state); - - // end refresh if all states are final return !states.some((state) => ( ['success', 'failed', 'upstream_failed', 'skipped', 'removed'].indexOf(state) === -1)); }; @@ -375,7 +373,8 @@ function handleRefresh() { updateNodesStates(taskInstances); // end refresh if all states are final - if (isFinal()) { + const isFinal = checkRunState(); + if (isFinal) { $('#auto_refresh').prop('checked', false); clearInterval(refreshInterval); } @@ -418,7 +417,8 @@ $('#auto_refresh').change(() => { function initRefresh() { const isDisabled = localStorage.getItem('disableAutoRefresh'); - $('#auto_refresh').prop('checked', !(isDisabled || isFinal())); + const isFinal = checkRunState(); + $('#auto_refresh').prop('checked', !(isDisabled || isFinal)); startOrStopRefresh(); d3.select('#refresh_button').on('click', () => handleRefresh()); } @@ -477,15 +477,15 @@ function groupTooltip(node, tis) { // Initiating the tooltips function updateNodesStates(tis) { g.nodes().forEach((nodeId) => { - const node = g.node(nodeId); - const { elem } = node; - const taskId = nodeId; + const { elem } = g.node(nodeId); if (elem) { const classes = `node enter ${getNodeState(nodeId, tis)}`; elem.setAttribute('class', classes); elem.setAttribute('data-toggle', 'tooltip'); + const taskId = nodeId; + const node = g.node(nodeId); elem.onmouseover = (evt) => { let tt; if (taskId in tis) { From 3c0354d3d7e65e9a1577cbd3be947ea53a8dd330 Mon Sep 17 00:00:00 2001 From: Brent Bovenzi Date: Tue, 22 Feb 2022 11:19:51 -0500 Subject: [PATCH 3/3] remove new line --- airflow/www/static/js/graph.js | 1 - 1 file changed, 1 deletion(-) diff --git a/airflow/www/static/js/graph.js b/airflow/www/static/js/graph.js index 55c6b306f1736..254db5a57cc11 100644 --- a/airflow/www/static/js/graph.js +++ b/airflow/www/static/js/graph.js @@ -478,7 +478,6 @@ function groupTooltip(node, tis) { function updateNodesStates(tis) { g.nodes().forEach((nodeId) => { const { elem } = g.node(nodeId); - if (elem) { const classes = `node enter ${getNodeState(nodeId, tis)}`; elem.setAttribute('class', classes);