Browse Source

fix: can't create new page or rename page if same page with

different parent exists.

fixes https://github.com/logseq/db-test/issues/272
Tienson Qin 7 months ago
parent
commit
5ce4935c51

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

@@ -69,7 +69,8 @@
   (cond
   (cond
     (seq tags)
     (seq tags)
     (when-let [another-id (first
     (when-let [another-id (first
-                           (d/q (if (ldb/property? entity)
+                           (d/q (cond
+                                  (ldb/property? entity)
                                   ;; Property names are unique in that they can
                                   ;; Property names are unique in that they can
                                   ;; have the same names as built-in property names
                                   ;; have the same names as built-in property names
                                   '[:find [?b ...]
                                   '[:find [?b ...]
@@ -79,6 +80,18 @@
                                     [?b :block/tags ?tag-id]
                                     [?b :block/tags ?tag-id]
                                     [(missing? $ ?b :logseq.property/built-in?)]
                                     [(missing? $ ?b :logseq.property/built-in?)]
                                     [(not= ?b ?eid)]]
                                     [(not= ?b ?eid)]]
+                                  (:logseq.property/parent entity)
+                                  '[:find [?b ...]
+                                    :in $ ?eid ?title [?tag-id ...]
+                                    :where
+                                    [?b :block/title ?title]
+                                    [?b :block/tags ?tag-id]
+                                    [(not= ?b ?eid)]
+                                    ;; same parent
+                                    [?b :logseq.property/parent ?bp]
+                                    [?eid :logseq.property/parent ?ep]
+                                    [(= ?bp ?ep)]]
+                                  :else
                                   '[:find [?b ...]
                                   '[:find [?b ...]
                                     :in $ ?eid ?title [?tag-id ...]
                                     :in $ ?eid ?title [?tag-id ...]
                                     :where
                                     :where

+ 11 - 3
src/main/frontend/components/cmdk/core.cljs

@@ -112,9 +112,17 @@
                             (take (get-group-limit group) items))))
                             (take (get-group-limit group) items))))
         node-exists? (let [blocks-result (keep :source-block (get-in results [:nodes :items]))]
         node-exists? (let [blocks-result (keep :source-block (get-in results [:nodes :items]))]
                        (when-not (string/blank? input)
                        (when-not (string/blank? input)
-                         (or (some-> (text/get-namespace-last-part input)
-                                     string/trim
-                                     db/get-page)
+                         (or (let [page (some-> (text/get-namespace-last-part input)
+                                                string/trim
+                                                db/get-page)
+                                   parent-title (:block/title (:logseq.property/parent page))
+                                   namespace? (string/includes? input "/")]
+                               (and page
+                                    (or (not namespace?)
+                                        (and
+                                         parent-title
+                                         (= (util/page-name-sanity-lc parent-title)
+                                            (util/page-name-sanity-lc (nth (reverse (string/split input "/")) 1)))))))
                              (some (fn [block]
                              (some (fn [block]
                                      (and
                                      (and
                                       (:block/tags block)
                                       (:block/tags block)