mirror of
https://github.com/logseq/logseq.git
synced 2026-04-30 08:56:29 +00:00
fix: remove buggy and inconsistent sort-by filter
In #11508 db graphs moved to a new table which improved but changed how sort worked for queries. Better to deprecate the text sort-by filter than to have a buggy and inconsistent sort for queries
This commit is contained in:
@@ -574,11 +574,12 @@ created-at:: 1608968448116
|
||||
(def get-property-value query-dsl/get-db-property-value)
|
||||
(def get-property-value #(get-in %1 [:block/properties %2])))
|
||||
|
||||
(deftest sort-by-queries
|
||||
(load-test-files [{:file/path "journals/2020_02_25.md"
|
||||
:file/content "rating:: 10"}
|
||||
{:file/path "journals/2020_12_26.md"
|
||||
:file/content "rating:: 8
|
||||
(when-not js/process.env.DB_GRAPH
|
||||
(deftest sort-by-queries
|
||||
(load-test-files [{:file/path "journals/2020_02_25.md"
|
||||
:file/content "rating:: 10"}
|
||||
{:file/path "journals/2020_12_26.md"
|
||||
:file/content "rating:: 8
|
||||
- DONE 26-b1
|
||||
created-at:: 1608968448113
|
||||
fruit:: plum
|
||||
@@ -590,43 +591,43 @@ created-at:: 1608968448115
|
||||
- 26-b4
|
||||
created-at:: 1608968448116
|
||||
"}])
|
||||
(let [task-filter (if js/process.env.DB_GRAPH "(task todo done)" "(task later done)")]
|
||||
(testing "sort-by user block property fruit"
|
||||
(let [result (->> (dsl-query (str "(and " task-filter " (sort-by fruit))"))
|
||||
(map #(get-property-value % :fruit)))]
|
||||
(is (= ["plum" "apple" nil]
|
||||
result)
|
||||
"sort-by correctly defaults to desc"))
|
||||
(let [task-filter "(task later done)"]
|
||||
(testing "sort-by user block property fruit"
|
||||
(let [result (->> (dsl-query (str "(and " task-filter " (sort-by fruit))"))
|
||||
(map #(get-property-value % :fruit)))]
|
||||
(is (= ["plum" "apple" nil]
|
||||
result)
|
||||
"sort-by correctly defaults to desc"))
|
||||
|
||||
(let [result (->> (dsl-query (str "(and " task-filter " (sort-by fruit desc))"))
|
||||
(map #(get-property-value % :fruit)))]
|
||||
(is (= ["plum" "apple" nil]
|
||||
result)
|
||||
"sort-by desc"))
|
||||
(let [result (->> (dsl-query (str "(and " task-filter " (sort-by fruit desc))"))
|
||||
(map #(get-property-value % :fruit)))]
|
||||
(is (= ["plum" "apple" nil]
|
||||
result)
|
||||
"sort-by desc"))
|
||||
|
||||
(let [result (->> (dsl-query (str "(and " task-filter " (sort-by fruit asc))"))
|
||||
(map #(get-property-value % :fruit)))]
|
||||
(is (= [nil "apple" "plum"]
|
||||
result)
|
||||
"sort-by asc")))
|
||||
(let [result (->> (dsl-query (str "(and " task-filter " (sort-by fruit asc))"))
|
||||
(map #(get-property-value % :fruit)))]
|
||||
(is (= [nil "apple" "plum"]
|
||||
result)
|
||||
"sort-by asc")))
|
||||
|
||||
(testing "sort-by hidden, built-in block property created-at"
|
||||
(let [result (->> (dsl-query (str "(and " task-filter " (sort-by created-at desc))"))
|
||||
(map #(get-property-value % :created-at)))]
|
||||
(is (= [1608968448115 1608968448114 1608968448113]
|
||||
result))
|
||||
"sorted-by desc")
|
||||
(testing "sort-by hidden, built-in block property created-at"
|
||||
(let [result (->> (dsl-query (str "(and " task-filter " (sort-by created-at desc))"))
|
||||
(map #(get-property-value % :created-at)))]
|
||||
(is (= [1608968448115 1608968448114 1608968448113]
|
||||
result))
|
||||
"sorted-by desc")
|
||||
|
||||
(let [result (->> (dsl-query (str "(and " task-filter " (sort-by created-at asc))"))
|
||||
(map #(get-property-value % :created-at)))]
|
||||
(is (= [1608968448113 1608968448114 1608968448115]
|
||||
result)
|
||||
"sorted-by asc")))
|
||||
(let [result (->> (dsl-query (str "(and " task-filter " (sort-by created-at asc))"))
|
||||
(map #(get-property-value % :created-at)))]
|
||||
(is (= [1608968448113 1608968448114 1608968448115]
|
||||
result)
|
||||
"sorted-by asc")))
|
||||
|
||||
(testing "user page property rating"
|
||||
(is (= [10 8]
|
||||
(->> (dsl-query "(and (page-property rating) (sort-by rating))")
|
||||
(map #(get-property-value % :rating))))))))
|
||||
(testing "user page property rating"
|
||||
(is (= [10 8]
|
||||
(->> (dsl-query "(and (page-property rating) (sort-by rating))")
|
||||
(map #(get-property-value % :rating)))))))))
|
||||
|
||||
(deftest simplify-query
|
||||
(are [x y] (= (query-dsl/simplify-query x) y)
|
||||
|
||||
Reference in New Issue
Block a user