|
|
@@ -16,19 +16,18 @@
|
|
|
[rum.core :as rum]
|
|
|
[frontend.config :as config]))
|
|
|
|
|
|
-(defn built-in-custom-query?
|
|
|
+(defn- built-in-custom-query?
|
|
|
[title]
|
|
|
(let [queries (get-in (state/sub-config) [:default-queries :journals])]
|
|
|
(when (seq queries)
|
|
|
(boolean (some #(= % title) (map :title queries))))))
|
|
|
|
|
|
-;; TODO: Split this into file and DB graph versions. DB graph needlessly coupled too file graph args
|
|
|
+;; TODO: Split this into file and DB graph versions. DB graph needlessly coupled to file graph args
|
|
|
(rum/defcs custom-query-inner < rum/static
|
|
|
- [state config {:keys [query breadcrumb-show?]}
|
|
|
+ [state {:keys [db-graph? dsl-query?] :as config} {:keys [query breadcrumb-show?]}
|
|
|
{:keys [query-error-atom
|
|
|
current-block
|
|
|
table?
|
|
|
- dsl-query?
|
|
|
page-list?
|
|
|
view-f
|
|
|
result
|
|
|
@@ -59,15 +58,15 @@
|
|
|
(str error)]))]
|
|
|
(util/hiccup-keywordize result))
|
|
|
|
|
|
- (and (config/db-based-graph? (state/get-current-repo))
|
|
|
- (not (:built-in? config)))
|
|
|
+ (and db-graph? (not (:built-in-query? config)))
|
|
|
(query-view/query-result (assoc config :id (:db/id current-block))
|
|
|
current-block result)
|
|
|
|
|
|
- (and (not (config/db-based-graph? (state/get-current-repo)))
|
|
|
+ (and (not db-graph?)
|
|
|
(or page-list? table?))
|
|
|
(query-table/result-table config current-block result {:page? page-list?} map-inline page-cp ->elem inline-text)
|
|
|
|
|
|
+ ;; Normally displays built-in-query results
|
|
|
(and (seq result) (or only-blocks? blocks-grouped-by-page?))
|
|
|
(->hiccup result
|
|
|
(assoc config
|
|
|
@@ -116,52 +115,53 @@
|
|
|
[:span.opacity-60.text-sm.ml-2.results-count
|
|
|
(str result-count (if (> result-count 1) " results" " result"))])]))
|
|
|
|
|
|
+(defn- calculate-collapsed?
|
|
|
+ [current-block current-block-uuid {:keys [collapsed?]}]
|
|
|
+ (let [temp-collapsed? (state/sub-collapsed current-block-uuid)
|
|
|
+ collapsed?' (if (some? temp-collapsed?)
|
|
|
+ temp-collapsed?
|
|
|
+ (or collapsed?
|
|
|
+ (:block/collapsed? current-block)))]
|
|
|
+ collapsed?'))
|
|
|
+
|
|
|
(rum/defcs custom-query* < rum/reactive rum/static db-mixins/query
|
|
|
(rum/local nil ::query-result-atom)
|
|
|
{:init (fn [state]
|
|
|
- (let [[config {:keys [title collapsed?]}] (:rum/args state)
|
|
|
- built-in? (built-in-custom-query? title)
|
|
|
- dsl-query? (:dsl-query? config)
|
|
|
- current-block-uuid (or (:block/uuid (:block config))
|
|
|
- (:block/uuid config))]
|
|
|
- (when-not (or built-in? dsl-query?)
|
|
|
- (when collapsed?
|
|
|
- (editor-handler/collapse-block! current-block-uuid))))
|
|
|
+ (let [[{:keys [dsl-query? db-graph? built-in-query?] :as config}
|
|
|
+ {:keys [collapsed?]}] (:rum/args state)]
|
|
|
+ ;; collapsed? not needed for db graphs
|
|
|
+ (when (not db-graph?)
|
|
|
+ (when-not (or built-in-query? dsl-query?)
|
|
|
+ (when collapsed?
|
|
|
+ (editor-handler/collapse-block! (or (:block/uuid (:block config))
|
|
|
+ (:block/uuid config)))))))
|
|
|
(assoc state :query-error (atom nil)
|
|
|
:fulltext-query-result (atom nil)))}
|
|
|
- [state config {:keys [title builder query view collapsed?] :as q}]
|
|
|
+ [state {:keys [db-graph? dsl-query? built-in-query?] :as config} {:keys [builder query view collapsed?] :as q}]
|
|
|
(let [*query-result-atom (::query-result-atom state)
|
|
|
*query-error (:query-error state)
|
|
|
*fulltext-query-result (:fulltext-query-result state)
|
|
|
- built-in? (built-in-custom-query? title)
|
|
|
- config (assoc config :built-in? built-in?)
|
|
|
- dsl-query? (:dsl-query? config)
|
|
|
current-block-uuid (or (:block/uuid (:block config))
|
|
|
(:block/uuid config))
|
|
|
current-block (db/entity [:block/uuid current-block-uuid])
|
|
|
- temp-collapsed? (state/sub-collapsed current-block-uuid)
|
|
|
- collapsed?' (if (some? temp-collapsed?)
|
|
|
- temp-collapsed?
|
|
|
- (or
|
|
|
- collapsed?
|
|
|
- (:block/collapsed? current-block)))
|
|
|
- built-in-collapsed? (and collapsed? built-in?)
|
|
|
- db-based? (config/db-based-graph? (state/get-current-repo))
|
|
|
- table? (when-not db-based?
|
|
|
+ ;; Get query result
|
|
|
+ collapsed?' (calculate-collapsed? current-block current-block-uuid {:collapsed? (if-not db-graph? collapsed? false)})
|
|
|
+ built-in-collapsed? (and collapsed? built-in-query?)
|
|
|
+ table? (when-not db-graph?
|
|
|
(or (get-in current-block [:block/properties :query-table])
|
|
|
(and (string? query) (string/ends-with? (string/trim query) "table"))))
|
|
|
- view-fn (if (keyword? view) (get-in (state/sub-config) [:query/views view]) view)
|
|
|
- view-f (and view-fn (sci/eval-string (pr-str view-fn)))
|
|
|
result (when (or built-in-collapsed? (not collapsed?'))
|
|
|
(or @*query-result-atom
|
|
|
(let [result (query-result/get-query-result config q *query-error *fulltext-query-result current-block-uuid {:table? table?})]
|
|
|
(reset! *query-result-atom result)
|
|
|
result)))
|
|
|
+ ;; Args for displaying query header and results
|
|
|
+ view-fn (if (keyword? view) (get-in (state/sub-config) [:query/views view]) view)
|
|
|
+ view-f (and view-fn (sci/eval-string (pr-str view-fn)))
|
|
|
page-list? (and (seq result)
|
|
|
(some? (:block/name (first result))))
|
|
|
opts {:query-error-atom *query-error
|
|
|
:current-block current-block
|
|
|
- :dsl-query? dsl-query?
|
|
|
:table? table?
|
|
|
:view-f view-f
|
|
|
:page-list? page-list?
|
|
|
@@ -170,9 +170,9 @@
|
|
|
(if (:custom-query? config)
|
|
|
;; Don't display recursive results when query blocks are a query result
|
|
|
[:code (if dsl-query? (str "Results for " (pr-str query)) "Advanced query results")]
|
|
|
- (when-not (and built-in? (empty? result))
|
|
|
+ (when-not (and built-in-query? (empty? result))
|
|
|
[:div.custom-query (get config :attr {})
|
|
|
- (when (and (not db-based?) (not built-in?))
|
|
|
+ (when (and (not db-graph?) (not built-in-query?))
|
|
|
(file-query/custom-query-header config
|
|
|
q
|
|
|
{:query-error-atom *query-error
|
|
|
@@ -186,10 +186,10 @@
|
|
|
|
|
|
(when (and dsl-query? builder) builder)
|
|
|
|
|
|
- (if built-in?
|
|
|
+ (if built-in-query?
|
|
|
[:div {:style {:margin-left 2}}
|
|
|
(ui/foldable
|
|
|
- (query-title config title {:result-count (count result)})
|
|
|
+ (query-title config (:title q) {:result-count (count result)})
|
|
|
(fn []
|
|
|
(custom-query-inner config q opts))
|
|
|
{:default-collapsed? collapsed?
|
|
|
@@ -205,5 +205,8 @@
|
|
|
(ui/block-error "Query Error:" {:content (:query q)})
|
|
|
(ui/lazy-visible
|
|
|
(fn []
|
|
|
- (custom-query* config q))
|
|
|
+ (custom-query* (merge config
|
|
|
+ {:db-graph? (config/db-based-graph? (state/get-current-repo))
|
|
|
+ :built-in-query? (built-in-custom-query? (:title q))})
|
|
|
+ q))
|
|
|
{:debug-id q})))
|