diff --git a/deps/db/src/logseq/db/frontend/malli_schema.cljs b/deps/db/src/logseq/db/frontend/malli_schema.cljs index afe376064..cb0f9bea9 100644 --- a/deps/db/src/logseq/db/frontend/malli_schema.cljs +++ b/deps/db/src/logseq/db/frontend/malli_schema.cljs @@ -264,8 +264,7 @@ (def property-common-schema-attrs "Property :schema attributes common to all properties" - [[:hide? {:optional true} :boolean] - [:description {:optional true} :string]]) + [[:hide? {:optional true} :boolean]]) (def internal-property (vec @@ -371,10 +370,7 @@ [:db/ident {:optional true} logseq-property-ident] [:block/title {:optional true} :string] [:property.value/content {:optional true} [:or :string :double]] - [:block/closed-value-property {:optional true} [:set :int]] - [:block/schema {:optional true} - [:map - [:description {:optional true} :string]]]] + [:block/closed-value-property {:optional true} [:set :int]] ] (remove #(#{:block/title} (first %)) block-attrs) page-or-block-attrs))) diff --git a/deps/db/src/logseq/db/frontend/property.cljs b/deps/db/src/logseq/db/frontend/property.cljs index c213af9e6..ac68b53a0 100644 --- a/deps/db/src/logseq/db/frontend/property.cljs +++ b/deps/db/src/logseq/db/frontend/property.cljs @@ -150,6 +150,10 @@ :hide? true :view-context :page :public? true}} + :logseq.property/description {:schema + {:type :default + :public? true}} + :logseq.property.table/sorting {:schema {:type :coll :hide? true diff --git a/deps/db/src/logseq/db/frontend/property/build.cljs b/deps/db/src/logseq/db/frontend/property/build.cljs index 7b8a4d241..383113054 100644 --- a/deps/db/src/logseq/db/frontend/property/build.cljs +++ b/deps/db/src/logseq/db/frontend/property/build.cljs @@ -21,7 +21,7 @@ (defn build-closed-value-block "Builds a closed value block to be transacted" - [block-uuid block-value property {:keys [db-ident icon description]}] + [block-uuid block-value property {:keys [db-ident icon]}] (assert block-uuid (uuid? block-uuid)) (cond-> (closed-value-new-block block-uuid block-value property) @@ -31,9 +31,6 @@ icon (assoc :logseq.property/icon icon) - description - (update :block/schema assoc :description description) - true sqlite-util/block-with-timestamps)) @@ -46,13 +43,13 @@ :ref-type? true}) property-attributes)] (into [property-tx] - (map (fn [{:keys [db-ident value icon description uuid]}] + (map (fn [{:keys [db-ident value icon uuid]}] (cond-> (build-closed-value-block uuid value property - {:db-ident db-ident :icon icon :description description}) + {:db-ident db-ident :icon icon}) true (assoc :block/order (db-order/gen-key)))) (:closed-values property))))) diff --git a/deps/db/src/logseq/db/sqlite/common_db.cljs b/deps/db/src/logseq/db/sqlite/common_db.cljs index 8a6fb4c3e..b7168d9ca 100644 --- a/deps/db/src/logseq/db/sqlite/common_db.cljs +++ b/deps/db/src/logseq/db/sqlite/common_db.cljs @@ -82,34 +82,32 @@ (defn- property-with-values [db block] (when (entity-plus/db-based-graph? db) - (let [block (d/entity db (:db/id block)) - block-properties (when (seq (:block/properties block)) - (mapcat - (fn [[_property-id property-values]] - (let [values (if (and (coll? property-values) - (map? (first property-values))) - property-values - #{property-values}) - value-ids (when (every? map? values) - (->> (map :db/id values) - (filter (fn [id] (or (int? id) (keyword? id)))))) - value-blocks (->> - (when (seq value-ids) - (map - (fn [id] (d/pull db '[*] id)) - value-ids)) - ;; FIXME: why d/pull returns {:db/id db-ident} instead of {:db/id number-eid}? - (map (fn [block] - (let [from-property-id (get-in block [:logseq.property/created-from-property :db/id])] - (if (keyword? from-property-id) - (assoc-in block [:logseq.property/created-from-property :db/id] (:db/id (d/entity db from-property-id))) - block))))) - page (when (seq values) - (when-let [page-id (:db/id (:block/page (d/entity db (:db/id (first values)))))] - (d/pull db '[*] page-id)))] - (remove nil? (concat [page] value-blocks)))) - (:block/properties block)))] - block-properties))) + (let [block (d/entity db (:db/id block))] + (->> (:block/properties block) + vals + (mapcat + (fn [property-values] + (let [values (->> + (if (and (coll? property-values) + (map? (first property-values))) + property-values + #{property-values}) + (remove sqlite-util/page?)) + value-ids (when (every? map? values) + (->> (map :db/id values) + (filter (fn [id] (or (int? id) (keyword? id)))))) + value-blocks (->> + (when (seq value-ids) + (map + (fn [id] (d/pull db '[*] id)) + value-ids)) + ;; FIXME: why d/pull returns {:db/id db-ident} instead of {:db/id number-eid}? + (keep (fn [block] + (let [from-property-id (get-in block [:logseq.property/created-from-property :db/id])] + (if (keyword? from-property-id) + (assoc-in block [:logseq.property/created-from-property :db/id] (:db/id (d/entity db from-property-id))) + block)))))] + value-blocks))))))) (defn get-block-children-ids "Returns children UUIDs" diff --git a/deps/outliner/src/logseq/outliner/property.cljs b/deps/outliner/src/logseq/outliner/property.cljs index 18594a6c7..4edda32f8 100644 --- a/deps/outliner/src/logseq/outliner/property.cljs +++ b/deps/outliner/src/logseq/outliner/property.cljs @@ -397,32 +397,24 @@ (seq properties)))) (defn- build-closed-value-tx - [db property resolved-value {:keys [id icon description] - :or {description ""}}] + [db property resolved-value {:keys [id icon]}] (let [block (when id (d/entity db [:block/uuid id])) block-id (or id (ldb/new-block-id)) icon (when-not (and (string? icon) (string/blank? icon)) icon) - description (string/trim description) - description (when-not (string/blank? description) description) tx-data (if block - [(let [schema (:block/schema block)] - (cond-> - (outliner-core/block-with-updated-at - (merge - {:block/uuid id - :block/closed-value-property (:db/id property) - :block/schema (if description - (assoc schema :description description) - (dissoc schema :description))} - (if (db-property-type/original-value-ref-property-types (get-in property [:block/schema :type])) - {:property.value/content resolved-value} - {:block/title resolved-value}))) - icon - (assoc :logseq.property/icon icon)))] + [(cond-> + (outliner-core/block-with-updated-at + (merge + {:block/uuid id + :block/closed-value-property (:db/id property)} + (if (db-property-type/original-value-ref-property-types (get-in property [:block/schema :type])) + {:property.value/content resolved-value} + {:block/title resolved-value}))) + icon + (assoc :logseq.property/icon icon))] (let [max-order (:block/order (last (:property/closed-values property))) new-block (-> (db-property-build/build-closed-value-block block-id resolved-value - property {:icon icon - :description description}) + property {:icon icon}) (assoc :block/order (db-order/gen-key max-order nil)))] [new-block (outliner-core/block-with-updated-at @@ -434,7 +426,7 @@ (defn upsert-closed-value! "id should be a block UUID or nil" - [conn property-id {:keys [id value] :as opts}] + [conn property-id {:keys [id value description] :as opts}] (assert (or (nil? id) (uuid? id))) (let [db @conn property (d/entity db property-id) @@ -472,9 +464,20 @@ nil :else - (ldb/transact! conn - (build-closed-value-tx @conn property resolved-value opts) - {:outliner-op :save-block})))))) + (let [tx-data (build-closed-value-tx @conn property resolved-value opts)] + (ldb/transact! conn tx-data {:outliner-op :save-block}) + + (when (seq description) + (if-let [desc-ent (and id (:logseq.property/description (d/entity db [:block/uuid id])))] + (ldb/transact! conn + [(outliner-core/block-with-updated-at {:db/id (:db/id desc-ent) + :block/title description})] + {:outliner-op :save-block}) + (set-block-property! conn + ;; new closed value is first in tx-data + [:block/uuid (or id (:block/uuid (first tx-data)))] + :logseq.property/description + description))))))))) (defn add-existing-values-to-closed-values! "Adds existing values as closed values and returns their new block uuids" diff --git a/deps/outliner/test/logseq/outliner/property_test.cljs b/deps/outliner/test/logseq/outliner/property_test.cljs index 119ecfcdb..8f0308226 100644 --- a/deps/outliner/test/logseq/outliner/property_test.cljs +++ b/deps/outliner/test/logseq/outliner/property_test.cljs @@ -255,7 +255,7 @@ :description "choice 4"}) updated-b (d/entity @conn [:block/uuid (:block/uuid b)])] (is (= 4 (db-property/closed-value-content updated-b))) - (is (= "choice 4" (:description (:block/schema updated-b)))))))) + (is (= "choice 4" (db-property/property-value-content (:logseq.property/description updated-b)))))))) (deftest delete-closed-value! (let [closed-value-uuid (random-uuid) 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 b2c9f8929..afcd86499 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 @@ -65,7 +65,7 @@ (cond-> {:block/title class-name :build/properties (cond-> {:url url} (class-m "rdfs:comment") - (assoc :description (get-comment-string (class-m "rdfs:comment") renamed-pages)))} + (assoc :logseq.property/description (get-comment-string (class-m "rdfs:comment") renamed-pages)))} parent-class' (assoc :build/class-parent (keyword (strip-schema-prefix parent-class'))) (seq properties) @@ -117,12 +117,12 @@ schema (cond-> {:type schema-type} ;; This cardinality rule should be adjusted as we use schema.org more (= schema-type :node) - (assoc :cardinality :many) - (property-m "rdfs:comment") - (assoc :description (get-comment-string (property-m "rdfs:comment") renamed-pages)))] + (assoc :cardinality :many))] {(keyword (strip-schema-prefix (property-m "@id"))) (cond-> {:block/schema schema - :build/properties {:url url}} + :build/properties (cond-> {:url url} + (property-m "rdfs:comment") + (assoc :logseq.property/description (get-comment-string (property-m "rdfs:comment") renamed-pages)))} (= schema-type :node) (assoc :build/schema-classes (mapv (comp keyword strip-schema-prefix) range-includes)))})) @@ -256,8 +256,13 @@ (get-schema-type (get-range-includes property-m) class-map))) frequencies) "\n")) - (apply merge - (mapv #(->property-page % class-map options) select-properties))) + (assoc + (apply merge + (mapv #(->property-page % class-map options) select-properties)) + ;; Have to update schema for now as validation doesn't take into account existing properties + :logseq.property/description {:block/schema {:public? true :type :default} + :build/properties {:url "https://schema.org/description" + :logseq.property/description "A description of the item."}})) (defn- get-all-classes-and-properties "Get all classes and properties from raw json file" @@ -267,7 +272,8 @@ (if (string? type') [type'] type'))) "rdfs:Class") schema-data) - all-properties* (get-all-properties schema-data options) + ;; Use built-in description + all-properties* (remove #(= "schema:description" (% "@id")) (get-all-properties schema-data options)) property-tuples (map #(vector (% "@id") :property) all-properties*) class-tuples (map #(vector (% "@id") :class) all-classes*) page-tuples (map #(vector (str "schema:" %) :node) existing-pages) @@ -276,6 +282,7 @@ renamed-properties (detect-property-conflicts-and-get-renamed-properties property-tuples page-tuples options) renamed-pages (merge renamed-classes renamed-properties) + ;; Note: schema:description refs don't get renamed but they aren't used ;; Updates keys like @id, @subClassOf rename-page-ids (fn [m] (w/postwalk (fn [x] diff --git a/src/main/frontend/components/property.cljs b/src/main/frontend/components/property.cljs index 4294aa4ca..9f93b3a18 100644 --- a/src/main/frontend/components/property.cljs +++ b/src/main/frontend/components/property.cljs @@ -238,6 +238,7 @@ db-mixins/query (rum/local nil ::property-name) (rum/local nil ::property-schema) + (rum/local nil ::property-description) {:init (fn [state] (let [*values (atom :loading)] (p/let [result (db-async/