From 244a86557faba831e555c68bed2dcce18bb22c07 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Fri, 14 Jun 2024 18:11:20 -0400 Subject: [PATCH] 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 --- .../src/logseq/db/frontend/malli_schema.cljs | 10 +++--- deps/db/src/logseq/db/frontend/property.cljs | 33 +++++++++---------- .../logseq/db/frontend/property/build.cljs | 4 +-- .../src/logseq/db/frontend/property/type.cljs | 8 ++--- .../src/logseq/db/frontend/property/util.cljs | 2 +- deps/db/src/logseq/db/frontend/rules.cljc | 4 +-- deps/db/src/logseq/db/frontend/schema.cljs | 2 +- deps/db/test/logseq/db/sqlite/build_test.cljs | 4 +-- .../src/logseq/outliner/property.cljs | 4 +-- deps/publishing/src/logseq/publishing/db.cljs | 2 +- .../create_graph_with_schema_org.cljs | 2 +- .../components/property/closed_value.cljs | 6 ++-- .../frontend/components/property/value.cljs | 10 +++--- .../frontend/components/query/builder.cljs | 2 +- src/main/frontend/components/query_table.cljs | 2 +- src/main/frontend/db/async.cljs | 2 +- .../frontend/handler/common/developer.cljs | 4 +-- .../handler/db_based/property/util.cljs | 4 +-- .../handler/db_based/property_test.cljs | 14 ++++---- 19 files changed, 59 insertions(+), 60 deletions(-) diff --git a/deps/db/src/logseq/db/frontend/malli_schema.cljs b/deps/db/src/logseq/db/frontend/malli_schema.cljs index fc68e591d..dde615021 100644 --- a/deps/db/src/logseq/db/frontend/malli_schema.cljs +++ b/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" diff --git a/deps/db/src/logseq/db/frontend/property.cljs b/deps/db/src/logseq/db/frontend/property.cljs index d36982b91..d9ccf883e 100644 --- a/deps/db/src/logseq/db/frontend/property.cljs +++ b/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 {}))) \ No newline at end of file diff --git a/deps/db/src/logseq/db/frontend/property/build.cljs b/deps/db/src/logseq/db/frontend/property/build.cljs index 76b4df886..156e7c88e 100644 --- a/deps/db/src/logseq/db/frontend/property/build.cljs +++ b/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)) diff --git a/deps/db/src/logseq/db/frontend/property/type.cljs b/deps/db/src/logseq/db/frontend/property/type.cljs index 99682dd84..dfe1b14bf 100644 --- a/deps/db/src/logseq/db/frontend/property/type.cljs +++ b/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?]}] diff --git a/deps/db/src/logseq/db/frontend/property/util.cljs b/deps/db/src/logseq/db/frontend/property/util.cljs index 0d4891368..58413b650 100644 --- a/deps/db/src/logseq/db/frontend/property/util.cljs +++ b/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 diff --git a/deps/db/src/logseq/db/frontend/rules.cljc b/deps/db/src/logseq/db/frontend/rules.cljc index b800b242f..cbffa15b9 100644 --- a/deps/db/src/logseq/db/frontend/rules.cljc +++ b/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] diff --git a/deps/db/src/logseq/db/frontend/schema.cljs b/deps/db/src/logseq/db/frontend/schema.cljs index 74173b48b..29cb3da01 100644 --- a/deps/db/src/logseq/db/frontend/schema.cljs +++ b/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 {}})) diff --git a/deps/db/test/logseq/db/sqlite/build_test.cljs b/deps/db/test/logseq/db/sqlite/build_test.cljs index 6b97c61ba..7eecf5eaf 100644 --- a/deps/db/test/logseq/db/sqlite/build_test.cljs +++ b/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"))) \ No newline at end of file diff --git a/deps/outliner/src/logseq/outliner/property.cljs b/deps/outliner/src/logseq/outliner/property.cljs index b03ef4c7d..82f69ed44 100644 --- a/deps/outliner/src/logseq/outliner/property.cljs +++ b/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)) diff --git a/deps/publishing/src/logseq/publishing/db.cljs b/deps/publishing/src/logseq/publishing/db.cljs index 1d67a20d1..888c95f8d 100644 --- a/deps/publishing/src/logseq/publishing/db.cljs +++ b/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)] diff --git a/scripts/src/logseq/tasks/db_graph/create_graph_with_schema_org.cljs b/scripts/src/logseq/tasks/db_graph/create_graph_with_schema_org.cljs index 82efd84c4..342d17d45 100644 --- a/scripts/src/logseq/tasks/db_graph/create_graph_with_schema_org.cljs +++ b/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 %))) diff --git a/src/main/frontend/components/property/closed_value.cljs b/src/main/frontend/components/property/closed_value.cljs index fd8b0c6e2..a7eec3c72 100644 --- a/src/main/frontend/components/property/closed_value.cljs +++ b/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" diff --git a/src/main/frontend/components/property/value.cljs b/src/main/frontend/components/property/value.cljs index 5f6b90a00..30a190f5e 100644 --- a/src/main/frontend/components/property/value.cljs +++ b/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)) diff --git a/src/main/frontend/components/query/builder.cljs b/src/main/frontend/components/query/builder.cljs index 798660ba0..fa3a66cda 100644 --- a/src/main/frontend/components/query/builder.cljs +++ b/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'' diff --git a/src/main/frontend/components/query_table.cljs b/src/main/frontend/components/query_table.cljs index b84bb4526..25ce723a6 100644 --- a/src/main/frontend/components/query_table.cljs +++ b/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 diff --git a/src/main/frontend/db/async.cljs b/src/main/frontend/db/async.cljs index cef28e3c0..5a05a1f66 100644 --- a/src/main/frontend/db/async.cljs +++ b/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)] diff --git a/src/main/frontend/handler/common/developer.cljs b/src/main/frontend/handler/common/developer.cljs index be85d1262..3c12e6c25 100644 --- a/src/main/frontend/handler/common/developer.cljs +++ b/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 {}))) diff --git a/src/main/frontend/handler/db_based/property/util.cljs b/src/main/frontend/handler/db_based/property/util.cljs index d7d0d0dc9..be1081db3 100644 --- a/src/main/frontend/handler/db_based/property/util.cljs +++ b/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) diff --git a/src/test/frontend/handler/db_based/property_test.cljs b/src/test/frontend/handler/db_based/property_test.cljs index dd66a02d0..141006221 100644 --- a/src/test/frontend/handler/db_based/property_test.cljs +++ b/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])))