Просмотр исходного кода

fix(regression): property/has-property rules return

properties and not internal attributes like :block/title and
:block/created-at
Gabriel Horner 11 месяцев назад
Родитель
Сommit
3755175bcb

+ 2 - 1
deps/db/src/logseq/db/frontend/property.cljs

@@ -16,7 +16,8 @@
      * :type - Property type
      * :cardinality - property cardinality. Default to one/single cardinality if not set
      * :hide? - Boolean which hides property when set on a block or exported e.g. slides
-     * :public? - Boolean which allows property to be used by user e.g. add and remove property to blocks/pages
+     * :public? - Boolean which allows property to be used by user: add and remove property to blocks/pages
+       and queryable via property/has-property rules
      * :view-context - Keyword to indicate which view contexts a property can be
        seen in when :public? is set. Valid values are :page, :block and :never. Property can
        be viewed in any context if not set

+ 7 - 1
deps/db/src/logseq/db/frontend/rules.cljc

@@ -166,12 +166,18 @@
     '[(has-property ?b ?prop)
       [?b ?prop _]
       [?prop-e :db/ident ?prop]
-      [?prop-e :block/type "property"]]
+      [?prop-e :block/type "property"]
+      [?prop-e :block/schema ?prop-schema]
+      [(get ?prop-schema :public? true) ?public]
+      [(= true ?public)]]
 
     :property
     '[(property ?b ?prop ?val)
       [?prop-e :db/ident ?prop]
       [?prop-e :block/type "property"]
+      [?prop-e :block/schema ?prop-schema]
+      [(get ?prop-schema :public? true) ?public]
+      [(= true ?public)]
       [?b ?prop ?pv]
       (or
        ;; non-ref value

+ 3 - 10
deps/db/test/logseq/db/frontend/rules_test.cljs

@@ -10,10 +10,6 @@
        db
        (rules/extract-rules rules/db-query-dsl-rules)))
 
-(defn- remove-built-in-properties
-  [conn properties]
-  (remove (fn [k] (:logseq.property/built-in? (d/entity @conn k))) properties))
-
 (deftest has-property-rule
   (let [conn (db-test/create-conn-with-blocks
               {:properties {:foo {:block/schema {:type :default}}
@@ -33,10 +29,9 @@
                 (map (comp :block/title first))))
         "has-property returns no result when block doesn't have property")
     (is (= [:user.property/foo]
-           (->> (q-with-rules '[:find [?p ...]
-                                :where (has-property ?b ?p) [?b :block/title "Page"]]
-                              @conn)
-                (remove-built-in-properties conn)))
+           (q-with-rules '[:find [?p ...]
+                           :where (has-property ?b ?p) [?b :block/title "Page"]]
+                         @conn))
         "has-property can bind to property arg")))
 
 (deftest property-rule
@@ -106,7 +101,6 @@
              (->> (q-with-rules '[:find [?p ...]
                                   :where (property ?b ?p _) [?b :block/title "Page"]]
                                 @conn)
-                  (remove-built-in-properties conn)
                   set))
           "property can bind to property arg with unbound property value")
       (is (= #{[:user.property/number-many 10]
@@ -116,7 +110,6 @@
              (->> (q-with-rules '[:find ?p ?v
                                   :where (property ?b ?p ?v) [?b :block/title "Page"]]
                                 @conn)
-                  (remove (fn [[k _v]] (:logseq.property/built-in? (d/entity @conn k))))
                   set))
           "property can bind to property and property value args")
       (is (= #{"Page"}