fix: exclude-from-graph-view and public properties

Hide them as no need to see them by default but still need to be
accessible to modify. public's queries hadn't been updated to work with db graph yet
pull/10438/head
Gabriel Horner 2023-09-20 09:26:36 -04:00
parent e052c2894a
commit 6cf19c60f8
3 changed files with 51 additions and 10 deletions

View File

@ -60,9 +60,11 @@
:icon {:original-name "Icon"
:schema {:type :map}}
:public {:schema {:type :checkbox}}
:public {:schema {:type :checkbox :hide? true}
:visible true}
:filters {:schema {:type :map}}
:exclude-from-graph-view {:schema {:type :checkbox}}
:exclude-from-graph-view {:schema {:type :checkbox :hide? true}
:visible true}
:created-in-property {:schema {:type :checkbox}}})
(def visible-built-in-properties

View File

@ -37,6 +37,45 @@
db)
(map first)))
(defn- get-db-public-pages
"Returns public pages and anything they are directly related to: their tags,
their properties and any property values that are pages. Anything on the
related pages are _not_ included e.g. properties on tag or property pages"
[db]
(let [pages (->> (d/q
'[:find ?p
:in $ %
:where (page-property ?p :public true)]
db
(rules/extract-rules rules/db-query-dsl-rules [:page-property]))
(map first)
set)
page-ents (map #(d/entity db %) pages)
tag-pages* (mapcat #(map :db/id (:block/tags %)) page-ents)
tag-pages (concat tag-pages*
;; built-in property needs to be public to display tags
(when (seq tag-pages*)
(some-> (d/entity db [:block/name "tags"]) :db/id vector)))
property-pages (mapcat (fn [ent]
(let [props (:block/properties ent)]
(->> (keys props)
(into (mapcat #(filter uuid? (if (coll? %) % [%]))
(vals props)))
(map #(:db/id (d/entity db [:block/uuid %]))))))
page-ents)]
(concat pages tag-pages property-pages)))
(defn- get-db-public-false-pages
[db]
(->> (d/q
'[:find ?p
:in $ %
:where (page-property ?p :public false)]
db
(rules/extract-rules rules/db-query-dsl-rules [:page-property]))
(map first)
set))
(defn- get-public-false-pages
[db]
(->> (d/q
@ -113,11 +152,11 @@
(defn clean-export!
"Prepares a database assuming all pages are public unless a page has a 'public:: false'"
[db]
[db {:keys [db-graph?]}]
(let [remove? #(contains? #{"recent" "file"} %)
non-public-pages (get-public-false-pages db)
non-public-datoms (get-public-false-block-ids db)
non-public-datom-ids (set (concat non-public-pages non-public-datoms))
non-public-datom-ids (if db-graph?
(get-db-public-false-pages db)
(set (concat (get-public-false-pages db) (get-public-false-block-ids db))))
filtered-db (d/filter db
(fn [_db datom]
(let [ns (namespace (:a datom))]
@ -130,8 +169,8 @@
(defn filter-only-public-pages-and-blocks
"Prepares a database assuming all pages are private unless a page has a 'public:: true'"
[db]
(when-let [public-pages* (seq (get-public-pages db))]
[db {:keys [db-graph?]}]
(when-let [public-pages* (seq (if db-graph? (get-db-public-pages db) (get-public-pages db)))]
(let [public-pages (set/union (set public-pages*)
(get-aliases-for-page-ids db public-pages*))
exported-namespace? #(contains? #{"block" "recent"} %)

View File

@ -137,8 +137,8 @@ generated index.html string and assets used by the html"
val
(:all-pages-public? repo-config))
[db asset-filenames'] (if all-pages-public?
(db/clean-export! db*)
(db/filter-only-public-pages-and-blocks db*))
(db/clean-export! db* {:db-graph? db-graph?})
(db/filter-only-public-pages-and-blocks db* {:db-graph? db-graph?}))
asset-filenames (remove nil? asset-filenames')
db-str (dt/write-transit-str db)