Ver código fonte

fix: named blocks and function macro

Had to update properties queries. Also loosened pu/lookup so that
user properties can use it
Gabriel Horner 2 anos atrás
pai
commit
b2802e9a54

+ 13 - 4
src/main/frontend/components/block/macros.cljs

@@ -3,8 +3,13 @@
   (:require [clojure.walk :as walk]
             [frontend.extensions.sci :as sci]
             [frontend.handler.common :as common-handler]
+            [frontend.handler.property.util :as pu]
+            [frontend.db :as db]
+            [frontend.state :as state]
+            [logseq.graph-parser.util :as gp-util]
             [goog.string :as gstring]
-            [goog.string.format]))
+            [goog.string.format]
+            [frontend.config :as config]))
 
 (defn- normalize-query-function
   [ast result]
@@ -41,10 +46,14 @@
            :updated-at
            :block/updated-at
 
-           (let [vals (map #(get-in % [:block/properties f]) result)
-                 int? (some integer? vals)]
+           (let [vals (map #(pu/lookup (:block/properties %) f) result)
+                 int? (some integer? vals)
+                 repo (state/get-current-repo)
+                 prop-key (if (config/db-based-graph? repo)
+                            (:block/uuid (db/entity repo [:block/name (gp-util/page-name-sanity-lc (name f))]))
+                            f)]
              `(~'fn [~'b]
-                    (~'let [~'result-str (~'get-in ~'b [:block/properties ~f])
+                    (~'let [~'result-str (~'get-in ~'b [:block/properties ~prop-key])
                             ~'result-num (~'parseFloat ~'result-str)
                             ~'result (if (~'isNaN ~'result-num) ~'result-str ~'result-num)]
                            (~'or ~'result (~'when ~int? 0))))))

+ 25 - 10
src/main/frontend/db/model.cljs

@@ -24,7 +24,8 @@
             [cljs-time.core :as t]
             [cljs-time.format :as tf]
             ;; add map ops to datascript Entity
-            [frontend.db.datascript.entity-plus :as entity-plus]))
+            [frontend.db.datascript.entity-plus :as entity-plus]
+            [frontend.config :as config]))
 
 ;; TODO: extract to specific models and move data transform logic to the
 ;; corresponding handlers.
@@ -271,15 +272,29 @@ independent of format as format specific heading characters are stripped"
   "Returns first block for given page name and block's route name. Block's route
   name must match the content of a page's block header"
   [repo page-name route-name]
-  (->> (d/q '[:find (pull ?b [:block/uuid])
-              :in $ ?page-name ?route-name ?content-matches
-              :where
-              [?page :block/name ?page-name]
-              [?b :block/page ?page]
-              [?b :block/properties ?prop]
-              [(get ?prop :heading) _]
-              [?b :block/content ?content]
-              [(?content-matches ?content ?route-name)]]
+  (->> (d/q (if (config/db-based-graph? repo)
+              '[:find (pull ?b [:block/uuid])
+                :in $ ?page-name ?route-name ?content-matches
+                :where
+                [?page :block/name ?page-name]
+                [?b :block/page ?page]
+                [?b :block/properties ?prop]
+                [?prop-b :block/name "heading"]
+                [?prop-b :block/type "property"]
+                [?prop-b :block/uuid ?prop-uuid]
+                [(get ?prop ?prop-uuid) _]
+                [?b :block/content ?content]
+                [(?content-matches ?content ?route-name)]]
+
+              '[:find (pull ?b [:block/uuid])
+                :in $ ?page-name ?route-name ?content-matches
+                :where
+                [?page :block/name ?page-name]
+                [?b :block/page ?page]
+                [?b :block/properties ?prop]
+                [(get ?prop :heading) _]
+                [?b :block/content ?content]
+                [(?content-matches ?content ?route-name)]])
             (conn/get-db repo)
             page-name
             route-name

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

@@ -11,8 +11,7 @@
   [coll key]
   (let [repo (state/get-current-repo)]
     (if (and (config/db-based-graph? repo)
-             (keyword? key)
-             (contains? db-property/built-in-properties-keys key))
+             (keyword? key))
       (when-let [property (db/entity repo [:block/name (gp-util/page-name-sanity-lc (name key))])]
         (get coll (:block/uuid property)))
       (get coll key))))