refactor: don't store :checkbox as ref type

pull/11451/head
Tienson Qin 2024-08-01 13:06:47 +08:00
parent 76f7baedd3
commit 8c81895ff7
10 changed files with 32 additions and 49 deletions

View File

@ -442,7 +442,7 @@
(defn built-in?
"Built-in page or block"
[entity]
(db-property/property-value-content (:logseq.property/built-in? entity)))
(:logseq.property/built-in? entity))
(defn built-in-class-property?
"Whether property a built-in property for the specific class"

View File

@ -33,7 +33,7 @@
"Property value ref types where the refed entity stores its value in
:property.value/content e.g. :number is stored as a number. new value-ref-property-types
should default to this as it allows for more querying power"
#{:number :url :checkbox})
#{:number :url})
(def value-ref-property-types
"Property value ref types where the refed entities either store their value in
@ -105,10 +105,6 @@
(when-let [entity (d/entity db id-or-value)]
(number? (:property.value/content entity)))))
(defn- checkbox-entity?
[db id]
(boolean? (:property.value/content (d/entity db id))))
(defn- text-entity?
[db s {:keys [new-closed-value?]}]
(if new-closed-value?
@ -128,7 +124,6 @@
(and (some? (:block/title ent))
(contains? (:block/type ent) "journal"))))
(def built-in-validation-schemas
"Map of types to malli validation schemas that validate a property value for that type"
{:default [:fn
@ -140,7 +135,7 @@
:date [:fn
{:error/message "should be a journal date"}
date?]
:checkbox checkbox-entity?
:checkbox boolean?
:url [:fn
{:error/message "should be a URL"}
url-entity?]
@ -165,7 +160,7 @@
(def property-types-with-db
"Property types whose validation fn requires a datascript db"
#{:default :checkbox :url :number :date :node :entity})
#{:default :url :number :date :node :entity})
;; Helper fns
;; ==========

View File

@ -169,10 +169,12 @@
:page-property
'[(page-property ?p ?prop ?val)
[?p :block/name]
[?p ?prop ?pv]
(or [?pv :block/title ?val]
[?pv :property.value/content ?val])
[?p :block/name]
(or
[?pv :block/title ?val]
[?pv :property.value/content ?val]
[(= ?pv ?val)])
[?prop-e :db/ident ?prop]
[?prop-e :block/type "property"]]
@ -186,8 +188,10 @@
:property
'[(property ?b ?prop ?val)
[?b ?prop ?pv]
(or [?pv :block/title ?val]
[?pv :property.value/content ?val])
(or
[?pv :block/title ?val]
[?pv :property.value/content ?val]
[(= ?pv ?val)])
[(missing? $ ?b :block/name)]
[?prop-e :db/ident ?prop]
[?prop-e :block/type "property"]]

View File

@ -256,8 +256,6 @@
_ (when db-graph?
(reset! db-order/*max-key (db-order/get-max-order db)))
schema (:schema db)
built-in-value (when-let [id (:db/id (:logseq.property/built-in? (d/entity db :logseq.class/Root)))]
(d/datoms db :eavt id))
idents (mapcat (fn [id]
(when-let [e (d/entity db id)]
(d/datoms db :eavt (:db/id e))))
@ -269,8 +267,7 @@
all-pages (get-all-pages db)
structured-datoms (when db-graph?
(get-structured-datoms db))
data (concat built-in-value
idents
data (concat idents
all-pages
structured-datoms
favorites

View File

@ -10,8 +10,8 @@
[logseq.db.frontend.schema :as db-schema]
[logseq.db.sqlite.util :as sqlite-util]))
(defn- mark-block-as-built-in [block built-in-prop-value]
(assoc block :logseq.property/built-in? [:block/uuid (:block/uuid built-in-prop-value)]))
(defn- mark-block-as-built-in [block]
(assoc block :logseq.property/built-in? true))
(defn build-initial-properties*
[built-in-properties]
@ -40,19 +40,13 @@
:logseq.property/built-in?
built-in-property-schema
{:title (name :logseq.property/built-in?)})
built-in-prop-value (db-property-build/build-property-value-block
{:db/id [:block/uuid (:block/uuid built-in-property)]}
{:db/ident :logseq.property/built-in?
:block/schema built-in-property-schema}
true)
mark-block-as-built-in' (fn [block]
(mark-block-as-built-in {:block/uuid (:block/uuid block)} built-in-prop-value))
(mark-block-as-built-in {:block/uuid (:block/uuid block)}))
properties (build-initial-properties* db-property/built-in-properties)
;; Tx order matters. built-in-property must come first as all properties depend on it.
tx (concat [built-in-property]
properties
[built-in-prop-value]
;; Adding built-ins must come after initial properties and built-in-prop-value
;; Adding built-ins must come after initial properties
[(mark-block-as-built-in' built-in-property)]
(map mark-block-as-built-in' properties)
(keep #(when (= #{"closed value"} (:block/type %)) (mark-block-as-built-in' %))
@ -62,8 +56,7 @@
(assert (string/starts-with? (str block-uuid) "00000002") m)))
{:tx tx
:properties (filter #(contains? (:block/type %) "property") properties)
:built-in-prop-value built-in-prop-value}))
:properties (filter #(contains? (:block/type %) "property") properties)}))
(defn kv
"Creates a key-value pair tx with the key and value respectively stored under
@ -87,7 +80,7 @@
(vec conflicting-idents))
{:idents conflicting-idents}))))
(defn- build-initial-classes [db-ident->properties built-in-prop-value]
(defn- build-initial-classes [db-ident->properties]
(map
(fn [[db-ident {:keys [schema title]}]]
(let [title' (or title (name db-ident))]
@ -105,8 +98,7 @@
:db/ident db-ident
:block/uuid (common-uuid/gen-uuid :db-ident-block-uuid db-ident)}
(seq properties)
(assoc :class/schema.properties properties))))
built-in-prop-value)))
(assoc :class/schema.properties properties)))))))
db-class/built-in-classes))
(defn build-db-initial-data
@ -133,11 +125,11 @@
:file/content ""
:file/created-at (js/Date.)
:file/last-modified-at (js/Date.)}]
{properties-tx :tx :keys [built-in-prop-value properties]} (build-initial-properties)
{properties-tx :tx :keys [properties]} (build-initial-properties)
db-ident->properties (zipmap (map :db/ident properties) properties)
default-classes (build-initial-classes db-ident->properties built-in-prop-value)
default-classes (build-initial-classes db-ident->properties)
default-pages (->> (map sqlite-util/build-new-page built-in-pages-names)
(map #(mark-block-as-built-in % built-in-prop-value)))
(map mark-block-as-built-in))
tx (vec (concat initial-data properties-tx default-classes
initial-files default-pages))]
(validate-tx-for-duplicate-idents tx)

View File

@ -25,7 +25,7 @@
configure-opts {:selected? false
:page-configure? configure?}
has-viewable-properties? (outliner-property/block-has-viewable-properties? page)
hide-properties? (db-property/property-value-content (:logseq.property/hide-properties? page))]
hide-properties? (:logseq.property/hide-properties? page)]
(when (or configure? (and (not hide-properties?) has-viewable-properties?))
[:div.ls-page-properties
{:class (util/classnames [{:no-properties (not has-viewable-properties?)}])}

View File

@ -100,7 +100,7 @@
(when-not (or contents?
config/publishing?
(and db-based?
(db-property/property-value-content (:logseq.property/built-in? page))))
(:logseq.property/built-in? page)))
{:title (t :page/delete)
:options {:on-click #(delete-page-confirm! page)}})

View File

@ -756,14 +756,12 @@
(property-value-date-picker block property value (merge opts {:editing? editing?}))
:checkbox
(let [add-property! (fn []
(<add-property! block (:db/ident property)
(boolean (not (db-property/property-value-content value)))))]
(let [add-property! (fn [] (<add-property! block (:db/ident property) (boolean (not value))))]
[:label.flex.w-full.as-scalar-value-wrap.cursor-pointer
(shui/checkbox {:class "jtrigger flex flex-row items-center"
:disabled config/publishing?
:auto-focus editing?
:checked (db-property/property-value-content value)
:checked value
:on-checked-change add-property!
:on-key-down (fn [e]
(when (= (util/ekey e) "Enter")
@ -860,7 +858,7 @@
(first v)
:else
v)
empty-value? (= :logseq.property/empty-placeholder (:db/ident (first v)))
empty-value? (when (coll? v) (= :logseq.property/empty-placeholder (:db/ident (first v))))
closed-values? (seq (:property/closed-values property))
value-cp [:div.property-value-inner
{:data-type type

View File

@ -44,8 +44,7 @@
[frontend.modules.outliner.ui :as ui-outliner-tx]
[frontend.modules.outliner.op :as outliner-op]
[frontend.handler.property.util :as pu]
[datascript.impl.entity :as de]
[logseq.db.frontend.property :as db-property]))
[datascript.impl.entity :as de]))
(def <create! page-common-handler/<create!)
(def <delete! page-common-handler/<delete!)
@ -496,5 +495,4 @@
(property-handler/set-block-property! (state/get-current-repo)
(:block/uuid page-entity)
:logseq.property/hide-properties?
(not
(db-property/property-value-content (:logseq.property/hide-properties? page-entity)))))
(not (:logseq.property/hide-properties? page-entity))))

View File

@ -79,7 +79,6 @@
(> db-schema/version version-in-db)
(let [db-based? (ldb/db-based-graph? @conn)
built-in-value (:db/id (get (d/entity db :logseq.class/Root) :logseq.property/built-in?))
updates (keep (fn [[v updates]]
(when (and (< version-in-db v) (<= v db-schema/version))
updates))
@ -94,7 +93,7 @@
(assert (str "DB migration: property already exists " k)))))
(into {})
sqlite-create-graph/build-initial-properties*
(map (fn [b] (assoc b :logseq.property/built-in? built-in-value))))
(map (fn [b] (assoc b :logseq.property/built-in? true))))
fixes (mapcat
(fn [update]
(when-let [fix (:fix update)]