Просмотр исходного кода

chore: rename :property/value to :property.value/content

property-value is widely being used to refer to the entity or value
associated with a property entity. Naming the content of a
property-entity :property/value is confusing. property-value content is
a unique name and consistent with :block/content. Also rename related
fns which had similarly confusing names
Gabriel Horner 1 год назад
Родитель
Сommit
244a86557f

+ 5 - 5
deps/db/src/logseq/db/frontend/malli_schema.cljs

@@ -360,7 +360,7 @@
   (vec
    (concat
     [:map]
-    [[:property/value [:or :string :double]]]
+    [[:property.value/content [:or :string :double]]]
     (remove #(#{:block/content} (first %)) block-attrs)
     page-or-block-attrs)))
 
@@ -372,7 +372,7 @@
      ;; for built-in properties
      [:db/ident {:optional true} logseq-property-ident]
      [:block/content {:optional true} :string]
-     [:property/value {:optional true} [:or :string :double]]
+     [:property.value/content {:optional true} [:or :string :double]]
      [:block/closed-value-property {:optional true} [:set :int]]
      [:block/schema {:optional true}
       [:map
@@ -383,10 +383,10 @@
 (def closed-value-block
   "A closed value for a property with closed/allowed values"
   [:and closed-value-block*
-   [:fn {:error/message ":block/content or :property/value required"
-         :error/path [:property/value]}
+   [:fn {:error/message ":block/content or :property.value/content required"
+         :error/path [:property.value/content]}
     (fn [m]
-      (or (:block/content m) (:property/value m)))]])
+      (or (:block/content m) (:property.value/content m)))]])
 
 (def normal-block
   "A block with content and no special type or tag behavior"

+ 16 - 17
deps/db/src/logseq/db/frontend/property.cljs

@@ -223,44 +223,43 @@
   (when-let [property (d/entity db property-id)]
     (:property/closed-values property)))
 
-(defn closed-value-name
-  "Gets name of closed value given closed value ent/map. Works for all closed value types"
+(defn closed-value-content
+  "Gets content/value of a given closed value ent/map. Works for all closed value types"
   [ent]
   (or (:block/content ent)
-      (:property/value ent)))
+      (:property.value/content ent)))
 
-(defn get-property-value-name
-  "Given an entity, gets a readable name for the property value of a ref type
-  property. Different than closed-value-name as there implementation will likely
-  differ"
+(defn property-value-content
+  "Given an entity, gets the content for the property value of a ref type
+  property i.e. what the user sees. For page types the content is the page name"
   [ent]
   (or (:block/content ent)
-      (:property/value ent)
+      (:property.value/content ent)
       (:block/original-name ent)))
 
-(defn get-property-value-name-from-ref
+(defn ref->property-value-content
   "Given a ref from a pulled query e.g. `{:db/id X}`, gets a readable name for
   the property value of a ref type property"
   [db ref]
   (some->> (:db/id ref)
            (d/entity db)
-           get-property-value-name))
+           property-value-content))
 
-(defn get-property-value-names-from-ref
+(defn ref->property-value-contents
   "Given a ref or refs from a pulled query e.g. `{:db/id X}`, gets a readable
   name for the property values of a ref type property"
   [db ref]
   (if (or (set? ref) (sequential? ref))
-    (set (map #(get-property-value-name-from-ref db %) ref))
-    (get-property-value-name-from-ref db ref)))
+    (set (map #(ref->property-value-content db %) ref))
+    (ref->property-value-content db ref)))
 
 (defn get-closed-value-entity-by-name
   "Given a property, finds one of its closed values by name or nil if none
   found. Works for all closed value types"
-  [db db-ident value-name]
+  [db db-ident value-content]
   (let [values (get-closed-property-values db db-ident)]
     (some (fn [e]
-            (when (= (closed-value-name e) value-name)
+            (when (= (closed-value-content e) value-content)
               e)) values)))
 
 (def default-user-namespace "user.property")
@@ -281,7 +280,7 @@
   (and (map? block)
        (:logseq.property/created-from-property block)
        (:block/page block)
-       (not (some? (closed-value-name block)))))
+       (not (some? (closed-value-content block)))))
 
 (defn many?
   [property]
@@ -294,5 +293,5 @@
   (->> (properties block)
        (map (fn [[k v]]
               [(:block/original-name (d/entity db k))
-               (get-property-value-names-from-ref db v)]))
+               (ref->property-value-contents db v)]))
        (into {})))

+ 2 - 2
deps/db/src/logseq/db/frontend/property/build.cljs

