fix: can't create page with tag from cmd-k

e.g. `Foo #Movie`. Also cleanup build-new-class which shouldn't allow
for db-ident overrides
This commit is contained in:
Gabriel Horner
2025-01-08 14:09:36 -05:00
parent 4a245b5f72
commit e0b5dace85
2 changed files with 19 additions and 13 deletions

View File

@@ -123,6 +123,5 @@
[db page-m]
{:pre [(string? (:block/title page-m))]}
(let [db-ident (create-user-class-ident-from-name (:block/title page-m))
db-ident' (or (:db/ident page-m)
(db-ident/ensure-unique-db-ident db db-ident))]
db-ident' (db-ident/ensure-unique-db-ident db db-ident)]
(sqlite-util/build-new-class (assoc page-m :db/ident db-ident'))))

View File

@@ -30,13 +30,16 @@
(let [v (if (uuid? tag)
(d/entity db [:block/uuid tag])
tag)]
(cond
(de/entity? v)
(:db/id v)
(map? v)
(:db/id v)
:else
v)))
(cond (de/entity? v)
(:db/id v)
;; tx map
(map? v)
;; Handle adding :db/ident if a new tag
(if (d/entity db [:block/uuid (:block/uuid v)])
v
(db-class/build-new-class db v))
:else
v)))
tags'))
property-vals-tx-m
;; Builds property values for built-in properties like logseq.property.pdf/file
@@ -49,9 +52,12 @@
(when (db-property-util/built-in-has-ref-value? k)
[k v])))
(into {})))]
(cond-> (if class? [(db-class/build-new-class db page')
[:db/retract [:block/uuid (:block/uuid page)] :block/tags :logseq.class/Page]]
[page'])
(cond-> (if class?
[(merge (db-class/build-new-class db page')
;; FIXME: new pages shouldn't have db/ident but converting property to tag still relies on this
(select-keys page' [:db/ident]))
[:db/retract [:block/uuid (:block/uuid page)] :block/tags :logseq.class/Page]]
[page'])
(seq property-vals-tx-m)
(into (vals property-vals-tx-m))
true
@@ -187,7 +193,8 @@
(not (ldb/class? existing-page))
(or (ldb/property? existing-page) (ldb/internal-page? existing-page)))
;; Convert existing user property or page to class
(let [tx-data [(db-class/build-new-class db (select-keys existing-page [:block/title :block/uuid :db/ident :block/created-at]))
(let [tx-data [(merge (db-class/build-new-class db (select-keys existing-page [:block/title :block/uuid :block/created-at]))
(select-keys existing-page [:db/ident]))
[:db/retract [:block/uuid (:block/uuid existing-page)] :block/tags :logseq.class/Page]]]
{:tx-meta tx-meta
:tx-data tx-data})))