fix: use :entity type instead of :uuid for ref type values

pull/11196/head
Tienson Qin 2024-04-04 18:07:26 +08:00 committed by Gabriel Horner
parent 7c1f52d2a4
commit b096b4673c
7 changed files with 25 additions and 24 deletions

View File

@ -28,7 +28,7 @@
(let [[property-type schema-fn] e (let [[property-type schema-fn] e
schema-fn' (if (db-property-type/property-types-with-db property-type) (partial schema-fn db) schema-fn) schema-fn' (if (db-property-type/property-types-with-db property-type) (partial schema-fn db) schema-fn)
validation-fn #(validate-property-value property-type schema-fn' %)] validation-fn #(validate-property-value property-type schema-fn' %)]
[property-type [:tuple :uuid [:fn validation-fn]]]) [property-type [:tuple :entity [:fn validation-fn]]])
:else :else
e))) e)))
db-schema)) db-schema))

View File

@ -46,10 +46,10 @@
:public? true}} :public? true}}
;; number (1-6) or boolean for auto heading ;; number (1-6) or boolean for auto heading
:logseq.property/heading {:schema {:type :any :hide? true}} :logseq.property/heading {:schema {:type :any :hide? true}}
:logseq.property/created-from-block {:schema {:type :uuid}} :logseq.property/created-from-block {:schema {:type :entity}}
:logseq.property/created-from-property {:schema {:type :uuid}} :logseq.property/created-from-property {:schema {:type :entity}}
:logseq.property/created-from-template {:schema {:type :uuid}} :logseq.property/created-from-template {:schema {:type :entity}}
:logseq.property/source-page-id {:schema {:type :uuid}} :logseq.property/source-page {:schema {:type :entity}}
:logseq.property/built-in? {:schema {:type :checkbox}} :logseq.property/built-in? {:schema {:type :checkbox}}
:logseq.property/hide-properties? {:schema {:type :checkbox}} :logseq.property/hide-properties? {:schema {:type :checkbox}}
:logseq.property/query-table {:schema {:type :checkbox}} :logseq.property/query-table {:schema {:type :checkbox}}

View File

