mirror of
https://github.com/logseq/logseq.git
synced 2026-05-23 20:24:15 +00:00
fix(journals): hide recycled journals and refresh list on recycle
This commit is contained in:
@@ -256,7 +256,9 @@
|
||||
(keep (fn [d]
|
||||
(when (<= (:v d) today)
|
||||
(let [e (d/entity db (:e d))]
|
||||
(when (and (entity-util/journal? e) (:db/id e))
|
||||
(when (and (entity-util/journal? e)
|
||||
(:db/id e)
|
||||
(not (entity-util/recycled? e)))
|
||||
e))))))))
|
||||
|
||||
(defn- get-structured-datoms
|
||||
|
||||
@@ -31,9 +31,16 @@
|
||||
|
||||
(s/def ::affected-keys (s/coll-of ::react-query-keys))
|
||||
|
||||
(defn- journal-page?
|
||||
[db eid journal-tag-id]
|
||||
(when (and db eid journal-tag-id)
|
||||
(some (fn [tag]
|
||||
(= journal-tag-id (:db/id tag)))
|
||||
(:block/tags (d/entity db eid)))))
|
||||
|
||||
(defn get-affected-queries-keys
|
||||
"Get affected queries through transaction datoms."
|
||||
[{:keys [tx-data db-after]}]
|
||||
[{:keys [tx-data db-before db-after]}]
|
||||
{:post [(s/valid? ::affected-keys %)]}
|
||||
(let [blocks (->> (filter (fn [datom] (contains? #{:block/parent :block/page} (:a datom))) tx-data)
|
||||
(map :v)
|
||||
@@ -47,12 +54,19 @@
|
||||
tags (->> (filter (fn [datom] (= :block/tags (:a datom))) tx-data)
|
||||
(map :v)
|
||||
(distinct))
|
||||
journals? (some (fn [datom]
|
||||
(and
|
||||
(= :block/tags (:a datom))
|
||||
(= (:db/id (d/entity db-after :logseq.class/Journal))
|
||||
(:v datom))))
|
||||
tx-data)
|
||||
journal-tag-id (:db/id (d/entity db-after :logseq.class/Journal))
|
||||
touched-eids (->> tx-data (map :e) distinct)
|
||||
journals? (or (some (fn [datom]
|
||||
(and (= :block/tags (:a datom))
|
||||
(= journal-tag-id (:v datom))))
|
||||
tx-data)
|
||||
(some (fn [datom]
|
||||
(= :block/journal-day (:a datom)))
|
||||
tx-data)
|
||||
(some (fn [eid]
|
||||
(or (journal-page? db-before eid journal-tag-id)
|
||||
(journal-page? db-after eid journal-tag-id)))
|
||||
touched-eids))
|
||||
reaction-targets (->> (filter (fn [datom]
|
||||
(= :logseq.property.reaction/target (:a datom))) tx-data)
|
||||
(map :v)
|
||||
|
||||
@@ -86,6 +86,20 @@
|
||||
(is (= 1 (:db/id (db/entity test-db 1))))
|
||||
(is (= 1 (:db/id (db/entity (conn/get-db test-db) 1)))))
|
||||
|
||||
(deftest get-latest-journals-should-exclude-recycled-journal-pages
|
||||
(load-test-files
|
||||
[{:page {:build/journal 20240101}}
|
||||
{:page {:build/journal 20240102}}
|
||||
{:page {:build/journal 20240103}}])
|
||||
(let [journal-2024-01-02-id (ffirst (d/q '[:find ?e
|
||||
:where
|
||||
[?e :block/journal-day 20240102]]
|
||||
(conn/get-db test-db)))]
|
||||
(db/transact! test-db [{:db/id journal-2024-01-02-id
|
||||
:logseq.property/deleted-at 1704196800000}]))
|
||||
(is (= [20240103 20240101]
|
||||
(mapv :block/journal-day (model/get-latest-journals test-db 10)))))
|
||||
|
||||
(deftest get-block-by-page-name-and-block-route-name
|
||||
(load-test-files
|
||||
[{:page {:block/title "foo"}
|
||||
|
||||
@@ -19,3 +19,14 @@
|
||||
:logseq.property.reaction/target target-id}])
|
||||
affected (worker-react/get-affected-queries-keys tx-report)]
|
||||
(is (some #{[:frontend.worker.react/block-reactions target-id]} affected)))))
|
||||
|
||||
(deftest affected-keys-journals-when-journal-recycled
|
||||
(testing "recycling a journal page should refresh journals query key"
|
||||
(let [conn (db-test/create-conn-with-blocks
|
||||
[{:page {:build/journal 20240101}}
|
||||
{:page {:build/journal 20240102}}])
|
||||
journal (db-test/find-journal-by-journal-day @conn 20240102)
|
||||
tx-report (d/transact! conn [{:db/id (:db/id journal)
|
||||
:logseq.property/deleted-at 1704196800000}])
|
||||
affected (worker-react/get-affected-queries-keys tx-report)]
|
||||
(is (some #{[:frontend.worker.react/journals]} affected)))))
|
||||
|
||||
Reference in New Issue
Block a user