1
0
Эх сурвалжийг харах

fix: objects with empty properties weren't collapsible

Also
- moved file specific collapse to only apply to file graphs
- removed db Query collapse branch b/c it was covered by other db
  branches
- updated separate lint to include org mode syntax that is deprecated in
  db graphs
Gabriel Horner 1 жил өмнө
parent
commit
41554646de

+ 2 - 0
scripts/src/logseq/tasks/dev/db_and_file_graphs.clj

@@ -98,6 +98,8 @@
                               "block/name"
                               ;; anything org mode
                               "org"
+                              "#+BEGIN_"
+                              "#+END_"
                               "pre-block"
                               "db/get-page"
                               "/page-name-sanity-lc"]))

+ 17 - 26
src/main/frontend/handler/editor.cljs

@@ -3350,17 +3350,19 @@
            (mldoc/block-with-title? first-elem-type))
          true)))
 
-(defn- valid-custom-query-block?
-  "Whether block has a valid custom query."
+(defn- db-collapsable?
   [block]
-  (let [entity (db/entity (:db/id block))
-        content (:block/title entity)]
-    (when content
-      (when (and (string/includes? content "#+BEGIN_QUERY")
-                 (string/includes? content "#+END_QUERY"))
-        (let [ast (mldoc/->edn (string/trim content) (or (:block/format entity) :markdown))
-              q (mldoc/extract-first-query-from-ast ast)]
-          (some? (:query (common-util/safe-read-map-string q))))))))
+  (let [property-keys (->> (keys (:block/properties block))
+                           (remove db-property/db-attribute-properties)
+                           (remove #(outliner-property/property-with-other-position? (db/entity %))))]
+    (or (and (seq property-keys)
+             (not (db-pu/all-hidden-properties? property-keys)))
+        (and (seq (:block/tags block))
+             (some (fn [t]
+                     (let [properties (map :db/ident (:logseq.property.class/properties t))]
+                       (prn :tags (:block/title t) properties)
+                       (and (seq properties)
+                            (not (db-pu/all-hidden-properties? properties))))) (:block/tags block))))))
 
 (defn collapsable?
   ([block-id]
@@ -3371,23 +3373,12 @@
    (when block-id
      (let [repo (state/get-current-repo)]
        (if-let [block (db/entity [:block/uuid block-id])]
-         (let [db-based? (config/db-based-graph? repo)
-               tags (:block/tags (db/entity (:db/id block)))
-               property-keys (->> (keys (:block/properties block))
-                                  (remove db-property/db-attribute-properties)
-                                  (remove #(outliner-property/property-with-other-position? (db/entity %))))]
+         (let [db-based? (config/db-based-graph? repo)]
            (or (if ignore-children? false (db-model/has-children? block-id))
-               (and (not db-based?) (file-editor-handler/valid-dsl-query-block? block))
-               (valid-custom-query-block? block)
-               (and db-based? (ldb/class-instance? (db/entity :logseq.class/Query) block))
-               (and db-based?
-                    (seq property-keys)
-                    (not (db-pu/all-hidden-properties? property-keys)))
-               (and db-based? (seq tags)
-                    (some (fn [t]
-                            (let [properties (map :db/ident (:logseq.property.class/properties (:block/schema t)))]
-                              (and (seq properties)
-                                   (not (db-pu/all-hidden-properties? properties))))) tags))
+               (and db-based? (db-collapsable? block))
+               (and (not db-based?)
+                    (or (file-editor-handler/valid-dsl-query-block? block)
+                        (file-editor-handler/valid-custom-query-block? block)))
                (and
                 (:outliner/block-title-collapse-enabled? (state/get-config))
                 (block-with-title? (:block/format block)

+ 13 - 0
src/main/frontend/handler/file_based/editor.cljs

@@ -19,6 +19,7 @@
             [frontend.handler.file-based.property.util :as property-util]
             [logseq.db.frontend.schema :as db-schema]
             [logseq.common.util.block-ref :as block-ref]
+            [logseq.common.util :as common-util]
             [logseq.db :as ldb]))
 
 (defn- remove-non-existed-refs!
@@ -227,3 +228,15 @@
                            (query-dsl/parse-query query-body)
                            (catch :default _e
                              nil))))))))))
+
+(defn valid-custom-query-block?
+  "Whether block has a valid custom query."
+  [block]
+  (let [entity (db/entity (:db/id block))
+        content (:block/title entity)]
+    (when content
+      (when (and (string/includes? content "#+BEGIN_QUERY")
+                 (string/includes? content "#+END_QUERY"))
+        (let [ast (mldoc/->edn (string/trim content) (or (:block/format entity) :markdown))
+              q (mldoc/extract-first-query-from-ast ast)]
+          (some? (:query (common-util/safe-read-map-string q))))))))