Skip to content

Business intelligence made simple

Fixed tablesXhr for fetch [skip ci]

Andrew Kane2de7ec4136ab
diff --git a/app/assets/javascripts/blazer/application.js b/app/assets/javascripts/blazer/application.js
index 1e544d16..175dd237 100644
--- a/app/assets/javascripts/blazer/application.js
+++ b/app/assets/javascripts/blazer/application.js
@@ -115,8 +115,12 @@ function toggle(element, found) {
}
}
-function getJSON(url, success) {
- fetch(url, {headers: {"Accept": "application/json"}})
+function getJSON(url, success, controller) {
+ const options = {headers: {"Accept": "application/json"}}
+ if (controller) {
+ options.signal = controller.signal
+ }
+ fetch(url, options)
.then(function (response) {
if (!response.ok) {
throw new Error("Bad response")
diff --git a/app/views/blazer/queries/_form.html.erb b/app/views/blazer/queries/_form.html.erb
index 57a6118a..536c07ac 100644
--- a/app/views/blazer/queries/_form.html.erb
+++ b/app/views/blazer/queries/_form.html.erb
@@ -140,7 +140,9 @@
tablesXhr.abort()
}
- tablesXhr = getJSON(Routes.tables_queries_path({data_source: dataSource}), function (data) {
+ tablesXhr = new AbortController()
+
+ getJSON(Routes.tables_queries_path({data_source: dataSource}), function (data) {
const newOptions = []
for (const table of data) {
if (typeof table === "object") {
@@ -152,7 +154,7 @@
tableSelect.selectize.clearOptions()
tableSelect.selectize.addOption(newOptions)
tableSelect.selectize.refreshOptions(false)
- })
+ }, tablesXhr)
}
function adjustHeight() {