Merge pull request #6120 from 8N9KT/feat/filter-page-graph

feat: hide journals in page graph
This commit is contained in:
Gabriel Horner
2022-07-25 13:52:40 -04:00
committed by GitHub
5 changed files with 64 additions and 14 deletions

View File

@@ -434,6 +434,7 @@
(defonce *orphan-pages? (atom true))
(defonce *builtin-pages? (atom nil))
(defonce *excluded-pages? (atom true))
(defonce *show-journals-in-page-graph? (atom nil))
(rum/defc ^:large-vars/cleanup-todo graph-filters < rum/reactive
[graph settings n-hops]
@@ -630,9 +631,21 @@
graph (update graph :nodes #(filter-graph-nodes % search-graph-filters))]
(global-graph-inner graph settings theme)))
(rum/defc page-graph-inner < rum/static
(rum/defc page-graph-inner < rum/reactive
[_page graph dark?]
(let [ show-journals-in-page-graph? (rum/react *show-journals-in-page-graph?) ]
[:div.sidebar-item.flex-col
[:div.flex.items-center.justify-between.mb-0
[:span (t :right-side-bar/show-journals)]
[:div.mt-1
(ui/toggle show-journals-in-page-graph? ;my-val;
(fn []
(let [value (not show-journals-in-page-graph?)]
(reset! *show-journals-in-page-graph? value)
))
true)]
]
(graph/graph-2d {:nodes (:nodes graph)
:links (:links graph)
:width 600
@@ -640,7 +653,7 @@
:dark? dark?
:register-handlers-fn
(fn [graph]
(graph-register-handlers graph (atom nil) (atom nil) dark?))})])
(graph-register-handlers graph (atom nil) (atom nil) dark?))})]))
(rum/defc page-graph < db-mixins/query rum/reactive
[]
@@ -650,9 +663,10 @@
(date/today))
theme (:ui/theme @state/state)
dark? (= theme "dark")
show-journals-in-page-graph (rum/react *show-journals-in-page-graph?)
graph (if (util/uuid-string? page)
(graph-handler/build-block-graph (uuid page) theme)
(graph-handler/build-page-graph page theme))]
(graph-handler/build-page-graph page theme show-journals-in-page-graph))]
(when (seq (:nodes graph))
(page-graph-inner page graph dark?))))

View File

@@ -1120,18 +1120,23 @@
;; get pages who mentioned this page
;; TODO: use :block/_refs
(defn get-pages-that-mentioned-page
[repo page]
[repo page include-journals]
(when (conn/get-db repo)
(let [page-id (:db/id (db-utils/entity [:block/name (util/safe-page-name-sanity-lc page)]))
pages (page-alias-set repo page)
query-base '[:find ?mentioned-page-name
:in $ ?pages ?page-name
:where
[?block :block/refs ?p]
[(contains? ?pages ?p)]
[?block :block/page ?mentioned-page]
[?mentioned-page :block/name ?mentioned-page-name]]
query (if include-journals
query-base
(conj query-base '[?mentioned-page :block/journal? false]))
mentioned-pages (->> (react/q repo [:frontend.db.react/page<-pages page-id] {:use-cache? false}
'[:find ?mentioned-page-name
:in $ ?pages ?page-name
:where
[?block :block/refs ?p]
[(contains? ?pages ?p)]
[?block :block/page ?mentioned-page]
[?mentioned-page :block/name ?mentioned-page-name]]
query
pages
page)
react

View File

@@ -68,6 +68,7 @@
:right-side-bar/all-pages "All pages"
:right-side-bar/flashcards "Flashcards"
:right-side-bar/new-page "New page"
:right-side-bar/show-journals "Show Journals"
:left-side-bar/journals "Journals"
:left-side-bar/new-page "New page"
:left-side-bar/nav-favorites "Favorites"
@@ -3204,6 +3205,7 @@
:right-side-bar/all-pages "Tutte le pagine"
:right-side-bar/flashcards "Flashcard"
:right-side-bar/new-page "Nuova pagina"
:right-side-bar/show-journals "Mostra diari"
:left-side-bar/journals "Diario"
:left-side-bar/new-page "Nuova pagina"
:left-side-bar/nav-favorites "Preferiti"

View File

@@ -120,7 +120,7 @@
:page-name->original-name page-name->original-name})))))
(defn build-page-graph
[page theme]
[page theme show-journal]
(let [dark? (= "dark" theme)]
(when-let [repo (state/get-current-repo)]
(let [page (util/page-name-sanity-lc page)
@@ -128,7 +128,7 @@
tags (:tags (:block/properties page-entity))
tags (remove #(= page %) tags)
ref-pages (db/get-page-referenced-pages repo page)
mentioned-pages (db/get-pages-that-mentioned-page repo page)
mentioned-pages (db/get-pages-that-mentioned-page repo page show-journal)
namespaces (db/get-all-namespace-relation repo)
links (concat
namespaces
@@ -148,7 +148,7 @@
(let [ref-pages (-> (map first (db/get-page-referenced-pages repo page))
(set)
(set/intersection other-pages))
mentioned-pages (-> (map first (db/get-pages-that-mentioned-page repo page))
mentioned-pages (-> (map first (db/get-pages-that-mentioned-page repo page show-journal))
(set)
(set/intersection other-pages))]
(concat

View File

@@ -82,4 +82,33 @@
;; 1 (count a-ref-blocks)
;; (set ["b" "c"]) (set alias-names))))
(deftest ^:focus get-pages-that-mentioned-page-with-show-journal
(load-test-files [{:file/path "journals/2020_08_15.md"
:file/content "link 1 to [[page ONE]] and link to [[generic page]]"}
{:file/path "journals/2020_09_18.md"
:file/content "link 2 to [[page ONE]]"}
{:file/path "pages/page ONE.md"
:file/content "tags:: a tag
- page one has link to [[Dec 26th, 2020]] journal page"}
{:file/path "pages/a tag.md"
:file/content "i'm a tag"}
{:file/path "pages/generic page.md"
:file/content "- link to page one [[page ONE]]"}])
(is (= '("sep 18th, 2020" "aug 15th, 2020" "generic page")
(map first (model/get-pages-that-mentioned-page test-helper/test-db "page ONE" true)))
"Must be 'generic page' + 2 journals")
(is (= '("generic page")
(map first (model/get-pages-that-mentioned-page test-helper/test-db "page ONE" false)))
"Must be only 'generic page'")
(is (= '("aug 15th, 2020")
(map first (model/get-pages-that-mentioned-page test-helper/test-db "generic page" true)))
"Must show only 'aug 15th, 2020'")
(is (= '()
(map first (model/get-pages-that-mentioned-page test-helper/test-db "generic page" false)))
"Must be empty"))
#_(cljs.test/test-ns 'frontend.db.model-test)