Skip to content

Commit

Permalink
fix: importer importing some pages as both Tag and Page
Browse files Browse the repository at this point in the history
Also fixed using pages as a tag first time via '#' didn't build tx correctly.
Fixing these allowed for enabling logseq.class/Page validation
  • Loading branch information
logseq-cldwalker committed Jan 2, 2025
1 parent 3d42cf7 commit b7723db
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 21 deletions.
5 changes: 5 additions & 0 deletions deps/db/src/logseq/db/frontend/class.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
(when (= (get-in m [:properties :logseq.property/parent]) :logseq.class/Page) class-ident))
built-in-classes)))

(def page-classes
"Built-in classes that behave like a page. Classes should match entity-util/page?"
(into #{:logseq.class/Page :logseq.class/Tag :logseq.class/Property}
page-children-classes))

(def internal-tags
"Built-in classes that are hidden on a node and all pages view"
#{:logseq.class/Page :logseq.class/Property :logseq.class/Tag :logseq.class/Root
Expand Down
10 changes: 5 additions & 5 deletions deps/db/src/logseq/db/frontend/malli_schema.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
;; properties in their schema that they depend on
(let [exceptions-to-block-properties (conj required-properties :block/tags)
page-class-id (:db/id (d/entity db :logseq.class/Page))
private-tag-ids (set (map #(:db/id (d/entity db %)) db-class/private-tags))]
all-page-class-ids (set (map #(:db/id (d/entity db %)) db-class/page-classes))]
(mapv
(fn [ent]
(reduce (fn [m [k v]]
Expand All @@ -149,7 +149,7 @@
v
(merge (select-keys ent [:logseq.property/built-in?])
{:page-class-id page-class-id
:private-tag-ids private-tag-ids})]))
:all-page-class-ids all-page-class-ids})]))
(assoc m k v))))
{}
ent))
Expand Down Expand Up @@ -238,10 +238,10 @@
true))]
;; Ensure use of :logseq.class/Page is consistent and simple. Doing so reduces complexity elsewhere
;; and allows for Page to exist as its own public concept later
#_[:fn {:error/message "should not have other built-in private tags when tagged with #Page"}
(fn [[_k v {:keys [page-class-id private-tag-ids]}]]
[:fn {:error/message "should not have other built-in page tags when tagged with #Page"}
(fn [[_k v {:keys [page-class-id all-page-class-ids]}]]
(if (contains? v page-class-id)
(empty? (set/intersection (disj v page-class-id) private-tag-ids))
(empty? (set/intersection (disj v page-class-id) all-page-class-ids))
true))]])

