refactor: don't couple internal ref types to places it's not used

Follow up to #11494. Internal ref types are not used in most of the UI
and in any of the outliner layer.  Have separate vars for internal and
user ref types so we can see how they're used
pull/11506/head
Gabriel Horner 2024-09-03 16:23:04 -04:00
parent 2654ca9b6f
commit c36984c433
7 changed files with 38 additions and 34 deletions

View File

@ -42,19 +42,24 @@
(def value-ref-property-types
"Property value ref types where the refed entities either store their value in
:property.value/content or :block/title (for :default)"
(into #{:default}
original-value-ref-property-types))
(into #{:default} original-value-ref-property-types))
(def ref-property-types
"Ref types. Property values that users see are stored in either
:property.value/content, :block/title.
:block/title is for all the page related types"
(into #{:date :node :entity :class :page :property} value-ref-property-types))
(def user-ref-property-types
"User ref types. Property values that users see are stored in either
:property.value/content or :block/title. :block/title is for all the page related types"
(into #{:date :node} value-ref-property-types))
(assert (set/subset? ref-property-types
(set/union (set user-built-in-property-types) internal-built-in-property-types))
(assert (set/subset? user-ref-property-types
(set user-built-in-property-types))
"All ref types are valid property types")
(def all-ref-property-types
"All ref types - user and internal"
(into #{:entity :class :page :property} user-ref-property-types))
(assert (set/subset? all-ref-property-types
(set/union (set user-built-in-property-types) internal-built-in-property-types))
"All ref types are valid property types")
;; Property value validation
;; =========================

View File

@ -104,7 +104,7 @@
:block/order (db-order/gen-key)}
(seq classes)
(assoc :property/schema.classes classes)
(or ref-type? (contains? (conj db-property-type/ref-property-types :entity) (:type prop-schema)))
(or ref-type? (contains? db-property-type/all-ref-property-types (:type prop-schema)))
(assoc :db/valueType :db.type/ref))))))
(defn build-new-class

View File

@ -128,7 +128,7 @@
(if-let [built-in-type (get-in db-property/built-in-properties [k :schema :type])]
(if (= :block/tags k)
(mapv #(:db/ident (d/entity db (:db/id %))) v)
(if (db-property-type/ref-property-types built-in-type)
(if (db-property-type/all-ref-property-types built-in-type)
(db-property/ref->property-value-contents db v)
v))
(db-property/ref->property-value-contents db v))])))

View File

@ -75,8 +75,8 @@
(let [ident (:db/ident property)
cardinality (if (= cardinality :many) :db.cardinality/many :db.cardinality/one)
old-type (get-in property [:block/schema :type])
old-ref-type? (db-property-type/ref-property-types old-type)
ref-type? (db-property-type/ref-property-types type')]
old-ref-type? (db-property-type/user-ref-property-types old-type)
ref-type? (db-property-type/user-ref-property-types type')]
[(cond->
{:db/ident ident
:db/cardinality cardinality}
@ -247,7 +247,7 @@
(when-not (and (= property-id :block/alias) (= v (:db/id block))) ; alias can't be itself
(ldb/transact! conn [{:db/id (:db/id block) property-id v}]
{:outliner-op :save-block}))
(let [new-value (if (db-property-type/ref-property-types property-type)
(let [new-value (if (db-property-type/user-ref-property-types property-type)
(convert-ref-property-value conn property-id v property-type)
v)
existing-value (get block property-id)]

View File

@ -397,7 +397,7 @@
(shui/popup-show! (.-target e)
(fn [{:keys [id]}]
(let [opts {:toggle-fn (fn [] (shui/popup-hide! id))}
values' (->> (if (contains? db-property-type/ref-property-types (get-in property [:block/schema :type]))
values' (->> (if (contains? db-property-type/user-ref-property-types (get-in property [:block/schema :type]))
(map #(:block/uuid (db/entity %)) values)
values)
(remove string/blank?)

View File

@ -116,21 +116,21 @@
checkbox? (= :checkbox (get-in property [:block/schema :type]))]
(assert (qualified-keyword? property-id) "property to add must be a keyword")
(p/do!
(if (and class? class-schema?)
(db-property-handler/class-add-property! (:db/id block) property-id)
(if (and (db-property-type/ref-property-types (get-in property [:block/schema :type]))
(string? property-value'))
(<create-new-block! block (db/entity property-id) property-value' {:edit-block? false})
(property-handler/set-block-property! repo (:block/uuid block) property-id property-value')))
(when exit-edit?
(ui/hide-popups-until-preview-popup!)
(shui/dialog-close!))
(when-not (or many? checkbox?)
(when-let [input (state/get-input)]
(.focus input)))
(when checkbox?
(state/set-editor-action-data! {:type :focus-property-value
:property property}))))))
(if (and class? class-schema?)
(db-property-handler/class-add-property! (:db/id block) property-id)
(if (and (db-property-type/user-ref-property-types (get-in property [:block/schema :type]))
(string? property-value'))
(<create-new-block! block (db/entity property-id) property-value' {:edit-block? false})
(property-handler/set-block-property! repo (:block/uuid block) property-id property-value')))
(when exit-edit?
(ui/hide-popups-until-preview-popup!)
(shui/dialog-close!))
(when-not (or many? checkbox?)
(when-let [input (state/get-input)]
(.focus input)))
(when checkbox?
(state/set-editor-action-data! {:type :focus-property-value
:property property}))))))
(defn- add-or-remove-property-value
[block property value selected? {:keys [refresh-result-f]}]
@ -519,7 +519,7 @@
(let [schema (:block/schema property)
type (:type schema)
closed-values? (seq (:property/closed-values property))
ref-type? (db-property-type/ref-property-types type)
ref-type? (db-property-type/user-ref-property-types type)
items (if closed-values?
(keep (fn [block]
(let [icon (pu/get-block-property-value block :logseq.property/icon)

View File

@ -95,11 +95,10 @@
[block property]
(let [type (get-in property [:block/schema :type])
many? (= :db.cardinality/many (get property :db/cardinality))
ref-types (into db-property-type/ref-property-types #{:entity})
number-type? (= :number type)
v (get block (:db/ident property))
v' (if many? v [v])
col (->> (if (ref-types type) (map db-property/property-value-content v') v')
col (->> (if (db-property-type/all-ref-property-types type) (map db-property/property-value-content v') v')
(remove nil?))]
(if number-type?
(reduce + (filter number? col))
@ -375,7 +374,7 @@
[property]
(let [schema (:block/schema property)
type (:type schema)]
(db-property-type/ref-property-types type))))
(db-property-type/all-ref-property-types type))))
(defn- get-property-values
[rows property]