mirror of https://github.com/logseq/logseq
fix: db import of collapsed block being invalid
Also cleanup infer fn which had import-specific code and add tests for :default to :page :type change. Part of LOG-3176feat/asset-sync
parent
8279205fc7
commit
60b13a525e
|
@ -187,7 +187,6 @@
|
|||
"Infers a user defined built-in :type from property value(s)"
|
||||
[val]
|
||||
(cond
|
||||
(coll? val) :page
|
||||
(number? val) :number
|
||||
(url? val) :url
|
||||
(contains? #{true false} val) :checkbox
|
||||
|
|
|
@ -256,6 +256,8 @@
|
|||
:date
|
||||
(and (coll? prop-val) (seq prop-val) (text-with-refs? prop-val prop-val-text))
|
||||
:default
|
||||
(coll? prop-val)
|
||||
:page
|
||||
:else
|
||||
(db-property-type/infer-property-type-from-value
|
||||
(macro-util/expand-value-if-macro prop-val macros)))
|
||||
|
@ -494,11 +496,11 @@
|
|||
(select-keys block [:block/properties-text-values :block/name :block/content :block/uuid])
|
||||
options')]
|
||||
{:block
|
||||
(cond-> (dissoc block :block/properties)
|
||||
(cond-> block
|
||||
true
|
||||
(merge block-properties)
|
||||
(seq classes-from-properties)
|
||||
;; Add a map of {:block.temp/new-class TAG} to be processed later
|
||||
;; Add a map of {:block.temp/new-class TAG} to be processed later
|
||||
(update :block/tags
|
||||
(fnil into [])
|
||||
(map #(hash-map :block.temp/new-class %
|
||||
|
@ -506,7 +508,7 @@
|
|||
classes-from-properties)))
|
||||
:properties-tx pvalues-tx})
|
||||
{:block block :properties-tx []})
|
||||
(update :block dissoc :block/properties-text-values :block/properties-order :block/invalid-properties)))
|
||||
(update :block dissoc :block/properties :block/properties-text-values :block/properties-order :block/invalid-properties)))
|
||||
|
||||
(defn- handle-page-properties
|
||||
[{:block/keys [properties] :as block*} db page-names-to-uuids refs
|
||||
|
|
|
@ -141,7 +141,7 @@
|
|||
|
||||
;; Counts
|
||||
;; Includes journals as property values e.g. :logseq.task/deadline
|
||||
(is (= 13 (count (d/q '[:find ?b :where [?b :block/type "journal"]] @conn))))
|
||||
(is (= 14 (count (d/q '[:find ?b :where [?b :block/type "journal"]] @conn))))
|
||||
|
||||
;; Don't count pages like url.md that have properties but no content
|
||||
(is (= 5
|
||||
|
@ -177,21 +177,22 @@
|
|||
(is (= #{{:db/ident :user.property/prop-bool :block/schema {:type :checkbox}}
|
||||
{:db/ident :user.property/prop-string :block/schema {:type :default}}
|
||||
{:db/ident :user.property/prop-num :block/schema {:type :number}}
|
||||
{:db/ident :user.property/url :block/schema {:type :url}}
|
||||
{:db/ident :user.property/sameas :block/schema {:type :url}}
|
||||
{:db/ident :user.property/rangeincludes :block/schema {:type :page}}
|
||||
{:db/ident :user.property/startedat :block/schema {:type :date}}}
|
||||
(->> @conn
|
||||
(d/q '[:find [(pull ?b [:db/ident :block/schema]) ...]
|
||||
:where [?b :block/type "property"]])
|
||||
(filter #(contains? #{:prop-bool :prop-string :prop-num :rangeincludes :url :sameas
|
||||
:startedat}
|
||||
(filter #(contains? #{:prop-bool :prop-string :prop-num :rangeincludes :sameas :startedat}
|
||||
(keyword (name (:db/ident %)))))
|
||||
set))
|
||||
"Main property types have correct inferred :type")
|
||||
(is (= :default
|
||||
(get-in (d/entity @conn :user.property/description) [:block/schema :type]))
|
||||
"Property value consisting of text and refs is inferred as :default")
|
||||
(is (= :url
|
||||
(get-in (d/entity @conn :user.property/url) [:block/schema :type]))
|
||||
"Property value with a macro correctly inferred as :url")
|
||||
|
||||
(is (= {:user.property/prop-bool true
|
||||
:user.property/prop-num 5
|
||||
|
@ -259,13 +260,25 @@
|
|||
(readable-properties @conn (find-block-by-content @conn "{{query (property :prop-string)}}")))
|
||||
"query block has correct query properties"))
|
||||
|
||||
(testing "db attributes"
|
||||
(is (= true
|
||||
(:block/collapsed? (find-block-by-content @conn "collapsed block")))
|
||||
"Collapsed blocks are imported"))
|
||||
|
||||
(testing "property :type changes"
|
||||
(is (= :page
|
||||
(get-in (d/entity @conn :user.property/finishedat) [:block/schema :type]))
|
||||
"property remains :page after one value is :page and the next is :date")
|
||||
":page property to :date value remains :page")
|
||||
(is (= :default
|
||||
(get-in (d/entity @conn :user.property/duration) [:block/schema :type]))
|
||||
":number property changes to :default after one value is :default"))
|
||||
":number property to :default value changes to :default")
|
||||
|
||||
(is (= :default
|
||||
(get-in (d/entity @conn :user.property/description) [:block/schema :type]))
|
||||
":default property to :page (or any non :default value) remains :default")
|
||||
(is (= "[[Jakob]]"
|
||||
(:user.property/description (readable-properties @conn (find-block-by-content @conn #":default to :page"))))
|
||||
":page property value correctly saved as :default with full text"))
|
||||
|
||||
(testing "tags without tag options"
|
||||
(let [block (find-block-by-content @conn #"Inception")
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
- MEETING TITLE #Meeting
|
||||
template:: meeting
|
||||
participants:: TODO
|
||||
- pending block for :num to :default
|
||||
- pending block for :number to :default
|
||||
duration:: 10
|
||||
- test :num to :default
|
||||
duration:: 20m
|
||||
- test :number to :default
|
||||
duration:: 20m
|
||||
- test :default to :page
|
||||
description:: [[Jakob]]
|
|
@ -0,0 +1,3 @@
|
|||
- collapsed block
|
||||
collapsed:: true
|
||||
- child
|
Loading…
Reference in New Issue