Browse Source

fix: query table rows should show page ref names

instead of special ids. Also tweaked page delete message to
remove needless contraction
Gabriel Horner 1 year ago
parent
commit
429b257ee9

+ 16 - 0
deps/db/src/logseq/db/frontend/content.cljs

@@ -45,6 +45,22 @@
    content
    refs))
 
+(defn special-id-ref->page-ref
+  "Convert special id ref backs to page name refs using refs."
+  [content refs]
+  (reduce
+   (fn [content ref]
+     (if (:block/name ref)
+       (string/replace content
+                       (str page-ref/left-brackets
+                            page-ref-special-chars
+                            (:block/uuid ref)
+                            page-ref/right-brackets)
+                       (page-ref/->page-ref (:block/original-name ref)))
+       content))
+   content
+   refs))
+
 (defn db-special-id-ref->page
   "Convert special id ref backs to page name using `db`."
   [db content]

+ 15 - 4
src/main/frontend/components/query_table.cljs

@@ -20,7 +20,8 @@
             [logseq.graph-parser.text :as text]
             [logseq.db.frontend.property :as db-property]
             [frontend.handler.property.util :as pu]
-            [frontend.handler.db-based.property.util :as db-pu]))
+            [frontend.handler.db-based.property.util :as db-pu]
+            [logseq.db.frontend.content :as db-content]))
 
 ;; Util fns
 ;; ========
@@ -288,13 +289,23 @@
 (rum/defc result-table < rum/reactive
   [config current-block result {:keys [page?] :as options} map-inline page-cp ->elem inline-text inline]
   (when current-block
-    (let [result' (if page? result (attach-clock-property result))
+    (let [db-graph? (config/db-based-graph? (state/get-current-repo))
+          result' (cond-> (if page? result (attach-clock-property result))
+                    db-graph?
+                    ((fn [res]
+                       (map #(if (:block/content %)
+                               (update % :block/content
+                                       db-content/special-id-ref->page-ref
+                                       ;; Lookup here instead of initial query as advanced queries
+                                       ;; won't usually have a ref's name
+                                       (map (fn [m] (db/entity (:db/id m))) (:block/refs %)))
+                               %)
+                            res))))
           columns (get-columns current-block result' {:page? page?})
-          db-graph? (config/db-based-graph? (state/get-current-repo))
           ;; Sort state needs to be in sync between final result and sortable title
           ;; as user needs to know if there result is sorted
           sort-state (get-sort-state current-block {:db-graph? db-graph?})
-          sort-result (sort-result result (assoc sort-state :page? page?))
+          sort-result (sort-result result' (assoc sort-state :page? page?))
           table-version (get-shui-component-version :table config)]
       (case table-version
         2 (let [v2-columns (mapv #(if (uuid? %) (db-pu/get-property-name %) %) columns)

+ 1 - 1
src/main/frontend/worker/handler/page.cljs

@@ -190,7 +190,7 @@
             {:msg "Page content deleted but unable to delete this page because blocks use this property"})
 
       (or (seq (:block/_refs page)) (contains? (:block/type page) "hidden"))
-      {:msg "Page content deleted but unable to delete this page because there're still references to it"})
+      {:msg "Page content deleted but unable to delete this page because there are still references to it"})
 
     (catch :default e
       (js/console.error e)