@ -12,7 +12,7 @@
(def internal-built-in-property-types (def internal-built-in-property-types
"Valid property types only for use by internal built-in-properties" "Valid property types only for use by internal built-in-properties"
#{:keyword :map :coll :any :uuid}) #{:keyword :map :coll :any :uuid :entity})
(def user-built-in-property-types (def user-built-in-property-types
"Valid property types for users in order they appear in the UI" "Valid property types for users in order they appear in the UI"
@ -60,14 +60,11 @@
;; TODO: Confirm that macro expanded value is url when it's easier to pass data into validations ;; TODO: Confirm that macro expanded value is url when it's easier to pass data into validations
(macro-util/macro? s)) (macro-util/macro? s))
(defn- logseq-block? (defn- entity?
[db id] [db id]
(some? (d/entity db id))) (some? (d/entity db id)))
;; FIXME: template instance check ;; TODO: strict check on date/page/template
(defn- logseq-template?
[db id]
(some? (d/entity db id)))
(defn- existing-closed-value-valid? (defn- existing-closed-value-valid?
"Validates that the given existing closed value is valid" "Validates that the given existing closed value is valid"
@ -106,17 +103,20 @@
(some-fn number? uuid?)] (some-fn number? uuid?)]
:date [:fn :date [:fn
{:error/message "should be a journal date"} {:error/message "should be a journal date"}
logseq-block?] entity?]
:checkbox boolean? :checkbox boolean?
:url [:fn :url [:fn
{:error/message "should be a URL"} {:error/message "should be a URL"}
(some-fn url? uuid? macro-url?)] (some-fn url? uuid? macro-url?)]
:page [:fn :page [:fn
{:error/message "should be a page"} {:error/message "should be a page"}
logseq-block?] entity?]
:template [:fn :template [:fn
{:error/message "should has #template"} {:error/message "should has #template"}
logseq-template?] entity?]
:entity [:fn
{:error/message "should be a db entity"}
entity?]
;; internal usage ;; internal usage
:keyword keyword? :keyword keyword?
:uuid uuid? :uuid uuid?
@ -132,7 +132,7 @@
(def property-types-with-db (def property-types-with-db
"Property types whose validation fn requires a datascript db" "Property types whose validation fn requires a datascript db"
#{:date :page :template}) #{:date :page :template :entity})
;; Helper fns ;; Helper fns
;; ========== ;; ==========

View File

@ -64,7 +64,7 @@
(assoc :block/created-at updated-at))] (assoc :block/created-at updated-at))]
block)) block))
(def property-ref-types #{:page :block :date :object}) (def property-ref-types #{:page :block :date :entity})
(defn build-new-property (defn build-new-property
"Build a standard new property so that it is is consistent across contexts" "Build a standard new property so that it is is consistent across contexts"

View File

@ -3638,7 +3638,7 @@
(defn hidden-page->source-page (defn hidden-page->source-page
[page] [page]
(or (or
(:logseq.property/source-page-id page) (get page (pu/get-pid :logseq.property/source-page))
;; FIXME: what if the source page has been deleted? ;; FIXME: what if the source page has been deleted?
page)) page))

View File

@ -648,6 +648,7 @@
multiple-values? (= :many (:cardinality schema)) multiple-values? (= :many (:cardinality schema))
class (str (when-not row? "flex flex-1 ") class (str (when-not row? "flex flex-1 ")
(when multiple-values? "property-value-content")) (when multiple-values? "property-value-content"))
type (:type schema)
type (or (when (and (= type :default) (uuid? value)) :block) type (or (when (and (= type :default) (uuid? value)) :block)
type type
:default) :default)
@ -671,7 +672,7 @@
(nil? (:block/_parent property-block)))) (nil? (:block/_parent property-block))))
value (if invalid-block? "" value)] value (if invalid-block? "" value)]
(when (or (= type :default) invalid-block?) (when (or (= type :default) invalid-block?)
(set-editing! (assoc property :block/uuid (random-uuid)) editor-id dom-id value {:ref @*ref}))))} (set-editing! property editor-id dom-id value {:ref @*ref}))))}
(if (string/blank? value) (if (string/blank? value)
(if template? (if template?
(let [id (first (:classes schema)) (let [id (first (:classes schema))

View File

@ -451,14 +451,14 @@
(defn property-create-new-block (defn property-create-new-block
[block property value parse-block] [block property value parse-block]
(let [current-page-id (:block/uuid (or (:block/page block) block)) (let [current-page-id (:db/id (or (:block/page block) block))
page-name (str "$$$" current-page-id) page-name (str "$$$" current-page-id)
page-entity (db/entity [:block/name page-name]) page-entity (db/entity [:block/name page-name])
page (or page-entity page (or page-entity
(-> (block/page-name->map page-name true) (-> (block/page-name->map page-name true)
(assoc :block/type #{"hidden"} (assoc :block/type #{"hidden"}
:block/format :markdown :block/format :markdown
:logseq.property/source-page-id current-page-id))) :logseq.property/source-page current-page-id)))
page-tx (when-not page-entity page) page-tx (when-not page-entity page)
page-id [:block/uuid (:block/uuid page)] page-id [:block/uuid (:block/uuid page)]
parent-id (db/new-block-id) parent-id (db/new-block-id)
@ -469,8 +469,8 @@
:block/parent page-id :block/parent page-id
:block/left (or (when page-entity (model/get-block-last-direct-child-id (db/get-db) (:db/id page-entity))) :block/left (or (when page-entity (model/get-block-last-direct-child-id (db/get-db) (:db/id page-entity)))
page-id) page-id)
:logseq.property/created-from-block block :logseq.property/created-from-block (:db/id block)
:logseq.property/created-from-property property} :logseq.property/created-from-property (:db/id property)}
sqlite-util/block-with-timestamps) sqlite-util/block-with-timestamps)
child-1-id (db/new-block-id) child-1-id (db/new-block-id)
child-1 (-> {:block/uuid child-1-id child-1 (-> {:block/uuid child-1-id
@ -503,14 +503,14 @@
(defn property-create-new-block-from-template (defn property-create-new-block-from-template
[block property template] [block property template]
(let [current-page-id (:block/uuid (or (:block/page block) block)) (let [current-page-id (:db/id (or (:block/page block) block))
page-name (str "$$$" current-page-id) page-name (str "$$$" current-page-id)
page-entity (db/entity [:block/name page-name]) page-entity (db/entity [:block/name page-name])
page (or page-entity page (or page-entity
(-> (block/page-name->map page-name true) (-> (block/page-name->map page-name true)
(assoc :block/type #{"hidden"} (assoc :block/type #{"hidden"}
:block/format :markdown :block/format :markdown
:logseq.property/source-page-id current-page-id))) :logseq.property/source-page current-page-id)))
page-tx (when-not page-entity page) page-tx (when-not page-entity page)
page-id [:block/uuid (:block/uuid page)] page-id [:block/uuid (:block/uuid page)]
block-id (db/new-block-id) block-id (db/new-block-id)