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

fix: markdown tables didn't recognize built-in v2 properties

also fix enum values not usable for api fn
Gabriel Horner 2 лет назад
Родитель
Сommit
2c1ccf99dc

+ 4 - 2
src/main/frontend/components/block.cljs

@@ -3165,8 +3165,10 @@
 (defn table
   [config {:keys [header groups col_groups]}]
   (case (get-shui-component-version :table config)
-    2 (shui/table-v2 {:data (concat [[header]] groups)}
-                     (make-shui-context config inline))
+    2 (let [v2-config (assoc-in config [:block :properties]
+                                (pu/readable-properties (get-in config [:block :block/properties])))]
+        (shui/table-v2 {:data (concat [[header]] groups)}
+                       (make-shui-context v2-config inline)))
     1 (let [tr (fn [elm cols]
                  (->elem
                   :tr

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

@@ -298,16 +298,7 @@
       (case table-version
         2 (let [v2-columns (mapv #(if (uuid? %) (pu/get-property-name %) %) columns)
                 v2-config (assoc-in config [:block :properties]
-                                    (->> (get-in config [:block :block/properties])
-                                         (map (fn [[k v]]
-                                                (let [prop-ent (db/entity [:block/uuid k])]
-                                                  [(-> prop-ent
-                                                      :block/name
-                                                      keyword)
-                                                  (if (= :enum (get-in prop-ent [:block/schema :type]))
-                                                    (pu/enum-value prop-ent v)
-                                                    v)])))
-                                         (into {})))
+                                (pu/readable-properties (get-in config [:block :block/properties])))
                 result-as-text (for [row result]
                                  (for [column columns]
                                    (build-column-text row column)))]

+ 17 - 1
src/main/frontend/handler/property/util.cljs

@@ -65,4 +65,20 @@
 (defn enum-value
   "Given an enum ent and the value's uuid, return the value's string"
   [ent value-uuid]
-  (get-in ent [:block/schema :enum-config :values value-uuid :name]))
+  (get-in ent [:block/schema :enum-config :values value-uuid :name]))
+
+(defn readable-properties
+  "Given a DB graph's properties, returns a readable properties map with keys as
+  property names and property values dereferenced where possible. A property's
+  value will only be a uuid if it's a page or a block"
+  [properties]
+  (->> properties
+       (map (fn [[k v]]
+              (let [prop-ent (db/entity [:block/uuid k])]
+                [(-> prop-ent
+                     :block/name
+                     keyword)
+                 (if (= :enum (get-in prop-ent [:block/schema :type]))
+                   (enum-value prop-ent v)
+                   v)])))
+       (into {})))

+ 1 - 1
src/main/logseq/api.cljs

@@ -748,7 +748,7 @@
   (fn [block-uuid]
     (when-let [block (db-model/query-block-by-uuid (sdk-utils/uuid-or-throw-error block-uuid))]
       (let [properties (if (config/db-based-graph? (state/get-current-repo))
-                         (update-keys (:block/properties block) pu/get-property-name)
+                         (pu/readable-properties (:block/properties block))
                          (:block/properties block))]
         (bean/->js (sdk-utils/normalize-keyword-for-json properties))))))