Skip to content

Commit f1aa5b8

Browse files
committed
graph: fix spurious error modal on page load (#2651)
Summary: Fixes #2646, and fixes #2650 as a side effect. I’ve gone with an additional boolean field `_datasetsFetched` rather than making `_datasets` nullable because `_datasets` is also passed down directly to `tf-graph-controls`, which expects a non-null array. This seemed simpler, all things considered. Test Plan: 1. Launch TensorBoard. Navigate to <http://localhost:6006/#graphs>. 2. Observe that there is no flash of “No graph definition files were found” (though there is instead a brief flash of white). 3. Note that the list of graphs loads, the first graph is selected, and the fragment updates. 4. Refresh the page. Note that the page behaves as in the initial load: in particular, there is no error modal. 5. Change the fragment such that the run is invalid (`#graphs&run=bad`) and note that the error modal appears without refreshing the page. 6. Refresh the page, and note that the error modal appears, and the first graph is automatically selected and loaded underneath it. wchargin-branch: graph-fix-error-modal
1 parent 30dd2e2 commit f1aa5b8

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

tensorboard/plugins/graph/tf_graph_dashboard/tf-graph-dashboard.html

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838
<dom-module id="tf-graph-dashboard">
3939
<template>
4040
<paper-dialog id="error-dialog" with-backdrop></paper-dialog>
41-
<template is="dom-if" if="[[_datasetsEmpty(_datasets)]]">
41+
<template
42+
is="dom-if"
43+
if="[[_datasetsState(_datasetsFetched, _datasets, 'EMPTY')]]"
44+
>
4245
<div style="max-width: 540px; margin: 80px auto 0 auto;">
4346
<h3>No graph definition files were found.</h3>
4447
<p>
@@ -75,7 +78,10 @@ <h3>No graph definition files were found.</h3>
7578
</p>
7679
</div>
7780
</template>
78-
<template is="dom-if" if="[[!_datasetsEmpty(_datasets)]]">
81+
<template
82+
is="dom-if"
83+
if="[[!_datasetsState(datasetsFetched, _datasets, 'PRESENT')]]"
84+
>
7985
<tf-dashboard-layout>
8086
<tf-graph-controls
8187
id="controls"
@@ -191,6 +197,10 @@ <h3>No graph definition files were found.</h3>
191197
type: Array,
192198
value: () => [],
193199
},
200+
_datasetsFetched: {
201+
type: Boolean,
202+
value: false,
203+
},
194204
_selectedDataset: {
195205
type: Number,
196206
value: 0,
@@ -275,8 +285,8 @@ <h3>No graph definition files were found.</h3>
275285
'_maybeFetchHealthPills(_debuggerDataEnabled, allStepsModeEnabled, ' +
276286
'specificHealthPillStep, _selectedNode)',
277287
'_maybeInitializeDashboard(_isAttached)',
278-
'_determineSelectedDataset(_datasets, run)',
279-
'_updateSelectedDatasetName(_datasets, _selectedDataset)',
288+
'_determineSelectedDataset(_datasetsFetched, _datasets, run)',
289+
'_updateSelectedDatasetName(_datasetsFetched, _datasets, _selectedDataset)',
280290
],
281291
attached: function() {
282292
this.set('_isAttached', true);
@@ -366,7 +376,7 @@ <h3>No graph definition files were found.</h3>
366376
this._debuggerDataEnabled &&
367377
this.healthPillsToggledOn &&
368378
this._renderHierarchy &&
369-
!this._datasetsEmpty(this._datasets)
379+
this._datasetsState(this._datasetsFetched, this._datasets, 'PRESENT')
370380
);
371381
},
372382
_maybeInitializeDashboard: function(isAttached) {
@@ -421,9 +431,10 @@ <h3>No graph definition files were found.</h3>
421431

422432
return {name: runName, tags: tagsWithV1Graph};
423433
});
434+
this._datasetsFetched = true;
424435
});
425436
},
426-
_determineSelectedDataset(datasets, run) {
437+
_determineSelectedDataset(datasetsFetched, datasets, run) {
427438
// By default, load the first dataset.
428439
if (!run) {
429440
// By default, load the first dataset.
@@ -434,17 +445,20 @@ <h3>No graph definition files were found.</h3>
434445
// If the URL specifies a dataset, load it.
435446
const dataset = datasets.findIndex((d) => d.name === run);
436447
if (dataset === -1) {
437-
// Tell the user if the dataset cannot be found to avoid misleading
438-
// the user.
439-
const dialog = this.$$('#error-dialog');
440-
dialog.textContent = `No dataset named "${run}" could be found.`;
441-
dialog.open();
448+
if (datasetsFetched) {
449+
// Tell the user if the dataset cannot be found to avoid misleading
450+
// the user.
451+
const dialog = this.$$('#error-dialog');
452+
dialog.textContent = `No dataset named "${run}" could be found.`;
453+
dialog.open();
454+
}
442455
return;
443456
}
444457

445458
this.set('_selectedDataset', dataset);
446459
},
447-
_updateSelectedDatasetName(datasets, selectedDataset) {
460+
_updateSelectedDatasetName(datasetsFetched, datasets, selectedDataset) {
461+
if (!datasetsFetched) return;
448462
// Cannot update `run` to update the hash in case datasets for graph is empty.
449463
if (datasets.length <= selectedDataset) return;
450464
this.set('run', datasets[selectedDataset].name);
@@ -528,8 +542,10 @@ <h3>No graph definition files were found.</h3>
528542
}.bind(this)
529543
);
530544
},
531-
_datasetsEmpty: function(datasets) {
532-
return !datasets || !datasets.length;
545+
_datasetsState: function(datasetsFetched, datasets, state) {
546+
if (!datasetsFetched) return state === 'NOT_LOADED';
547+
if (!datasets || !datasets.length) return state === 'EMPTY';
548+
return state === 'PRESENT';
533549
},
534550
_renderHierarchyChanged: function(renderHierarchy) {
535551
// Reload any data on the graph when the render hierarchy (which determines which nodes are

0 commit comments

Comments
 (0)