(def page-or-block-attrs
Expand Down
21 changes: 13 additions & 8 deletions deps/graph-parser/src/logseq/graph_parser/exporter.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,20 @@
;; Ignore new class tags from extract e.g. :logseq.class/Journal
(logseq-class-ident? %)))
(map #(vector :block/uuid (get-page-uuid (:page-names-to-uuids per-file-state) (:block/name %) {:block %})))
set)
page-classes (into #{:logseq.class/Page} db-class/page-children-classes)]
set)]
(cond-> block
true
(update :block/tags convert-tags-to-classes db per-file-state user-options all-idents)
;; ensure pages are a Page
true
(update :block/tags (fn [tags]
(if (seq (set/intersection (set tags) page-classes))
tags
(conj (vec tags) :logseq.class/Page))))
(cond-> (set tags)
;; ensure pages at least have a Page
true
(conj :logseq.class/Page)
;; Remove Page if another Page-like class is already present
(seq (set/intersection (disj (set tags) :logseq.class/Page)
db-class/page-classes))
(disj :logseq.class/Page))))
(seq page-tags)
(merge {:logseq.property/page-tags page-tags})))
block))
Expand Down Expand Up @@ -1343,8 +1346,10 @@
;; uuids to be valid. Also upstream-properties-tx comes after blocks-tx to possibly override blocks
tx (concat whiteboard-pages pages-index page-properties-tx property-page-properties-tx pages-tx'' classes-tx' blocks-index blocks-tx)
tx' (common-util/fast-remove-nils tx)
;; _ (prn :tx-counts (map count (vector whiteboard-pages pages-index page-properties-tx property-page-properties-tx pages-tx' classes-tx blocks-index blocks-tx)))
;; _ (when (not (seq whiteboard-pages)) (cljs.pprint/pprint {#_:property-pages-tx #_property-pages-tx :tx tx'}))
;; (prn :tx-counts (map #(vector %1 (count %2))
;; [:whiteboard-pages :pages-index :page-properties-tx :property-page-properties-tx :pages-tx' :classes-tx :blocks-index :blocks-tx]
;; [whiteboard-pages pages-index page-properties-tx property-page-properties-tx pages-tx' classes-tx blocks-index blocks-tx]))
;; _ (when (not (seq whiteboard-pages)) (cljs.pprint/pprint {#_:property-pages-tx #_property-pages-tx :pages-tx pages-tx :tx tx'}))
main-tx-report (d/transact! conn tx' {::new-graph? true})

upstream-properties-tx
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/background_tasks.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
(m/reduce
(fn [_ repo]
(when (some? repo)
(prn :reset-immutable-entities-cache!)
;; (prn :reset-immutable-entities-cache!)
(entity-plus/reset-immutable-entities-cache!)))
flows/current-repo-flow))
3 changes: 1 addition & 2 deletions src/main/frontend/components/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@
#{:logseq.class/Tag}
;; Page existence here should be the same as entity-util/page?.
;; Don't show 'New page' if a page has any of these tags
(into #{:logseq.class/Page :logseq.class/Tag :logseq.class/Property}
db-class/page-children-classes)))
db-class/page-classes))
(and db-tag? (some ldb/class? (:block/_alias (db/get-page q)))))
partial-matched-pages
(if db-tag?
Expand Down
3 changes: 0 additions & 3 deletions src/main/frontend/worker/db/migrate.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,6 @@
;; don't have :block/type indexed
datoms (->> (d/datoms db :eavt)
(filter (fn [d] (= :block/type (:a d)))))
journal-entity (d/entity db :logseq.class/Journal)
tx-data (mapcat (fn [{:keys [e _a v]}]
(let [tag (case v
"page" :logseq.class/Page
Expand All @@ -445,8 +444,6 @@
(some? tag)
(conj [:db/add e :block/tags tag])))) datoms)]
(concat
;; set journal's tag to `#Page`
[[:db/add (:db/id journal-entity) :block/tags :logseq.class/Page]]
tx-data
(when block-type-entity
[[:db/retractEntity (:db/id block-type-entity)]]))))
Expand Down
5 changes: 3 additions & 2 deletions src/main/frontend/worker/handler/page/db_based/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
(let [date-formatter (:logseq.property.journal/title-format (entity-plus/entity-memoized db :logseq.class/Journal))
title (sanitize-title title*)
types (cond class?
#{:logseq.class/Tag}
#{:logseq.class/Tag :logseq.class/Page}
whiteboard?
#{:logseq.class/Whiteboard}
today-journal?
Expand All @@ -187,7 +187,8 @@
(not (ldb/class? existing-page))
(or (ldb/property? existing-page) (ldb/internal-page? existing-page)))
;; Convert existing user property or page to class
(let [tx-data (db-class/build-new-class db (select-keys existing-page [:block/title :block/uuid :db/ident :block/created-at]))]
(let [tx-data [(db-class/build-new-class db (select-keys existing-page [:block/title :block/uuid :db/ident :block/created-at]))
[:db/retract [:block/uuid (:block/uuid existing-page)] :block/tags :logseq.class/Page]]]
{:tx-meta tx-meta
:tx-data tx-data})))
(let [format :markdown
Expand Down

0 comments on commit b7723db

Please sign in to comment.