@@ -16,7 +16,7 @@
             :logseq.property/created-from-property property-id
             :block/parent property-id}
            (if (db-property-type/original-value-ref-property-types (get-in property [:block/schema :type]))
-             {:property/value value}
+             {:property.value/content value}
              {:block/content value}))))
 
 (defn build-closed-value-block
@@ -76,7 +76,7 @@
         :logseq.property/created-from-property (or (:db/id property) {:db/ident (:db/ident property)})
         :block/order (db-order/gen-key)}
        (if (db-property-type/original-value-ref-property-types (get-in property [:block/schema :type]))
-         {:property/value value}
+         {:property.value/content value}
          {:block/content value}))
       sqlite-util/block-with-timestamps))
 

+ 4 - 4
deps/db/src/logseq/db/frontend/property/type.cljs

@@ -30,13 +30,13 @@
 
 (def original-value-ref-property-types
   "Property value ref types where the refed entity stores its value in
-  :property/value e.g. :number is stored as a number. new value-ref-property-types
+  :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})
 
 (def value-ref-property-types
   "Property value ref types where the refed entities either store their value in
-  :property/value or block/content"
+  :property.value/content or block/content"
   (into #{:default :template}
         original-value-ref-property-types))
 
@@ -89,14 +89,14 @@
   (if new-closed-value?
     (url? val)
     (when-let [ent (d/entity db val)]
-      (url? (:property/value ent)))))
+      (url? (:property.value/content ent)))))
 
 (defn- number-entity?
   [db id-or-value {:keys [new-closed-value?]}]
   (if new-closed-value?
     (number? id-or-value)
     (when-let [entity (d/entity db id-or-value)]
-      (number? (:property/value entity)))))
+      (number? (:property.value/content entity)))))
 
 (defn- text-entity?
   [db s {:keys [new-closed-value?]}]

+ 1 - 1
deps/db/src/logseq/db/frontend/property/util.cljs

@@ -24,7 +24,7 @@
   [repo coll db-ident]
   (if (sqlite-util/db-based-graph? repo)
     (let [val (get coll db-ident)]
-      (if (built-in-has-ref-value? db-ident) (db-property/get-property-value-name val) val))
+      (if (built-in-has-ref-value? db-ident) (db-property/property-value-content val) val))
     (get coll (get-pid repo db-ident))))
 
 (defn get-block-property-value

+ 2 - 2
deps/db/src/logseq/db/frontend/rules.cljc

@@ -172,7 +172,7 @@
       [?p :block/name]
       [?p ?prop ?pv]
       (or [?pv :block/content ?val]
-          [?pv :property/value ?val]
+          [?pv :property.value/content ?val]
           [?pv :block/original-name ?val])
       [?prop-e :db/ident ?prop]
       [?prop-e :block/type "property"]]
@@ -188,7 +188,7 @@
     '[(property ?b ?prop ?val)
       [?b ?prop ?pv]
       (or [?pv :block/content ?val]
-          [?pv :property/value ?val]
+          [?pv :property.value/content ?val]
           [?pv :block/original-name ?val])
       [(missing? $ ?b :block/name)]
       [?prop-e :db/ident ?prop]

+ 1 - 1
deps/db/src/logseq/db/frontend/schema.cljs

@@ -135,7 +135,7 @@
                                   :db/cardinality :db.cardinality/many}
     :property/schema.classes {:db/valueType :db.type/ref
                               :db/cardinality :db.cardinality/many}
-    :property/value {}
+    :property.value/content {}
     :file/last-modified-at {}
     :asset/uuid {:db/unique :db.unique/identity}
     :asset/meta {}}))

+ 2 - 2
deps/db/test/logseq/db/sqlite/build_test.cljs

@@ -40,7 +40,7 @@
                           :where [?b :block/content "Jrue Holiday"]])
                 first
                 :user.property/description
-                (db-property/get-property-value-name-from-ref @conn)))
+                (db-property/ref->property-value-contents @conn)))
         "description property is created and correctly associated to a block")
 
     (is (= "Awesome selfless basketball"
@@ -49,5 +49,5 @@
                            :where [?b :block/original-name "Jayson Tatum"]])
                 first
                 :user.property/description
-                (db-property/get-property-value-name-from-ref @conn)))
+                (db-property/ref->property-value-contents @conn)))
         "description property is created and correctly associated to a page")))

+ 2 - 2
deps/outliner/src/logseq/outliner/property.cljs

@@ -426,7 +426,7 @@
                                          (assoc schema :description description)
                                          (dissoc schema :description))}
                         (if (db-property-type/original-value-ref-property-types (get-in property [:block/schema :type]))
-                          {:property/value resolved-value}
+                          {:property.value/content resolved-value}
                           {:block/content resolved-value})))
                        icon
                        (assoc :logseq.property/icon icon)))]
