Remove :block/properties-text-values for db based graphs

pull/10016/head
Tienson Qin 2023-07-19 11:41:53 +08:00
parent 88371b8ad4
commit eb35d45d73
5 changed files with 43 additions and 52 deletions

View File

@ -112,7 +112,7 @@
(def schema-for-db-based-graph
(merge
schema
(dissoc schema :block/properties-text-values)
{}))
(def retract-attributes

View File

@ -66,7 +66,6 @@
[:label "Multiple values:"]
(let [many? (boolean (= :many (:cardinality @*property-schema)))]
(ui/checkbox {:checked many?
:disabled (if (= type :default) "disabled")
:on-change (fn []
(swap! *property-schema assoc :cardinality (if many? :one :many)))}))])
@ -463,15 +462,13 @@
(property-handler/delete-property-value! (state/get-current-repo)
entity
(:block/uuid property)
(or parsed-value item)))}
item))}
svg/close])]))
(rum/defcs property-value < rum/reactive
[state block property value opts]
(let [k (:block/uuid property)
v (get (:block/properties-text-values block)
k
(get (:block/properties block) k))
v (get (:block/properties block) k)
dom-id (str "ls-property-" (:blocks-container-id opts) "-" k)
editor-id (str "ls-property-" (:blocks-container-id opts) "-" (:db/id block) "-" (:db/id property))
schema (:block/schema property)
@ -545,8 +542,6 @@
(let [properties (:properties (:block/schema block))]
(map (fn [k] [k nil]) properties))
(:block/properties block))
properties-text-values (if (:class-schema? opts) {}
(:block/properties-text-values block))
new-property? (= edit-input-id (state/sub :ui/new-property-input-id))
class-properties (->> (:block/tags block)
(mapcat (fn [tag]
@ -565,7 +560,6 @@
{:class "select-none"})
(when (seq properties)
(for [[prop-uuid-or-built-in-prop v] properties]
(let [v* (get properties-text-values prop-uuid-or-built-in-prop v)]
(if (uuid? prop-uuid-or-built-in-prop)
(when-let [property (db/sub-block (:db/id (db/entity [:block/uuid prop-uuid-or-built-in-prop])))]
[:div.property-pair
@ -575,10 +569,10 @@
[:div.property-description.col-span-3.font-light
(get-in property [:block/schema :description])]
[:div.property-value.col-span-3
(property-value block property v* (assoc opts :parsed-value v))])])
(property-value block property v (assoc opts :parsed-value v))])])
;; TODO: built in properties should have UUID and corresponding schema
;; builtin
[:div
[:a.mr-2 (str prop-uuid-or-built-in-prop)]
[:span v*]]))))
[:span v]])))
(new-property repo block edit-input-id properties new-property? opts)])))

View File

@ -13,6 +13,8 @@
[logseq.graph-parser.util :as gp-util]
[frontend.db.listener :as db-listener]))
;; FIXME: db-version properties
(defn clear-selection!
[]
(state/clear-selection!))

View File

@ -19,6 +19,9 @@
[malli.core :as m]
[malli.error :as me]))
;; TODO:
;; Validate && list fixes for non-validated values when updating property schema
(defn- date-str?
[value]
(when-let [d (js/Date. value)]
@ -43,7 +46,7 @@
(seq (:block/class e)))))
(def builtin-schema-types
{:default string? ; default, might be mixed with refs, tags
{:default string? ; refs/tags will not be extracted
:number number?
:date [:fn
{:error/message "should be a date"}
@ -152,47 +155,32 @@
(notification/show! msg' :warning))
(do
(upsert-property! repo property k-name property-uuid property-type)
(let [refs (cond
(= property-type :default)
(block/extract-refs-from-text v*)
(uuid? v*)
[:block/uuid v*])
v' (if (= property-type :default)
(if (seq refs)
(distinct (map :block/uuid refs)) v*)
v*)
new-value (cond
(let [new-value (cond
(and multiple-values? old-value
(not= old-value :frontend.components.property/new-value-placeholder))
(if (coll? v')
(vec (distinct (concat value v')))
(let [v (mapv (fn [x] (if (= x old-value) v' x)) value)]
(if (contains? (set v) v')
(if (coll? v*)
(vec (distinct (concat value v*)))
(let [v (mapv (fn [x] (if (= x old-value) v* x)) value)]
(if (contains? (set v) v*)
v
(conj v v'))))
(conj v v*))))
multiple-values?
(let [f (if (coll? v') concat conj)]
(vec (distinct (f value v'))))
(let [f (if (coll? v*) concat conj)]
(vec (distinct (f value v*))))
:else
v')
v*)
new-value (if (coll? new-value)
(vec (remove string/blank? new-value))
new-value)
block-properties (assoc properties property-uuid new-value)
block-properties-text-values
(if (= property-type :default)
(assoc (:block/properties-text-values block) property-uuid v*)
(dissoc (:block/properties-text-values block) property-uuid))
refs (outliner-core/rebuild-block-refs block block-properties)]
;; TODO: fix block/properties-order
(db/transact! repo
[[:db/retract (:db/id block) :block/refs]
{:block/uuid (:block/uuid block)
:block/properties block-properties
:block/properties-text-values block-properties-text-values
:block/refs refs}]
{:outliner-op :add-property})))))))))
@ -208,7 +196,6 @@
[[:db/retract (:db/id block) :block/refs]
{:block/uuid (:block/uuid block)
:block/properties properties'
:block/properties-text-values (dissoc (:block/properties-text-values block) property-uuid)
:block/refs refs}]
{:outliner-op :remove-property})))))

View File

@ -150,12 +150,20 @@
(cond
(and (coll? v) (uuid? (first v)))
v
(uuid? v)
[v]
(and (coll? v) (string? (first v)))
(mapcat block/extract-refs-from-text v)
(string? v)
(block/extract-refs-from-text v)
:else
nil))))
property-refs (->> (concat property-key-refs property-value-refs)
(map (fn [id] {:block/uuid id})))
(map (fn [id-or-map] (if (uuid? id-or-map) {:block/uuid id-or-map} id-or-map))))
content-refs (when-not skip-content-parsing?
(some-> (:block/content block) block/extract-refs-from-text))]
(concat property-refs content-refs)))