소스 검색

fix: node created from tables can't be converted to Page

related to https://github.com/logseq/db-test/issues/428
Tienson Qin 1 개월 전
부모
커밋
3baff22123
3개의 변경된 파일13개의 추가작업 그리고 22개의 파일을 삭제
  1. 1 8
      deps/outliner/src/logseq/outliner/validate.cljs
  2. 2 9
      deps/outliner/test/logseq/outliner/validate_test.cljs
  3. 10 5
      src/main/frontend/worker/pipeline.cljs

+ 1 - 8
deps/outliner/src/logseq/outliner/validate.cljs

@@ -289,14 +289,7 @@
                               {:type :notification
                                :payload {:message message
                                          :type :error
-                                         :block (into {} block)}}))))
-          ;; Guard against classes and properties becoming namespace parents
-          (when (or (entity-util/class? (:block/page block)) (entity-util/property? (:block/page block)))
-            (throw (ex-info "Can't convert this block to page when block is in a property or tag."
-                            {:type :notification
-                             :payload {:message "Can't convert this block to page when block is in a property or tag."
-                                       :type :error
-                                       :block (into {} block)}}))))))))
+                                         :block (into {} block)}})))))))))
 
 (defn validate-tags-property
   "Validates adding a property value to :block/tags for given blocks"

+ 2 - 9
deps/outliner/test/logseq/outliner/validate_test.cljs

@@ -171,8 +171,7 @@
                :build-existing-tx? true})
         block (db-test/find-block-by-content @conn "block")
         block-invalid-title (db-test/find-block-by-content @conn #"invalid title")
-        block-invalid-location (db-test/find-block-by-content @conn #"invalid location")
-        block-invalid-in-class (db-test/find-block-by-content @conn "class block")]
+        block-invalid-location (db-test/find-block-by-content @conn #"invalid location")]
 
     (is (thrown-with-msg?
          js/Error
@@ -217,13 +216,7 @@
          js/Error
          #"Can't convert this block to page"
          (outliner-validate/validate-tags-property @conn [(:db/id block-invalid-location)] :logseq.class/Page))
-        "Block with invalid location can't be tagged with #Page")
-
-    (is (thrown-with-msg?
-         js/Error
-         #"Can't convert this block to page"
-         (outliner-validate/validate-tags-property @conn [(:db/id block-invalid-in-class)] :logseq.class/Page))
-        "Block in class or property can't be tagged with #Page")))
+        "Block with invalid location can't be tagged with #Page")))
 
 (deftest validate-tags-property-deletion
   (let [conn (db-test/create-conn-with-blocks

+ 10 - 5
src/main/frontend/worker/pipeline.cljs

@@ -161,11 +161,16 @@
 
                    ;; block->page
                    (and (:added datom) block-before (not (ldb/page? block-before))) ; block->page
-                   (let [->page-tx [{:db/id id
-                                     :block/name (common-util/page-name-sanity-lc (:block/title block-after))}
-                                    [:db/retract id :block/page]]
-                         move-parent-to-library-tx (let [block (d/entity db-after (:e datom))
-                                                         block-parent (:block/parent block)]
+                   (let [block (d/entity db-after (:e datom))
+                         block-parent (:block/parent block)
+                         ->page-tx (concat
+                                    [{:db/id id
+                                      :block/name (common-util/page-name-sanity-lc (:block/title block-after))}
+                                     [:db/retract id :block/page]]
+                                    (when (or (ldb/class? block-parent) (ldb/property? block-parent))
+                                      [[:db/retract id :block/parent]
+                                       [:db/retract id :block/order]]))
+                         move-parent-to-library-tx (do
                                                      (assert (ldb/page? block-parent))
                                                      (when (and (nil? (:block/parent block-parent))
                                                                 block-parent