|
|
@@ -13,9 +13,8 @@
|
|
|
[frontend.modules.outliner.tree :as tree]))
|
|
|
|
|
|
(defn trigger-custom-query!
|
|
|
- [state *query-error *query-triggered?]
|
|
|
- (let [[config query] (:rum/args state)
|
|
|
- repo (state/get-current-repo)
|
|
|
+ [config query *query-error]
|
|
|
+ (let [repo (state/get-current-repo)
|
|
|
result-atom (atom nil)
|
|
|
current-block-uuid (or (:block/uuid (:block config))
|
|
|
(:block/uuid config))
|
|
|
@@ -45,36 +44,34 @@
|
|
|
(catch :default e
|
|
|
(reset! *query-error e)
|
|
|
(atom nil)))]
|
|
|
- (when *query-triggered?
|
|
|
- (reset! *query-triggered? true))
|
|
|
(if (instance? Atom query-atom)
|
|
|
query-atom
|
|
|
result-atom)))
|
|
|
|
|
|
-(defn get-group-by-page [{:keys [result-transform query] :as q}
|
|
|
+(defn get-group-by-page [{:keys [result-transform query] :as query-m}
|
|
|
{:keys [table?]}]
|
|
|
(if table?
|
|
|
false ;; Immediately return false as table view can't handle grouping
|
|
|
- (get q :group-by-page?
|
|
|
+ (get query-m :group-by-page?
|
|
|
(and (not result-transform)
|
|
|
(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?)
|
|
|
+ [config query-m *query-error current-block-uuid options]
|
|
|
+ (let [query-atom (trigger-custom-query! config query-m *query-error)
|
|
|
query-result (and query-atom (rum/react query-atom))
|
|
|
- ;; exclude the current one, otherwise it'll loop forever
|
|
|
+ ;; exclude the current one, otherwise it'll loop forever
|
|
|
remove-blocks (if current-block-uuid [current-block-uuid] nil)
|
|
|
transformed-query-result (when query-result
|
|
|
- (let [result (db/custom-query-result-transform query-result remove-blocks q)]
|
|
|
+ (let [result (db/custom-query-result-transform query-result remove-blocks query-m)]
|
|
|
(if (and query-result (coll? result) (:block/uuid (first result)))
|
|
|
(cond-> result
|
|
|
- (get q :remove-block-children? true)
|
|
|
+ (get query-m :remove-block-children? true)
|
|
|
tree/filter-top-level-blocks)
|
|
|
result)))
|
|
|
- group-by-page? (get-group-by-page q options)
|
|
|
+ group-by-page? (get-group-by-page query-m options)
|
|
|
result (if (and group-by-page? (:block/uuid (first transformed-query-result)))
|
|
|
(let [result (db-utils/group-by-page transformed-query-result)]
|
|
|
(if (map? result)
|