fix: store text values as entities

pull/11177/head
Tienson Qin 2024-04-15 20:39:36 +08:00
parent 7fb5fb7511
commit fb93a35fbc
4 changed files with 39 additions and 48 deletions

View File

@ -25,7 +25,7 @@
(assert (set/subset? closed-value-property-types (set user-built-in-property-types))
"All closed value types are valid property types")
(def ref-property-types #{:page :date :entity})
(def ref-property-types #{:default :page :date :entity})
(assert (set/subset? ref-property-types
(into internal-built-in-property-types
@ -102,9 +102,9 @@
(def built-in-validation-schemas
"Map of types to malli validation schemas that validate a property value for that type"
{:default [:fn
{:error/message "should be a text"}
;; uuid check needed for property block values
(some-fn string? uuid?)] ; refs/tags will not be extracted
{:error/message "should be a entity"}
;; entity check needed for property block values
entity?]
:number [:fn
{:error/message "should be a number"}
;; TODO: Remove uuid? for :number and :url when type-or-closed-value? is used in this ns
@ -139,7 +139,7 @@
(def property-types-with-db
"Property types whose validation fn requires a datascript db"
#{:date :page :template :entity})
#{:default :date :page :template :entity})
;; Helper fns
;; ==========

View File

@ -28,8 +28,8 @@
[frontend.handler.property.util :as pu]))
(rum/defc property-empty-value
[]
(shui/button {:class "empty-btn" :variant :text} "Empty"))
[& {:as opts}]
(shui/button (merge {:class "empty-btn" :variant :text} opts) "Empty"))
(rum/defc icon-row < rum/reactive
[block]
@ -495,7 +495,7 @@
(when value
(if (state/sub-async-query-loading value)
[:div.text-sm.opacity-70 "loading"]
(if-let [v-block (db/sub-block (:db/id (db/entity [:block/uuid value])))]
(if-let [v-block (db/sub-block (:db/id value))]
(let [class? (contains? (:block/type v-block) "class")
invalid-warning [:div.warning.text-sm
"Invalid block value, please delete the current property."]]
@ -515,8 +515,8 @@
(:block/name v-block)
(rum/with-key
(page-cp {:disable-preview? true
:hide-close-button? true
:tag? class?} v-block)
:hide-close-button? true
:tag? class?} v-block)
(:db/id v-block))
:else
invalid-warning)
@ -634,14 +634,12 @@
class (str (when-not row? "flex flex-1 ")
(when multiple-values? "property-value-content"))
type (:type schema)
type (or (when (and (= type :default) (uuid? value)) :block)
type
:default)
type (if (= :block type)
(let [v-block (db/entity value)]
(if (get v-block (pu/get-pid :logseq.property/created-from-template))
:template
type))
type (if (= :default type)
(or
(let [v-block (db/entity value)]
(when (get v-block (pu/get-pid :logseq.property/created-from-template))
:template))
type)
type)
template? (= :template type)]
[:div.cursor-text.jtrigger
@ -650,32 +648,24 @@
:class class
:style {:min-height 24}
:on-click (fn []
(let [property-block (when (and (= type :block) (uuid? value))
(db/entity [:block/uuid value]))
invalid-block? (and (= type :block) (uuid? value)
(or (nil? property-block)
(nil? (:block/_parent property-block))))
value (if invalid-block? "" value)]
(when (or (= type :default) invalid-block?)
(set-editing! block property editor-id dom-id value opts))))}
(if (string/blank? value)
(if template?
(let [id (first (:classes schema))
template (when id (db/entity [:block/uuid id]))]
(when template
[:a.fade-link.pointer.text-sm.jtrigger
{:on-click (fn [e]
(util/stop e)
(<create-new-block-from-template! block property template))}
(str "Use template #" (:block/original-name template))]))
(property-empty-value))
;; FIXME:
)}
(if (and (string/blank? value) template?)
(let [id (first (:classes schema))
template (when id (db/entity [:block/uuid id]))]
(when template
[:a.fade-link.pointer.text-sm.jtrigger
{:on-click (fn [e]
(util/stop e)
(<create-new-block-from-template! block property template))}
(str "Use template #" (:block/original-name template))]))
(cond
(= type :template)
(property-template-value {:editor-id editor-id}
value
opts)
(and (= type :block) (uuid? value))
(= type :default)
(property-block-value value block property block-cp editor-box opts page-cp editor-id)
:else

View File

@ -542,13 +542,14 @@
last-block-id (:block/uuid (last blocks))
class? (contains? (:block/type block) "class")
property-id (:db/ident property)]
(db/transact! repo (if page (cons page blocks) blocks) {:outliner-op :insert-blocks})
(let [result (when property-id
(if (and class? class-schema?)
(class-add-property! repo (:db/id block) property-id)
(set-block-property! repo (:db/id block) property-id (:block/uuid first-block) {})))]
{:last-block-id last-block-id
:result result})))
(p/let [_ (db/transact! repo (if page (cons page blocks) blocks) {:outliner-op :insert-blocks})]
(let [result (when property-id
(if (and class? class-schema?)
(class-add-property! repo (:db/id block) property-id)
(when-let [parent-id (:db/id (db/entity [:block/uuid (:block/uuid first-block)]))]
(set-block-property! repo (:db/id block) property-id parent-id {}))))]
{:last-block-id last-block-id
:result result}))))
(defn property-create-new-block-from-template
[block property template]

View File

@ -10,7 +10,8 @@
[logseq.db.frontend.validate :as db-validate]
[logseq.db.sqlite.util :as sqlite-util]
[logseq.outliner.datascript-report :as ds-report]
[logseq.outliner.pipeline :as outliner-pipeline]))
[logseq.outliner.pipeline :as outliner-pipeline]
[logseq.db.frontend.property :as db-property]))
(defn- path-refs-need-recalculated?
[tx-meta]
@ -43,8 +44,7 @@
created-from-property (get b :logseq.property/created-from-property)
created-block (d/entity after-db (:db/id created-from-block))]
(when (and created-block created-from-property)
[[:db/retractEntity (:db/id b)]
[:db/add (:db/id created-block) (:db/ident created-from-property) ""]])))
[[:db/retractEntity (:db/id b)]])))
empty-property-parents)
(remove nil?)))))