FIX: ensures group_ids are not "" or nil (#39)

FIX: ensures group_ids are not “” or nil (#39)

diff --git a/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6 b/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6
index ed030f7..7c1e3b6 100644
--- a/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6
+++ b/assets/javascripts/discourse/controllers/admin-plugins-explorer.js.es6
@@ -7,7 +7,7 @@ import {
   observes
 } from "ember-addons/ember-computed-decorators";
 
-const NoQuery = Query.create({ name: "No queries", fake: true });
+const NoQuery = Query.create({ name: "No queries", fake: true, group_ids: [] });
 
 export default Ember.Controller.extend({
   queryParams: { selectedQueryId: "id" },
@@ -45,12 +45,17 @@ export default Ember.Controller.extend({
 
   @computed("selectedQueryId")
   selectedItem(selectedQueryId) {
-    const id = parseInt(selectedQueryId);
-    const item = this.model.find(q => q.id === id);
+    const id = parseInt(selectedQueryId, 10);
+    const item = this.model.findBy("id", id);
+
     !isNaN(id)
       ? this.set("showRecentQueries", false)
       : this.set("showRecentQueries", true);
-    if (id < 0) this.set("editDisabled", true);
+
+    if (id < 0) {
+      this.set("editDisabled", true);
+    }
+
     return item || NoQuery;
   },
 
diff --git a/plugin.rb b/plugin.rb
index e73296a..64a1fbc 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -658,7 +658,8 @@ SQL
       [:name, :description, :sql, :created_by, :created_at, :last_run_at].each do |sym|
         query.send("#{sym}=", h[sym].strip) if h[sym]
       end
-      query.group_ids = h[:group_ids]
+      group_ids = (h[:group_ids] == "" || !h[:group_ids]) ? [] : h[:group_ids]
+      query.group_ids = group_ids
       query.id = h[:id].to_i if h[:id]
       query
     end

GitHub sha: 4196321e

1 Like