fix: db import of whiteboard block with properties

Part of LOG-3176
pull/11433/head
Gabriel Horner 2024-07-25 15:58:19 -04:00
parent 47737148f8
commit 4c0c87337b
3 changed files with 68 additions and 17 deletions

View File

@ -25,7 +25,8 @@
[logseq.db.frontend.order :as db-order]
[logseq.db.frontend.db-ident :as db-ident]
[logseq.db.frontend.property.build :as db-property-build]
[logseq.db.frontend.malli-schema :as db-malli-schema]))
[logseq.db.frontend.malli-schema :as db-malli-schema]
[logseq.graph-parser.property :as gp-property]))
(defn- add-missing-timestamps
"Add updated-at or created-at timestamps if they doesn't exist"
@ -60,9 +61,9 @@
(if-let [new-class (:block.temp/new-class tag-block)]
(let [class-m (find-or-create-class db new-class all-idents)]
(merge class-m
(if-let [existing-tag-uuid (get page-names-to-uuids (common-util/page-name-sanity-lc new-class))]
{:block/uuid existing-tag-uuid}
{:block/uuid (common-uuid/gen-uuid :db-ident-block-uuid (:db/ident class-m))})))
(if-let [existing-tag-uuid (get page-names-to-uuids (common-util/page-name-sanity-lc new-class))]
{:block/uuid existing-tag-uuid}
{:block/uuid (common-uuid/gen-uuid :db-ident-block-uuid (:db/ident class-m))})))
(when (contains? tag-classes (:block/name tag-block))
(if-let [existing-tag-uuid (first
(d/q '[:find [?uuid ...]
@ -321,14 +322,14 @@
(let [property-classes (set (map keyword (:property-classes options)))]
(try
(mapv #(cond (#{:page :block :created-at :updated-at} %)
%
(property-classes %)
:block/tags
(= :tags %)
%
(property-classes %)
:block/tags
(= :tags %)
;; This could also be :logseq.property/page-tags
:block/tags
:else
(get-ident @all-idents %))
:block/tags
:else
(get-ident @all-idents %))
(edn/read-string val))
(catch :default e
(js/console.error "Translating query properties failed with:" e)
@ -839,6 +840,13 @@
:property-pages-tx (concat property-pages-tx converted-property-pages-tx)
:property-page-properties-tx property-page-properties-tx}))
(defn- update-whiteboard-blocks [blocks format]
(map (fn [b]
(if (seq (:block/properties b))
(update b :block/content #(gp-property/remove-properties format %))
b))
blocks))
(defn- extract-pages-and-blocks
[db file content {:keys [extract-options notify-user]}]
(let [format (common-util/get-format file)
@ -853,7 +861,8 @@
(extract/extract file content extract-options')
(common-config/whiteboard? file)
(extract/extract-whiteboard-edn file content extract-options')
(-> (extract/extract-whiteboard-edn file content extract-options')
(update :blocks update-whiteboard-blocks format))
:else
(notify-user {:msg (str "Skipped file since its format is not supported: " file)}))))

View File

@ -338,6 +338,12 @@
count))
"A block with different case of same ref names has 1 distinct ref"))
(testing "whiteboards"
(let [block-with-props (find-block-by-content @conn #"block with props")]
(is (= {:user.property/prop-num 10}
(readable-properties @conn block-with-props)))
(is (= "block with props" (:block/content block-with-props)))))
(testing "tags without tag options"
(let [block (find-block-by-content @conn #"Inception")
tag-page (find-page-by-name @conn "Movie")

View File

@ -8,7 +8,7 @@
{}
:block/updated-at 1720809014394
:block/uuid #uuid "6691677f-c208-4c83-aa40-6efc4286100c"}
{:block/created-at 1720808993087
{:block/created-at 1721935480784
:block/properties
{:ls-type :whiteboard-shape
:logseq.tldraw.shape
@ -34,7 +34,7 @@
:collapsedHeight 0
:nonce 1720805246071
:pageName nil}}
:block/updated-at 1720808993087}
:block/updated-at 1721935480784}
{:block/content "block with block ref ((669168ed-8734-4943-8a86-5e3a553a526d))"
:block/created-at 1720808993012
:block/format :markdown
@ -70,9 +70,45 @@
:nonce 1720808990579
:pageName nil}}
:block/updated-at 1720809157310
:block/created-at 1720809157310})
:block/created-at 1720809157310}
{:block/content "block with props\nprop-num:: 10"
:block/created-at 1721935480737
:block/format :markdown
:block/parent
{:block/uuid #uuid "6691676f-2eed-4619-b56a-69fd7d572c59"}
:block/properties
{:prop-num 10}
:block/updated-at 1721935504617
:block/uuid #uuid "66a2a678-1cea-44b6-a458-4b8c15e18a8d"}
{:block/properties
{:ls-type :whiteboard-shape
:logseq.tldraw.shape
{:blockType "B"
:stroke ""
:collapsed false
:borderRadius 8
:scale [1 1]
:pageId "66a2a678-1cea-44b6-a458-4b8c15e18a8d"
:scaleLevel "md"
:fill ""
:compact true
:isAutoResizing true
:type "logseq-portal"
:size [400 320]
:strokeType "line"
:strokeWidth 2
:opacity 1
:id "86f86420-4abb-11ef-9161-b98dd17dbef1"
:noFill false
:point [648.5671437694965 179.003191006195]
:parentId "6691676f-2eed-4619-b56a-69fd7d572c59"
:collapsedHeight 0
:nonce 1721935475555
:pageName nil}}
:block/updated-at 1721935504609
:block/created-at 1721935504609})
:pages (
{:block/tx-id 536871072
{:block/tx-id 536871657
:block/uuid #uuid "6691676f-2eed-4619-b56a-69fd7d572c59"
:block/properties
{:ls-type :whiteboard-page
@ -83,7 +119,7 @@
{}
:nonce 1
:assets []}}
:block/updated-at 1720809157310
:block/updated-at 1721935504609
:block/created-at 1720805231835
:block/format :markdown
:block/type ["page" "whiteboard"]