Sort by multiple columns

Excellent, thanks for sharing.

I finally got my deadline drive task resurfacing work the way I want it, order by deadline first, then for the same day, order by priority.

Sharing my default queries here.

:default-queries
 {:journals [
   {:title "🔨 DAILY"
    :query [:find (pull ?h [*])
            :where
            [?h :block/marker ?marker]
            [(contains? #{"NOW" "DOING", "TODO"} ?marker)]
            [?t :block/name "daily"]
            [?h :block/refs ?t]
            [?h :block/page ?p]
            [?p :block/journal? true]
           ]
    :inputs []
    :result-transform (fn [result] (sort-by (fn [h] (get h :block/deadline)) result))
    :collapsed? false}

   {:title "🔨 NOW"
    :query [:find (pull ?h [*])
            :where
            [?h :block/marker ?marker]
            [(contains? #{"NOW" "DOING"} ?marker)]
            (not [?t :block/name "daily"]
            [?h :block/refs ?t])
            [?h :block/page ?p]
            [?p :block/journal? true]
           ]
    :inputs []
    ;:result-transform (fn [result] (sort-by (fn [h] (get h :block/deadline)) result))
    :result-transform (fn [result]
     (sort-by (juxt (fn [h] (get h :block/deadline)) (fn [i] (get i :block/priority "Z"))) result))
    :collapsed? false}

   {:title "📅 NEXT"
    :query [:find (pull ?h [*])
            :in $ ?next
            :where
            [?h :block/marker ?marker]
            [(contains? #{"LATER" "TODO"} ?marker)]
            (not [?t :block/name "daily"]
            [?h :block/refs ?t])
            [?h :block/page ?p]
            [?p :block/journal? true]
            [?h :block/deadline ?d]
            [(< ?d ?next)]
           ]
    :inputs [:7d-after]
    ;:result-transform (fn [result] (sort-by (fn [h] (get h :block/deadline)) result))
    :result-transform (fn [result]
     (sort-by (juxt (fn [h] (get h :block/deadline)) (fn [i] (get i :block/priority "Z"))) result))
    :collapsed? false}

   {:title "📅 WAITING"
    :query [:find (pull ?h [*])
            :in $ ?next
            :where
            [?h :block/marker ?marker]
            [(contains? #{"WAITING"} ?marker)]
            [?h :block/page ?p]
            [?p :block/journal? true]
            [?h :block/deadline ?d]
            [(< ?d ?next)]
           ]
    :inputs [:7d-after]
    ;:result-transform (fn [result] (sort-by (fn [h] (get h :block/deadline)) result))
    :result-transform (fn [result]
     (sort-by (juxt (fn [h] (get h :block/deadline)) (fn [i] (get i :block/priority "Z"))) result))
    :collapsed? true}

   {:title "📅 BACKLOG"
    :query [:find (pull ?h [*])
            :in $ ?next
            :where
            [?h :block/marker ?marker]
            [(contains? #{"LATER" "TODO"} ?marker)]
            (not [?t :block/name "daily"]
            [?h :block/refs ?t])
            [?h :block/page ?p]
            [?p :block/journal? true]
            [?h :block/deadline ?d]
            [(>= ?d ?next)]
           ]
    :inputs [:7d-after]
    ;:result-transform (fn [result] (sort-by (fn [h] (get h :block/deadline)) result))
    :result-transform (fn [result]
     (sort-by (juxt (fn [h] (get h :block/deadline)) (fn [i] (get i :block/priority "Z"))) result))
    :collapsed? true}

   {:title "📅 WITHOUT DEADLINE"
    :query [:find (pull ?h [*])
            :where
            [?h :block/marker ?marker]
            [(contains? #{"TODO" "LATER" "DOING" "NOW" "WAITING"} ?marker)]
            (not [?h :block/deadline _])
            [?h :block/page ?p]
            [?p :block/journal? true]
            (not [?t :block/name "daily"]
            [?h :block/refs ?t])
            (not [?t :block/name "kaizen"]
            [?h :block/refs ?t])
           ]
    :inputs []
    :result-transform (fn [result] (sort-by (fn [h] (get h :block/id "Z")) result))
    :collapsed? true}
 ]}
1 Like