From 8a6de53d09b34cd50fc7cc2ba3f05dc56260bde7 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Thu, 22 May 2025 15:04:44 -0400 Subject: [PATCH] fix: namespaced pages converted to tags result in invalid graph. This wasn't a use case we supported before and if we do decide to support it should be purposefully done and available from all parts of the UI, not just conversion --- src/main/frontend/components/page_menu.cljs | 2 +- .../frontend/components/property/value.cljs | 2 +- src/main/frontend/handler/db_based/page.cljs | 23 +++++++++++-------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/frontend/components/page_menu.cljs b/src/main/frontend/components/page_menu.cljs index 9a8d8d371b..fcc36d54c5 100644 --- a/src/main/frontend/components/page_menu.cljs +++ b/src/main/frontend/components/page_menu.cljs @@ -151,7 +151,7 @@ (when (and db-based? (ldb/internal-page? page)) {:title (t :page/convert-to-tag) :options {:on-click (fn [] - (db-page-handler/convert-to-tag! page))}}) + (db-page-handler/convert-page-to-tag! page))}}) (when (and db-based? (ldb/class? page) (not (:logseq.property/built-in? page))) {:title (t :page/convert-tag-to-page) diff --git a/src/main/frontend/components/property/value.cljs b/src/main/frontend/components/property/value.cljs index e7d8d5e438..c7667db698 100644 --- a/src/main/frontend/components/property/value.cljs +++ b/src/main/frontend/components/property/value.cljs @@ -608,7 +608,7 @@ (:db/id page))) (and class? page? id) - (p/let [_ (db-page-handler/convert-to-tag! page-entity)] + (p/let [_ (db-page-handler/convert-page-to-tag! page-entity)] id) :else diff --git a/src/main/frontend/handler/db_based/page.cljs b/src/main/frontend/handler/db_based/page.cljs index a0d1cda3f1..40d1ee31c0 100644 --- a/src/main/frontend/handler/db_based/page.cljs +++ b/src/main/frontend/handler/db_based/page.cljs @@ -42,18 +42,21 @@ (when (valid-tag? repo (db/entity repo [:block/uuid block-id]) tag-entity) (db-property-handler/set-block-property! block-id :block/tags (:db/id tag-entity))))) -(defn convert-to-tag! +(defn convert-page-to-tag! "Converts a Page to a Tag" [page-entity] - (if (db/page-exists? (:block/title page-entity) #{:logseq.class/Tag}) - (notification/show! (str "A tag with the name \"" (:block/title page-entity) "\" already exists.") :warning false) - (let [txs [(db-class/build-new-class (db/get-db) - {:db/id (:db/id page-entity) - :block/title (:block/title page-entity) - :block/created-at (:block/created-at page-entity)}) - [:db/retract (:db/id page-entity) :block/tags :logseq.class/Page]]] + (cond (db/page-exists? (:block/title page-entity) #{:logseq.class/Tag}) + (notification/show! (str "A tag with the name \"" (:block/title page-entity) "\" already exists.") :warning false) + (:block/parent page-entity) + (notification/show! "Namespaced pages can't be tags" :error false) + :else + (let [txs [(db-class/build-new-class (db/get-db) + {:db/id (:db/id page-entity) + :block/title (:block/title page-entity) + :block/created-at (:block/created-at page-entity)}) + [:db/retract (:db/id page-entity) :block/tags :logseq.class/Page]]] - (db/transact! (state/get-current-repo) txs {:outliner-op :save-block})))) + (db/transact! (state/get-current-repo) txs {:outliner-op :save-block})))) (defn convert-tag-to-page! [entity] @@ -61,7 +64,7 @@ (notification/show! (str "A page with the name \"" (:block/title entity) "\" already exists.") :warning false) (when-not (:logseq.property/built-in? entity) (if (seq (:logseq.property.class/_extends entity)) - (notification/show! "This tag cannot be converted because it has tag children. All tag children must be removed or converted before converting this tag." :warning false) + (notification/show! "This tag cannot be converted because it has tag children. All tag children must be removed or converted before converting this tag." :error false) (p/let [objects (db-async/