Răsfoiți Sursa

enhance: provide a built-in description property

that is used by properties and closed values and can easily be used by
other blocks. Also removes :block/schema for closed values and schema
:description for properties which helps get away from data modeling debt
of :block/schema
Gabriel Horner 1 an în urmă
părinte
comite
eb63add1f0

+ 2 - 6
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)))
 

+ 4 - 0
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

+ 3 - 6
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)))))

+ 27 - 24
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"

+ 1 - 1
deps/outliner/test/logseq/outliner/property_test.cljs

@@ -256,7 +256,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)

+ 16 - 4
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/<get-block-property-values (state/get-current-repo)
@@ -248,6 +249,7 @@
                  (let [[property _opts] (:rum/args state)]
                    (reset! (::property-name state) (:block/title property))
                    (reset! (::property-schema state) (:block/schema property))
+                   (reset! (::property-description state) (db-property/property-value-content (:logseq.property/description property)))
                    (state/set-state! :editor/property-configure? true)
                    state))
    :will-unmount (fn [state]
@@ -260,6 +262,7 @@
     (when-not (= :loading values)
       (let [*property-name (::property-name state)
             *property-schema (::property-schema state)
+            *property-description (::property-description state)
             property (db/sub-block (:db/id property))
             built-in? (ldb/built-in? property)
             disabled? (or built-in? config/publishing?)
@@ -391,15 +394,24 @@
                                     (swap! *property-schema assoc :hide? (not hide?))
                                     (save-property-fn))})])
 
-          (let [description (or (:description @*property-schema) "")]
+          (let [description (or @*property-description "")]
             [:div.grid.grid-cols-5.gap-1.items-start.leading-8
              [:label.col-span-2 "Description:"]
              [:div.col-span-3
               [:div.mt-1
                (shui/textarea
                 {:on-change (fn [e]
-                              (swap! *property-schema assoc :description (util/evalue e)))
-                 :on-blur save-property-fn
+                              (reset! *property-description (util/evalue e)))
+                 :on-blur (fn []
+                            (if-let [ent (:logseq.property/description property)]
+                              (db/transact! (state/get-current-repo)
+                                            [(outliner-core/block-with-updated-at
+                                              {:db/id (:db/id ent) :block/title @*property-description})]
+                                            {:outliner-op :save-block})
+                              (db-property-handler/set-block-property!
+                               (:db/id property)
+                               :logseq.property/description
+                               @*property-description)))
                  :disabled disabled?
                  :default-value description})]]])]]))))
 
@@ -716,7 +728,7 @@
           [:div.flex.flex-1
            (if (and (:class-schema? opts) (:page-configure? opts))
              [:div.property-description.text-sm.opacity-70
-              (inline-text {} :markdown (get-in property [:block/schema :description]))]
+              (inline-text {} :markdown (db-property/property-value-content (:logseq.property/description property)))]
              [:div.property-value.flex.flex-1
               (pv/property-value block property v opts)])]]]))))
 

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

@@ -63,7 +63,7 @@
            (let [block (second (:rum/args state))
                  value (or (str (db-property/closed-value-content block)) "")
                  icon (:logseq.property/icon block)
-                 description (or (get-in block [:block/schema :description]) "")]
+                 description (or (db-property/property-value-content (:logseq.property/description block)) "")]
              (assoc state
                     ::value (atom value)
                     ::icon (atom icon)