mirror of https://github.com/logseq/logseq
fix: remove uniqueness on blocks for now
Fixes https://github.com/logseq/db-test-cn/issues/26. Also fixes the same issue for duplicate queries. Revisit this when use cases are better understood for tagged blockspull/11525/head
parent
4cd886cf1e
commit
ddabf90263
|
@ -66,33 +66,13 @@
|
|||
:type :warning}})))))
|
||||
|
||||
(defn ^:api validate-unique-by-name-tag-and-block-type
|
||||
"Validates uniqueness of blocks and pages for the following cases:
|
||||
"Validates uniqueness of nodes for the following cases:
|
||||
- Page names of type 'page' are unique by tag e.g. their can be Apple #Company and Apple #Fruit
|
||||
- Page names of other types are unique for their type e.g. their can be #Journal ('class') and Journal ('page')
|
||||
- Property names are unique and don't consider built-in property names
|
||||
- Block names are unique by tag"
|
||||
[db new-title {:block/keys [tags] :as entity}]
|
||||
(cond
|
||||
(ldb/page? entity)
|
||||
(validate-unique-for-page db new-title entity)
|
||||
|
||||
(and (not (:block/type entity)) (seq tags))
|
||||
(when-let [res (seq (d/q '[:find [?b ...]
|
||||
:in $ ?eid ?title [?tag-id ...]
|
||||
:where
|
||||
[?b :block/title ?title]
|
||||
[?b :block/tags ?tag-id]
|
||||
[(not= ?b ?eid)]
|
||||
[(missing? $ ?b :block/type)]]
|
||||
db
|
||||
(:db/id entity)
|
||||
new-title
|
||||
(map :db/id tags)))]
|
||||
(throw (ex-info "Duplicate block by tag"
|
||||
{:type :notification
|
||||
:payload {:message (str "Another block named " (pr-str new-title) " already exists for tag "
|
||||
(pr-str (->> res first (d/entity db) :block/tags first :block/title)))
|
||||
:type :warning}})))))
|
||||
- Property names are unique and don't consider built-in property names"
|
||||
[db new-title entity]
|
||||
(when (ldb/page? entity)
|
||||
(validate-unique-for-page db new-title entity)))
|
||||
|
||||
(defn validate-block-title
|
||||
"Validates a block title when it has changed"
|
||||
|
|
|
@ -41,35 +41,6 @@
|
|||
(assoc (find-block-by-content conn "background-image") :db/id 10000)))
|
||||
"Disallow duplicate user property")))
|
||||
|
||||
(deftest validate-block-title-unique-for-blocks
|
||||
(let [conn (create-conn-with-blocks
|
||||
[{:page {:block/title "page"}
|
||||
:blocks [{:block/title "yahoo"}
|
||||
{:block/title "Sing Sing" :build/tags [:Movie]}
|
||||
{:block/title "Chicago" :build/tags [:Musical]}]}])]
|
||||
|
||||
(is (nil?
|
||||
(outliner-validate/validate-unique-by-name-tag-and-block-type
|
||||
@conn
|
||||
"yahoo"
|
||||
(find-block-by-content conn "yahoo")))
|
||||
"Blocks without tags have no limits")
|
||||
|
||||
(is (thrown-with-msg?
|
||||
js/Error
|
||||
#"Duplicate block by tag"
|
||||
(outliner-validate/validate-unique-by-name-tag-and-block-type
|
||||
@conn
|
||||
"Sing Sing"
|
||||
(assoc (find-block-by-content conn "Sing Sing") :db/id 10000)))
|
||||
"Disallow duplicate page with tag")
|
||||
(is (nil?
|
||||
(outliner-validate/validate-unique-by-name-tag-and-block-type
|
||||
@conn
|
||||
"Sing Sing"
|
||||
(find-block-by-content conn "Chicago")))
|
||||
"Allow block with same name for different tag")))
|
||||
|
||||
(deftest validate-block-title-unique-for-pages
|
||||
(let [conn (create-conn-with-blocks
|
||||
[{:page {:block/title "page1"}}
|
||||
|
|
Loading…
Reference in New Issue