|
|
@@ -8,8 +8,7 @@
|
|
|
[frontend.ui :as ui]
|
|
|
[medley.core :as medley]
|
|
|
[rum.core :as rum]
|
|
|
- [frontend.util :as util]
|
|
|
- [frontend.config :as config]))
|
|
|
+ [frontend.util :as util]))
|
|
|
|
|
|
(defn- get-relation
|
|
|
"Get all parent pages along the namespace hierarchy path.
|
|
|
@@ -44,62 +43,25 @@
|
|
|
:else
|
|
|
nil))))))
|
|
|
|
|
|
-(rum/defc page-children
|
|
|
- [page-id parent-children-map namespace-page-map options]
|
|
|
- [:.ml-4.mb-2
|
|
|
- {:key (str "page-children-" page-id)}
|
|
|
- (->> (parent-children-map page-id)
|
|
|
- (sort-by #(get-in namespace-page-map [% :block/original-name]))
|
|
|
- (map #(let [child-name (get-in namespace-page-map [% :block/original-name])]
|
|
|
- (if (seq (parent-children-map %))
|
|
|
- (ui/foldable (block/page-reference false child-name {} child-name)
|
|
|
- (page-children % parent-children-map namespace-page-map options)
|
|
|
- (select-keys options [:default-collapsed?]))
|
|
|
- [:div
|
|
|
- (block/page-reference false child-name {} child-name)]))))])
|
|
|
-
|
|
|
-(rum/defc db-version-hierarchy
|
|
|
- [page namespace-pages]
|
|
|
- (let [parent-children-map (reduce (fn [acc m]
|
|
|
- (update acc
|
|
|
- (get-in m [:block/namespace :db/id])
|
|
|
- (fnil conj [])
|
|
|
- (:db/id m)))
|
|
|
- {}
|
|
|
- namespace-pages)
|
|
|
- namespace-page-map (into {} (map (juxt :db/id identity) namespace-pages))
|
|
|
- page-id (:db/id (db/entity [:block/name (util/page-name-sanity-lc page)]))
|
|
|
- ;; Expand children if there are about a page-ful of total blocks to display
|
|
|
- default-collapsed? (> (count namespace-pages) 30)]
|
|
|
- [:div.page-hierarchy.mt-6
|
|
|
- (ui/foldable
|
|
|
- [:h2.font-bold.opacity-30 (str "Hierarchy (" (count namespace-pages) ")")]
|
|
|
- [:div.p-4
|
|
|
- (page-children page-id parent-children-map namespace-page-map {:default-collapsed? default-collapsed?})]
|
|
|
- {:default-collapsed? false
|
|
|
- :title-trigger? true})]))
|
|
|
-
|
|
|
(rum/defc structures
|
|
|
[page]
|
|
|
- (let [{:keys [namespaces namespace-pages]} (get-relation page)]
|
|
|
+ (let [{:keys [namespaces]} (get-relation page)]
|
|
|
(when (seq namespaces)
|
|
|
- (if (config/db-based-graph? (state/get-current-repo))
|
|
|
- (db-version-hierarchy page namespace-pages)
|
|
|
- [:div.page-hierarchy.mt-6
|
|
|
- (ui/foldable
|
|
|
- [:h2.font-bold.opacity-30 "Hierarchy"]
|
|
|
- [:ul.namespaces {:style {:margin "12px 24px"}}
|
|
|
- (for [namespace namespaces]
|
|
|
- [:li.my-2
|
|
|
- (->>
|
|
|
- (for [[idx page] (medley/indexed namespace)]
|
|
|
- (when (and (string? page) page)
|
|
|
- (let [full-page (->> (take (inc idx) namespace)
|
|
|
- util/string-join-path)]
|
|
|
- (block/page-reference false
|
|
|
- full-page
|
|
|
- {}
|
|
|
- page))))
|
|
|
- (interpose [:span.mx-2.opacity-30 "/"]))])]
|
|
|
- {:default-collapsed? false
|
|
|
- :title-trigger? true})]))))
|
|
|
+ [:div.page-hierarchy.mt-6
|
|
|
+ (ui/foldable
|
|
|
+ [:h2.font-bold.opacity-30 "Hierarchy"]
|
|
|
+ [:ul.namespaces {:style {:margin "12px 24px"}}
|
|
|
+ (for [namespace namespaces]
|
|
|
+ [:li.my-2
|
|
|
+ (->>
|
|
|
+ (for [[idx page] (medley/indexed namespace)]
|
|
|
+ (when (and (string? page) page)
|
|
|
+ (let [full-page (->> (take (inc idx) namespace)
|
|
|
+ util/string-join-path)]
|
|
|
+ (block/page-reference false
|
|
|
+ full-page
|
|
|
+ {}
|
|
|
+ page))))
|
|
|
+ (interpose [:span.mx-2.opacity-30 "/"]))])]
|
|
|
+ {:default-collapsed? false
|
|
|
+ :title-trigger? true})])))
|