mirror of
https://github.com/logseq/logseq.git
synced 2026-05-25 05:04:24 +00:00
feat(outliner): enhance alias handling in set-block-db-attribute!
This commit is contained in:
20
deps/outliner/src/logseq/outliner/property.cljs
vendored
20
deps/outliner/src/logseq/outliner/property.cljs
vendored
@@ -669,14 +669,20 @@
|
||||
|
||||
:else
|
||||
(batch-remove-property! conn [eid] property-id)))))
|
||||
|
||||
(defn- set-block-db-attribute!
|
||||
[conn db block property property-id v]
|
||||
(throw-error-if-invalid-property-value db property v)
|
||||
(when (= property-id :block/alias)
|
||||
(throw-error-if-invalid-alias db block v))
|
||||
(when-not (and (= property-id :block/alias) (= v (:db/id block)))
|
||||
[conn block property property-id raw-v tx-v]
|
||||
(let [validation-db @conn
|
||||
validation-v (if (and (= :db.type/ref (:db/valueType property))
|
||||
(some? tx-v))
|
||||
tx-v
|
||||
raw-v)]
|
||||
(throw-error-if-invalid-property-value validation-db property validation-v)
|
||||
(when (= property-id :block/alias)
|
||||
(doseq [alias-id (if (coll? tx-v) tx-v [tx-v])]
|
||||
(throw-error-if-invalid-alias validation-db block alias-id)))
|
||||
(let [tx-data (cond->
|
||||
[{:db/id (:db/id block) property-id v}]
|
||||
[{:db/id (:db/id block) property-id tx-v}]
|
||||
(= property-id :logseq.property.class/extends)
|
||||
(conj [:db/retract (:db/id block) :logseq.property.class/extends :logseq.class/Root]))]
|
||||
(ldb/transact! conn tx-data
|
||||
@@ -719,7 +725,7 @@
|
||||
(outliner-validate/validate-extends-property @conn v' [block]))
|
||||
(cond
|
||||
db-attribute?
|
||||
(set-block-db-attribute! conn db block property property-id v)
|
||||
(set-block-db-attribute! conn block property property-id v v')
|
||||
|
||||
:else
|
||||
(let [_ (assert (some? property) (str "Property " property-id " doesn't exist yet"))
|
||||
|
||||
@@ -79,6 +79,18 @@
|
||||
conn (:db/id already-a) :block/alias (:db/id new-target)))
|
||||
"page that is an alias cannot gain its own aliases"))))
|
||||
|
||||
(deftest page-alias-converts-string-value-via-set-block-property
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
{:pages-and-blocks [{:page {:block/title "canonical-string-alias"}}]})
|
||||
canonical (db-test/find-page-by-title @conn "canonical-string-alias")]
|
||||
(outliner-property/set-block-property!
|
||||
conn (:db/id canonical) :block/alias "string-alias")
|
||||
(let [alias-page (db-test/find-page-by-title @conn "string-alias")
|
||||
canonical' (d/entity @conn (:db/id canonical))]
|
||||
(is alias-page)
|
||||
(is (= #{(:db/id alias-page)}
|
||||
(set (map :db/id (:block/alias canonical'))))))))
|
||||
|
||||
(deftest page-alias-invariants-reject-invalid-via-batch-set-property
|
||||
(testing "batch path: duplicate owner is rejected"
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
|
||||
Reference in New Issue
Block a user