Browse Source

Fix page rule unable to bind to args

Issue reported at
https://github.com/logseq/logseq/pull/4518#issuecomment-1068743086.
Also removed double reporting of errors in ui/catch-error to reduce
error noise for those scenarios
Gabriel Horner 3 years ago
parent
commit
3282d1c766

+ 2 - 1
src/main/frontend/db/rules.cljc

@@ -116,7 +116,8 @@
 
    :page
    '[(page ?b ?page-name)
-     [?b :block/page [:block/name ?page-name]]]
+     [?b :block/page ?bp]
+     [?bp :block/name ?page-name]]
 
    :namespace
    '[(namespace ?p ?namespace)

+ 2 - 4
src/main/frontend/ui.cljs

@@ -714,13 +714,11 @@
 (rum/defcs catch-error
   < {:did-catch
      (fn [state error _info]
-       (js/console.dir error)
+       (log/error :exception error)
        (assoc state ::error error))}
   [{error ::error, c :rum/react-component} error-view view]
   (if (some? error)
-    (do
-      (log/error :exception error)
-      error-view)
+    error-view
     view))
 
 (rum/defc block-error

+ 26 - 16
src/test/frontend/db/query_custom_test.cljs

@@ -1,5 +1,5 @@
 (ns frontend.db.query-custom-test
-  (:require [cljs.test :refer [deftest is use-fixtures]]
+  (:require [cljs.test :refer [deftest is use-fixtures testing]]
             [frontend.test.helper :as test-helper :refer [load-test-files]]
             [frontend.db.query-custom :as query-custom]
             [frontend.db.react :as react]))
@@ -21,23 +21,33 @@
 - LATER b3
 - b3"}])
 
-  (is (= ["LATER b3"]
-         (map :block/content
-              (custom-query {:query '[:find (pull ?b [*])
-                                      :where
-                                      (block-content ?b "b")
-                                      (task ?b #{"LATER"})]})))
-      "datalog query returns correct results")
+  (testing "advanced datalog queries"
+    (is (= ["LATER b3"]
+           (map :block/content
+                (custom-query {:query '[:find (pull ?b [*])
+                                        :where
+                                        (block-content ?b "b")
+                                        (task ?b #{"LATER"})]})))
+        "basic advanced query works")
 
-  (is (= ["LATER b3"]
-         (map :block/content
-              (custom-query {:query '[:find (pull ?b [*])
-                                      :in $
-                                      :where
-                                      (block-content ?b "b")
-                                      (task ?b #{"LATER"})]})))
-      "datalog query with :in returns correct results")
+    (is (= ["LATER b3"]
+           (map :block/content
+                (custom-query {:query '[:find (pull ?b [*])
+                                        :in $
+                                        :where
+                                        (block-content ?b "b")
+                                        (task ?b #{"LATER"})]})))
+        "advanced query with an :in works")
 
+    (is (= #{"page1"}
+           (set
+            (map #(get-in % [:block/page :block/name])
+                 (custom-query {:query '[:find (pull ?b [*])
+                                         :in $ ?page
+                                         :where
+                                         (page ?b ?page)]
+                                :inputs ["page1"]}))))
+        "advanced query with bound :in argument works"))
 
   (is (= ["LATER b3"]
          (map :block/content