@@ -459,7 +459,7 @@
                               resolved-value)]
         (cond
           (some (fn [b]
-                  (and (= (str resolved-value) (str (or (db-property/closed-value-name b)
+                  (and (= (str resolved-value) (str (or (db-property/closed-value-content b)
                                                         (:block/uuid b))))
                        (not= id (:block/uuid b))))
                 (:property/closed-values property))

+ 1 - 1
deps/publishing/src/logseq/publishing/db.cljs

@@ -14,7 +14,7 @@
   (when-some [props (and block page (:block/properties block))]
     ;; Can't use db-property-util/lookup b/c repo isn't available
     (let [prop-lookup-fn (if (entity-plus/db-based-graph? db)
-                           #(db-property/get-property-value-name (get %1 %2))
+                           #(db-property/property-value-content (get %1 %2))
                            #(get %1 (keyword (name %2))))]
       (when-some [uuid (:block/uuid block)]
         (when-some [stamp (prop-lookup-fn props :logseq.property.pdf/hl-stamp)]

+ 1 - 1
scripts/src/logseq/tasks/db_graph/create_graph_with_schema_org.cljs

@@ -374,7 +374,7 @@
                                        (assoc :block/properties (-> (update-keys props name)
                                                                     (update-vals (fn [v]
                                                                                    (if (:db/id v)
-                                                                                     (db-property/get-property-value-name (d/entity db (:db/id v)))
+                                                                                     (db-property/property-value-content (d/entity db (:db/id v)))
                                                                                      v)))))
                                        (seq (:class/schema.properties m))
                                        (update :class/schema.properties #(set (map :block/original-name %)))

+ 3 - 3
src/main/frontend/components/property/closed_value.cljs

@@ -61,7 +61,7 @@
   shortcut/disable-all-shortcuts
   {:init (fn [state]
            (let [block (second (:rum/args state))
-                 value (or (str (db-property/closed-value-name block)) "")
+                 value (or (str (db-property/closed-value-content block)) "")
                  icon (:logseq.property/icon block)
                  description (or (get-in block [:block/schema :description]) "")]
              (assoc state
@@ -116,7 +116,7 @@
   (rum/local false ::hover?)
   [state item {:keys [toggle-fn delete-choice update-icon]} parent-opts]
   (let [*hover? (::hover? state)
-        value (db-property/closed-value-name item)
+        value (db-property/closed-value-content item)
         page? (:block/original-name item)
         property-block? (db-property/property-created-block? item)]
     [:div.flex.flex-1.flex-row.items-center.gap-2.justify-between
@@ -186,7 +186,7 @@
     (for [value values]
       [:li (if (uuid? value)
              (let [result (db/entity [:block/uuid value])]
-               (db-property/closed-value-name result))
+               (db-property/closed-value-content result))
              (str value))])]
    (ui/button
     "Add choices"

+ 5 - 5
src/main/frontend/components/property/value.cljs

@@ -439,7 +439,7 @@
             items (if closed-values?
                     (keep (fn [block]
                             (let [icon (pu/get-block-property-value block :logseq.property/icon)
-                                  value (db-property/closed-value-name block)]
+                                  value (db-property/closed-value-content block)]
                               {:label (if icon
                                         [:div.flex.flex-row.gap-2
                                          (icon-component/icon icon)
@@ -454,7 +454,7 @@
                          (map (fn [{:keys [value]}]
                                 (if (and ref-type? (number? value))
                                   (when-let [e (db/entity value)]
-                                    {:label (db-property/get-property-value-name e)
+                                    {:label (db-property/property-value-content e)
                                      :value value})
                                   {:label value
                                    :value value})))
@@ -584,7 +584,7 @@
     (let [eid (if (de/entity? value) (:db/id value) [:block/uuid value])]
       (when-let [block (db/sub-block (:db/id (db/entity eid)))]
         (let [property-block? (db-property/property-created-block? block)
-              value' (db-property/closed-value-name block)
+              value' (db-property/closed-value-content block)
               icon (pu/get-block-property-value block :logseq.property/icon)]
           (cond
             icon
@@ -638,9 +638,9 @@
        (closed-value-item value opts)
 
        (de/entity? value)
-       (when-some [content (if (some? (:property/value value))
+       (when-some [content (if (some? (:property.value/content value))
                              ;; content needs to be a string for display purposes
-                             (str (:property/value value))
+                             (str (:property.value/content value))
                              (:block/content value))]
          (inline-text-cp content))
 

+ 1 - 1
src/main/frontend/components/query/builder.cljs

@@ -168,7 +168,7 @@
           _ (when db-graph?
               (doseq [id values] (db/sub-block id)))
           values' (if db-graph?
-                   (map #(db-property/get-property-value-name (db/entity repo %)) values)
+                   (map #(db-property/property-value-content (db/entity repo %)) values)
                    values)
           values'' (cons "Select all" values')]
       (select values''

+ 1 - 1
src/main/frontend/components/query_table.cljs

@@ -182,7 +182,7 @@
 
     [:string
      (if db-graph?
-       (db-property/get-property-value-names-from-ref db (get row column))
+       (db-property/ref->property-value-contents db (get row column))
        (if comma-separated-property?
          ;; Return original properties since comma properties need to
          ;; return collections for display purposes

+ 1 - 1
src/main/frontend/db/async.cljs

@@ -107,7 +107,7 @@
                          [(not= ?vid :logseq.property/empty-placeholder)]
                          (or
                           [?vid :block/content ?value]
-                          [?vid :property/value ?value]
+                          [?vid :property.value/content ?value]
                           [?vid :block/original-name ?value])]
                        property-id
                        value)]

+ 2 - 2
src/main/frontend/handler/common/developer.cljs

@@ -26,9 +26,9 @@
                                     [k
                                      (cond
                                        (de/entity? v)
-                                       (db-property/get-property-value-name v)
+                                       (db-property/property-value-content v)
                                        (and (set? v) (every? de/entity? v))
-                                       (set (map db-property/get-property-value-name v))
+                                       (set (map db-property/property-value-content v))
                                        :else
                                        v)]))
                              (into {})))

+ 2 - 2
src/main/frontend/handler/db_based/property/util.cljs

@@ -14,7 +14,7 @@
   "Get a property's name given its id"
   [e]
   (if-let [e (if (number? e) (db-utils/pull e) e)]
-    (db-property/get-property-value-name e)
+    (db-property/property-value-content e)
     e))
 
 (defn properties-by-name
@@ -41,7 +41,7 @@
               [(if original-key? k (-> prop-ent :block/original-name keyword))
                (cond
                  (set? v)
-                 (set (map db-property/get-property-value-name v))
+                 (set (map db-property/property-value-content v))
 
                  (sequential? v)
                  (map #(get-property-value (or (:db/id %) %)) v)

+ 7 - 7
src/test/frontend/handler/db_based/property_test.cljs

@@ -77,7 +77,7 @@
         2
         (every? keyword? (map first properties))
         true
-        (db-property/get-property-value-name (second (second properties)))
+        (db-property/property-value-content (second (second properties)))
         1)))
 
   (testing "Update property value"
@@ -89,7 +89,7 @@
       (are [x y] (= x y)
         (count properties)
         2
-        (db-property/get-property-value-name (second (second properties)))
+        (db-property/property-value-content (second (second properties)))
         2)))
 
   (testing "Wrong type property value shouldn't transacted"
@@ -105,7 +105,7 @@
       (are [x y] (= x y)
         (count properties)
         2
-        (db-property/get-property-value-name (second (second properties)))
+        (db-property/property-value-content (second (second properties)))
         2)))
 
   (testing "Add a multi-values property"
@@ -129,7 +129,7 @@
           3
           (count properties)
           #{1 2 3}
-          (set (map db-property/get-property-value-name (get properties :user.property/property-3)))))))
+          (set (map db-property/property-value-content (get properties :user.property/property-3)))))))
 
   (testing "Remove a property"
     (outliner-property/remove-block-property! (db/get-db false) fbid :user.property/property-3)
@@ -273,7 +273,7 @@
 (defn- get-closed-values
   "Get value from block ids"
   [values]
-  (set (map #(db-property/closed-value-name (db/entity [:block/uuid %])) values)))
+  (set (map #(db-property/closed-value-content (db/entity [:block/uuid %])) values)))
 
 ;; closed values related
 ;; upsert-closed-value
@@ -314,7 +314,7 @@
 
       (testing "Add new value"
         (let [_ (outliner-property/upsert-closed-value! conn (:db/id property) {:value 3})
-              b (first (d/q '[:find [(pull ?b [*]) ...] :where [?b :property/value 3]] @conn))]
+              b (first (d/q '[:find [(pull ?b [*]) ...] :where [?b :property.value/content 3]] @conn))]
           (is (contains? (set (:block/type b)) "closed value"))
           (let [values (get-value-ids k)]
             (is (= #{1 2 3}
@@ -326,7 +326,7 @@
                                                                                     :value 4
                                                                                     :description "choice 4"})
                   b (db/entity [:block/uuid block-id])]
-              (is (= 4 (db-property/closed-value-name b)))
+              (is (= 4 (db-property/closed-value-content b)))
               (is (= "choice 4" (:description (:block/schema b))))
               (is (contains? (:block/type b) "closed value"))
               (outliner-property/delete-closed-value! conn (:db/id property) (:db/id (db/entity [:block/uuid block-id])))