hierarchy.cljs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. (ns frontend.components.hierarchy
  2. (:require [frontend.search :as search]
  3. [clojure.string :as string]
  4. [frontend.components.block :as block]
  5. [rum.core :as rum]
  6. [frontend.ui :as ui]
  7. [medley.core :as medley]
  8. [frontend.db :as db]
  9. [frontend.state :as state]
  10. [frontend.text :as text]))
  11. ;; FIXME: use block/namespace to get the relation
  12. (defn get-relation
  13. [page]
  14. (when (text/namespace-page? page)
  15. (->> (db/get-namespace-pages (state/get-current-repo) page)
  16. (map (fn [page]
  17. (or (:block/original-name page) (:block/name page))))
  18. (map #(string/split % #"/"))
  19. (remove #(= % [page]))
  20. (sort))))
  21. (rum/defc structures
  22. [page]
  23. (let [namespaces (get-relation page)]
  24. (when (and (seq namespaces)
  25. (not (and (= 1
  26. (count namespaces)
  27. (count (first namespaces)))
  28. (not (string/includes? (ffirst namespaces) "/")))))
  29. [:div.page-hierachy.mt-6
  30. (ui/foldable
  31. [:h2.font-bold.opacity-30 "Hierarchy"]
  32. [:ul.namespaces {:style {:margin "12px 24px"}}
  33. (for [namespace namespaces]
  34. [:li.my-2
  35. (->>
  36. (for [[idx page] (medley/indexed namespace)]
  37. (when (and (string? page) page)
  38. (let [full-page (->> (take (inc idx) namespace)
  39. (string/join "/"))]
  40. (block/page-reference false
  41. full-page
  42. {}
  43. page))))
  44. (interpose [:span.mx-2.opacity-30 "/"]))])]
  45. true)])))