Browse Source

fix: :checkbox property not working in simple queries and rules

Also fix booleans not rendering in query table
Gabriel Horner 1 year ago
parent
commit
ee77145caf

+ 1 - 1
deps/db/src/logseq/db/frontend/malli_schema.cljs

@@ -360,7 +360,7 @@
   (vec
    (concat
     [:map]
-    [[:property.value/content [:or :string :double]]]
+    [[:property.value/content [:or :string :double :boolean]]]
     (remove #(#{:block/content} (first %)) block-attrs)
     page-or-block-attrs)))
 

+ 4 - 3
deps/db/src/logseq/db/frontend/property.cljs

@@ -55,7 +55,7 @@
                                                     :hide? true}}
    :logseq.property/source-page           {:schema {:type :entity
                                                     :hide? true}}
-   :logseq.property/built-in?             {:schema {:type :checkbox
+   :logseq.property/built-in?             {:schema {:type :boolean
                                                     :hide? true}}
    :logseq.property/hide-properties?      {:schema {:type :checkbox
                                                     :hide? true}}
@@ -234,8 +234,9 @@
   property i.e. what the user sees. For page types the content is the page name"
   [ent]
   (or (:block/content ent)
-      (:property.value/content ent)
-      (:block/original-name ent)))
+      (if-some [content (:property.value/content ent)]
+        content
+        (:block/original-name ent))))
 
 (defn ref->property-value-content
   "Given a ref from a pulled query e.g. `{:db/id X}`, gets a readable name for

+ 10 - 4
deps/db/src/logseq/db/frontend/property/type.cljs

@@ -11,7 +11,8 @@
 
 (def internal-built-in-property-types
   "Valid property types only for use by internal built-in-properties"
-  #{:keyword :map :coll :any :entity})
+  ;; TODO: Remove :boolean when logseq.property/built-in? references reusable property value entity on startup
+  #{:keyword :map :coll :any :entity :boolean})
 
 (def user-built-in-property-types
   "Valid property types for users in order they appear in the UI"
@@ -32,7 +33,7 @@
   "Property value ref types where the refed entity stores its value in
   :property.value/content e.g. :number is stored as a number. new value-ref-property-types
   should default to this as it allows for more querying power"
-  #{:number :url})
+  #{:number :url :checkbox})
 
 (def value-ref-property-types
   "Property value ref types where the refed entities either store their value in
@@ -98,6 +99,10 @@
     (when-let [entity (d/entity db id-or-value)]
       (number? (:property.value/content entity)))))
 
+(defn- checkbox-entity?
+  [db id]
+  (boolean? (:property.value/content (d/entity db id))))
+
 (defn- text-entity?
   [db s {:keys [new-closed-value?]}]
   (if new-closed-value?
@@ -133,7 +138,8 @@
    :date     [:fn
               {:error/message "should be a journal date"}
               date?]
-   :checkbox boolean?
+   :checkbox checkbox-entity?
+   :boolean  boolean?
    :url      [:fn
               {:error/message "should be a URL"}
               url-entity?]
@@ -165,7 +171,7 @@
 
 (def property-types-with-db
   "Property types whose validation fn requires a datascript db"
-  #{:default :url :number :date :page :object :template :entity})
+  #{:default :checkbox :url :number :date :page :object :template :entity})
 
 ;; Helper fns
 ;; ==========

+ 1 - 6
deps/outliner/src/logseq/outliner/property.cljs

@@ -239,13 +239,8 @@
       (when-not (and (= property-id :block/alias) (= v (:db/id block))) ; alias can't be itself
         (ldb/transact! conn [{:db/id (:db/id block) property-id v}]
                        {:outliner-op :save-block}))
-      (let [new-value (cond
-                        (= v :logseq.property/empty-placeholder)
-                        (if (= property-type :checkbox) false v)
-
-                        (db-property-type/ref-property-types property-type)
+      (let [new-value (if (db-property-type/ref-property-types property-type)
                         (convert-ref-property-value conn property-id v property-type)
-                        :else
                         v)
             existing-value (get block property-id)]
         (when-not (= existing-value new-value)

+ 1 - 1
src/main/frontend/components/db_based/page.cljs

@@ -25,7 +25,7 @@
         configure-opts {:selected? false
                         :page-configure? configure?}
         has-viewable-properties? (outliner-property/block-has-viewable-properties? page)
-        hide-properties? (:logseq.property/hide-properties? page)]
+        hide-properties? (db-property/property-value-content (:logseq.property/hide-properties? page))]
     (when (or configure? (and (not hide-properties?) has-viewable-properties?))
       [:div.ls-page-properties
        {:class (util/classnames [{:no-properties (not has-viewable-properties?)}])}

+ 1 - 1
src/main/frontend/components/page_menu.cljs

@@ -51,7 +51,7 @@
           whiteboard? (contains? (set (:block/type page)) "whiteboard")
           block? (and page (util/uuid-string? page-name) (not whiteboard?))
           contents? (= page-name "contents")
-          public? (get page (pu/get-pid :logseq.property/public))
+          public? (pu/get-block-property-value page :logseq.property/public)
           _favorites-updated? (state/sub :favorites/updated?)
           favorited? (page-handler/favorited? page-name)
           developer-mode? (state/sub [:ui/developer-mode?])

+ 3 - 2
src/main/frontend/components/property/value.cljs

@@ -777,12 +777,13 @@
 
           :checkbox
           (let [add-property! (fn []
-                                (<add-property! block (:db/ident property) (boolean (not value))))]
+                                (<add-property! block (:db/ident property)
+                                                (boolean (not (db-property/property-value-content value)))))]
             [:label.flex.w-full.as-scalar-value-wrap.cursor-pointer
              (shui/checkbox {:class "jtrigger flex flex-row items-center"
                              :disabled config/publishing?
                              :auto-focus editing?
-                             :checked value
+                             :checked (db-property/property-value-content value)
                              :on-checked-change add-property!
                              :on-key-down (fn [e]
                                             (when (= (util/ekey e) "Enter")

+ 1 - 1
src/main/frontend/components/query_table.cljs

@@ -263,7 +263,7 @@
                                                             (:db/id row)
                                                             :block-ref)
                                                            (reset! *mouse-down? false)))}
-                 (when value
+                 (when (some? value)
                    (render-column-value {:row-block row
                                          :row-format format
                                          :cell-format cell-format

+ 1 - 2
src/test/frontend/db/query_dsl_test.cljs

@@ -238,8 +238,7 @@ prop-d:: [[nada]]"}])
           (dsl-query "(and (not (page-property foo bar)) (page-property parent [[child page 2]]))")))
       "Page property queries nested NOT in first clause")
   
-  ;; TODO: Enable when boolean queries work
-  #_(testing "boolean values"
+  (testing "boolean values"
       (is (= ["page1"]
              (map :block/name (dsl-query "(page-property interesting true)")))
           "Boolean true")