fix: a potential data loss issue for whiteboard blocks

pull/6647/head
Peng Xiao 2022-09-06 23:09:26 +08:00
parent 839b5f35f9
commit f3418a6278
2 changed files with 7 additions and 9 deletions

View File

@ -668,9 +668,8 @@
[page-id blocks]
(let [[blocks other-blocks] (split-with
(fn [b]
(or (not= "macro" (:block/type b))
(whiteboard-properties? (:block/properties b))))
blocks)
(not= "macro" (:block/type b)))
blocks)
result (loop [blocks (map (fn [block] (assoc block :block/level-spaces (:block/level block))) blocks)
parents [{:page/id page-id ; db id or a map {:block/name "xxx"}
:block/level 0

View File

@ -216,11 +216,12 @@
(let [shape (:block/properties block)
shape? (gp-block/whiteboard-properties? shape)
default-page-ref {:block/name (gp-util/page-name-sanity-lc page-name)}]
(merge (when shape?
(merge (if shape?
(merge
{:block/uuid (uuid (:id shape))}
(with-whiteboard-block-refs shape)
(with-whiteboard-content shape)))
(with-whiteboard-content shape))
{:block/unordered true})
(when (nil? (:block/parent block)) {:block/parent default-page-ref})
(when (nil? (:block/format block)) {:block/format :markdown}) ;; TODO: read from config
{:block/page default-page-ref})))
@ -244,11 +245,9 @@
page-entity (build-page-entity (:block/properties page-block) file page-name page-original-name nil options)
page-block (merge page-block page-entity (when-not (:block/uuid page-block) {:block/uuid (d/squuid)}))
blocks (->> blocks
(map #(merge % {:block/level 1 ;; fixme
:block/uuid (or (:block/uuid %)
(map #(merge % {:block/uuid (or (:block/uuid %)
(gp-block/get-custom-id-or-new-id (:block/properties %)))}
(with-whiteboard-block-props % page-name)))
(gp-block/with-parent-and-left {:block/name page-name}))
(with-whiteboard-block-props % page-name))))
_ (when verbose (println "Parsing finished: " file))]
{:pages (list page-block)
:blocks blocks}))