mirror of
https://github.com/logseq/logseq.git
synced 2026-04-30 17:06:23 +00:00
Fix sort-by not working for blocks
- Also add sort-by support for pages which fixes #5643 - Add sort-by tests - Fix sample producing weird queries e.g. mixed block and page clauses - Clean up last, hard to read test setup in query-dsl
This commit is contained in:
@@ -38,11 +38,7 @@
|
||||
;; project (block, TBD)
|
||||
|
||||
;; Sort by (field, asc/desc):
|
||||
|
||||
;; created_at
|
||||
;; last_modified_at
|
||||
|
||||
;; (sort-by last_modified_at asc)
|
||||
;; (sort-by created-at asc)
|
||||
|
||||
;; (between -7d +7d)
|
||||
|
||||
@@ -151,13 +147,16 @@
|
||||
|
||||
:else
|
||||
(->> clauses
|
||||
(map (fn [result]
|
||||
(if (list? result)
|
||||
result
|
||||
(let [result (if (vector? (ffirst result))
|
||||
(apply concat result)
|
||||
result)]
|
||||
(cons 'and (seq result))))))
|
||||
(mapcat (fn [result]
|
||||
(cond
|
||||
;; rule like (task ?b #{"NOW"})
|
||||
(list? result)
|
||||
[result]
|
||||
;; datalog clause like [[?b :block/uuid]]
|
||||
(vector? result)
|
||||
result
|
||||
:else
|
||||
[(cons 'and (seq result))])))
|
||||
(apply list fe)))
|
||||
|
||||
:else
|
||||
@@ -320,33 +319,24 @@
|
||||
(when-let [num (second e)]
|
||||
(when (integer? num)
|
||||
(reset! sample num)
|
||||
{:query [['?p :block/uuid]]})))
|
||||
;; blank b/c this post-process filter doesn't effect query
|
||||
{})))
|
||||
|
||||
(defn- build-sort-by
|
||||
[e sort-by_]
|
||||
(let [[k order] (rest e)
|
||||
order (if (and order (contains? #{:asc :desc}
|
||||
(keyword (string/lower-case (name order)))))
|
||||
(keyword (string/lower-case (name order)))
|
||||
:desc)
|
||||
k (-> (string/lower-case (name k))
|
||||
(string/replace "_" "-"))
|
||||
get-value (cond
|
||||
(= k "created-at")
|
||||
:block/created-at
|
||||
|
||||
(= k "updated-at")
|
||||
:block/updated-at
|
||||
|
||||
:else
|
||||
#(get-in % [:block/properties k]))
|
||||
comp (if (= order :desc) >= <=)]
|
||||
(reset! sort-by_
|
||||
(fn [result]
|
||||
(->> result
|
||||
flatten
|
||||
(sort-by get-value comp))))
|
||||
nil))
|
||||
(let [[k order*] (map keyword (rest e))
|
||||
order (if (contains? #{:asc :desc} order*)
|
||||
order*
|
||||
:desc)
|
||||
comp (if (= order :desc) >= <=)]
|
||||
(reset! sort-by_
|
||||
(fn sort-results [result]
|
||||
;; first because there is one binding result in query-wrapper
|
||||
(sort-by #(-> % first (get-in [:block/properties k]))
|
||||
comp
|
||||
result)))
|
||||
;; blank b/c this post-process filter doesn't effect query
|
||||
{}))
|
||||
|
||||
(defn- build-page
|
||||
[e]
|
||||
@@ -392,7 +382,7 @@ Some bindings in this fn:
|
||||
page-ref? (page-ref/page-ref? e)]
|
||||
(when (or (and page-ref?
|
||||
(not (contains? #{'page-property 'page-tags} (:current-filter env))))
|
||||
(contains? #{'between 'property 'todo 'task 'priority 'sort-by 'page} fe)
|
||||
(contains? #{'between 'property 'todo 'task 'priority 'page} fe)
|
||||
(and (not page-ref?) (string? e)))
|
||||
(reset! blocks? true))
|
||||
(cond
|
||||
|
||||
Reference in New Issue
Block a user