[Fix 3789]: storing/loading multiple graphs from URL (#3813)

* Fix JS error: cannot read source of undefined

When the page was refreshed with queries on the page,
the updateTypeaheadMetricsSet function was called before
the typeahead had been initialized.

* Fix: updates URL when query submits

When queries were submitted by pressing enter, the URL did not update
to reflect the change. Not sure why, but this was only the case when
the queries were non-simple, meaning when either labels werre specified
or other promql functions were used.

* Rebase master and make assets
This commit is contained in:
Lovisa Svallingson 2018-02-14 23:23:12 -07:00 committed by Julius Volz
parent d127a21071
commit 04f723ca44
2 changed files with 52 additions and 52 deletions

File diff suppressed because one or more lines are too long

View File

@ -163,6 +163,7 @@ Prometheus.Graph.prototype.initialize = function() {
self.queryForm.submit(function() {
self.consoleTab.addClass("reload");
self.graphTab.addClass("reload");
self.handleChange();
self.submitQuery();
return false;
});
@ -192,8 +193,6 @@ Prometheus.Graph.prototype.initialize = function() {
}
self.populateInsertableMetrics();
queryHistory.bindHistoryEvents(self);
if (self.expr.val()) {
self.submitQuery();
}
@ -261,7 +260,6 @@ Prometheus.Graph.prototype.populateInsertableMetrics = function() {
Prometheus.Graph.prototype.initTypeahead = function(self) {
const source = queryHistory.isEnabled() ? pageConfig.queryHistMetrics.concat(pageConfig.allMetrics) : pageConfig.allMetrics;
self.expr.typeahead({
autoSelect: false,
source,
@ -298,6 +296,7 @@ Prometheus.Graph.prototype.initTypeahead = function(self) {
// This needs to happen after attaching the typeahead plugin, as it
// otherwise breaks the typeahead functionality.
self.expr.focus();
queryHistory.bindHistoryEvents(self);
}
Prometheus.Graph.prototype.getOptions = function() {
@ -446,6 +445,7 @@ Prometheus.Graph.prototype.submitQuery = function() {
self.showError(json.error);
return;
}
queryHistory.handleHistory(self);
success(json.data, textStatus);
},
@ -829,9 +829,9 @@ Prometheus.Graph.prototype.formatKMBT = function(y) {
* Page
*/
const pageConfig = {
allMetrics: [],
graphs: [],
queryHistMetrics: JSON.parse(localStorage.getItem('history')) || [],
allMetrics: [],
};
Prometheus.Page = function() {};
@ -864,7 +864,6 @@ Prometheus.Page.prototype.addGraph = function(options) {
this.removeGraph.bind(this)
);
// this.graphs.push(graph);
pageConfig.graphs.push(graph);
$(window).resize(function() {
@ -1060,7 +1059,9 @@ const queryHistory = {
updateTypeaheadMetricSet: function(metricSet) {
pageConfig.graphs.forEach(function(graph) {
graph.expr.data('typeahead').source = metricSet;
if (graph.expr.data('typeahead')) {
graph.expr.data('typeahead').source = metricSet;
}
});
}
};
@ -1102,4 +1103,3 @@ function init() {
}
$(init);