|
@@ -2727,29 +2727,32 @@
|
|
|
[state]
|
|
|
(let [[config query] (:rum/args state)
|
|
|
repo (state/get-current-repo)
|
|
|
- result-atom (atom nil)
|
|
|
- query-atom (if (:dsl-query? config)
|
|
|
- (let [q (:query query)
|
|
|
- form (safe-read-string q false)]
|
|
|
- (cond
|
|
|
- ;; Searches like 'foo' or 'foo bar' come back as symbols
|
|
|
- ;; and are meant to go directly to full text search
|
|
|
- (and (util/electron?) (symbol? form)) ; full-text search
|
|
|
- (p/let [blocks (search/block-search repo (string/trim (str form)) {:limit 30})]
|
|
|
- (when (seq blocks)
|
|
|
- (let [result (db/pull-many (state/get-current-repo) '[*] (map (fn [b] [:block/uuid (uuid (:block/uuid b))]) blocks))]
|
|
|
- (reset! result-atom result))))
|
|
|
-
|
|
|
- (symbol? form)
|
|
|
- (atom nil)
|
|
|
-
|
|
|
- :else
|
|
|
- (query-dsl/query (state/get-current-repo) q)))
|
|
|
- (db/custom-query query))
|
|
|
+ result-atom (or (:query-atom state) (atom nil))
|
|
|
+ [full-text-search? query-atom] (if (:dsl-query? config)
|
|
|
+ (let [q (:query query)
|
|
|
+ form (safe-read-string q false)]
|
|
|
+ (cond
|
|
|
+ ;; Searches like 'foo' or 'foo bar' come back as symbols
|
|
|
+ ;; and are meant to go directly to full text search
|
|
|
+ (and (util/electron?) (symbol? form)) ; full-text search
|
|
|
+ [true
|
|
|
+ (p/let [blocks (search/block-search repo (string/trim (str form)) {:limit 30})]
|
|
|
+ (when (seq blocks)
|
|
|
+ (let [result (db/pull-many (state/get-current-repo) '[*] (map (fn [b] [:block/uuid (uuid (:block/uuid b))]) blocks))]
|
|
|
+ (reset! result-atom result))))]
|
|
|
+
|
|
|
+ (symbol? form)
|
|
|
+ [false (atom nil)]
|
|
|
+
|
|
|
+ :else
|
|
|
+ [false (query-dsl/query (state/get-current-repo) q)]))
|
|
|
+ [false (db/custom-query query)])
|
|
|
query-atom (if (instance? Atom query-atom)
|
|
|
query-atom
|
|
|
result-atom)]
|
|
|
- (assoc state :query-atom query-atom)))
|
|
|
+ (assoc state
|
|
|
+ :query-atom query-atom
|
|
|
+ :full-text-search? full-text-search?)))
|
|
|
|
|
|
(rum/defcs ^:large-vars/cleanup-todo custom-query* < rum/reactive
|
|
|
{:will-mount trigger-custom-query!
|
|
@@ -2809,21 +2812,30 @@
|
|
|
[:div.custom-query.mt-4 (get config :attr {})
|
|
|
(ui/foldable
|
|
|
[:div.custom-query-title.flex.justify-between.w-full
|
|
|
- [:div [:span.title-text (cond
|
|
|
- (vector? title) title
|
|
|
- (string? title) (inline-text config
|
|
|
- (get-in config [:block :block/format] :markdown)
|
|
|
- title)
|
|
|
- :else title)]
|
|
|
+ [:div.flex.items-center
|
|
|
+ (when (:full-text-search? state)
|
|
|
+ [:a.control.fade-link.mr-1.inline-flex
|
|
|
+ {:title "Refresh query result"
|
|
|
+ :on-mouse-down (fn [e]
|
|
|
+ (util/stop e)
|
|
|
+ (trigger-custom-query! state))}
|
|
|
+ (ui/icon "refresh" {:style {:font-size 20}})])
|
|
|
+ [:span.title-text (cond
|
|
|
+ (vector? title) title
|
|
|
+ (string? title) (inline-text config
|
|
|
+ (get-in config [:block :block/format] :markdown)
|
|
|
+ title)
|
|
|
+ :else title)]
|
|
|
[:span.opacity-60.text-sm.ml-2.results-count
|
|
|
(str (count transformed-query-result) " results")]]
|
|
|
+
|
|
|
;;insert an "edit" button in the query view
|
|
|
(when-not built-in?
|
|
|
- [:a.opacity-70.hover:opacity-100.svg-small.inline
|
|
|
- {:on-mouse-down (fn [e]
|
|
|
- (util/stop e)
|
|
|
- (editor-handler/edit-block! current-block :max (:block/uuid current-block)))}
|
|
|
- svg/edit])]
|
|
|
+ [:a.opacity-70.hover:opacity-100.svg-small.inline
|
|
|
+ {:on-mouse-down (fn [e]
|
|
|
+ (util/stop e)
|
|
|
+ (editor-handler/edit-block! current-block :max (:block/uuid current-block)))}
|
|
|
+ svg/edit])]
|
|
|
(fn []
|
|
|
[:div
|
|
|
(when (and current-block (not view-f) (nil? table-view?))
|