瀏覽代碼

Revert change so that query functions can still work

Also add some docstring and slightly alter command name to reflect query
functions increased ability introduced with the related #9563
Gabriel Horner 2 年之前
父節點
當前提交
cb29fb6eae

+ 1 - 1
src/main/frontend/commands.cljs

@@ -278,7 +278,7 @@
     [["Query" [[:editor/input "{{query }}" {:backward-pos 2}]
                [:editor/exit]] query-doc]
      ["Zotero" (zotero-steps) "Import Zotero journal article"]
-     ["Query table function" [[:editor/input "{{function }}" {:backward-pos 2}]] "Create a query table function"]
+     ["Query function" [[:editor/input "{{function }}" {:backward-pos 2}]] "Create a query function"]
      ["Calculator" [[:editor/input "```calc\n\n```" {:type "block"
                                                      :backward-pos 4}]
                     [:codemirror/focus]] "Insert a calculator"]

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

@@ -2733,8 +2733,13 @@
         block (merge block (block/parse-title-and-body uuid format pre-block? content))
         blocks-container-id (:blocks-container-id config)
         config (update config :block merge block)
-        ;; Each block might have multiple queries, but we store only the first query's result
-        config (assoc config :query-result (atom nil))
+        ;; Each block might have multiple queries, but we store only the first query's result.
+        ;; This :query-result atom is used by the query function feature to share results between
+        ;; the parent's query block and the children blocks. This works because config is shared
+        ;; between parent and children blocks
+        config (if (nil? (:query-result config))
+                 (assoc config :query-result (atom nil))
+                 config)
         config (if ref? (block-handler/attach-order-list-state config block) config)
         heading? (:heading properties)
         *control-show? (get state ::control-show?)

+ 2 - 0
src/main/frontend/components/query/result.cljs

@@ -60,6 +60,8 @@
               (not (and (string? query) (string/includes? query "(by-page false)")))))))
 
 (defn get-query-result
+  "Fetches a query's result, transforms it as needed and saves the result into
+  an atom that is passed in as an argument"
   [state config *query-error *query-triggered? current-block-uuid q options]
   (let [query-atom (trigger-custom-query! state *query-error *query-triggered?)
         query-result (and query-atom (rum/react query-atom))