From b7723db753e07859bff0bf94a0e9c1b436fbf6dd Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Thu, 2 Jan 2025 17:18:29 -0500 Subject: [PATCH] fix: importer importing some pages as both Tag and Page Also fixed using pages as a tag first time via '#' didn't build tx correctly. Fixing these allowed for enabling logseq.class/Page validation --- deps/db/src/logseq/db/frontend/class.cljs | 5 +++++ .../src/logseq/db/frontend/malli_schema.cljs | 10 ++++----- .../src/logseq/graph_parser/exporter.cljs | 21 ++++++++++++------- src/main/frontend/background_tasks.cljs | 2 +- src/main/frontend/components/editor.cljs | 3 +-- src/main/frontend/worker/db/migrate.cljs | 3 --- .../worker/handler/page/db_based/page.cljs | 5 +++-- 7 files changed, 28 insertions(+), 21 deletions(-) diff --git a/deps/db/src/logseq/db/frontend/class.cljs b/deps/db/src/logseq/db/frontend/class.cljs index 201ffef9c59..2bbf76be0c3 100644 --- a/deps/db/src/logseq/db/frontend/class.cljs +++ b/deps/db/src/logseq/db/frontend/class.cljs @@ -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 diff --git a/deps/db/src/logseq/db/frontend/malli_schema.cljs b/deps/db/src/logseq/db/frontend/malli_schema.cljs index 1a4abdcb37e..decc3084b7a 100644 --- a/deps/db/src/logseq/db/frontend/malli_schema.cljs +++ b/deps/db/src/logseq/db/frontend/malli_schema.cljs @@ -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]] @@ -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)) @@ -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 diff --git a/deps/graph-parser/src/logseq/graph_parser/exporter.cljs b/deps/graph-parser/src/logseq/graph_parser/exporter.cljs index 978aeb6aa6c..b5246f199f2 100644 --- a/deps/graph-parser/src/logseq/graph_parser/exporter.cljs +++ b/deps/graph-parser/src/logseq/graph_parser/exporter.cljs @@ -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)) @@ -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 diff --git a/src/main/frontend/background_tasks.cljs b/src/main/frontend/background_tasks.cljs index 743c0cd11b4..94b5f6af7f7 100644 --- a/src/main/frontend/background_tasks.cljs +++ b/src/main/frontend/background_tasks.cljs @@ -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)) diff --git a/src/main/frontend/components/editor.cljs b/src/main/frontend/components/editor.cljs index 73947e5143c..757fbaad6e8 100644 --- a/src/main/frontend/components/editor.cljs +++ b/src/main/frontend/components/editor.cljs @@ -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? diff --git a/src/main/frontend/worker/db/migrate.cljs b/src/main/frontend/worker/db/migrate.cljs index 29c44899b98..ba66233be5b 100644 --- a/src/main/frontend/worker/db/migrate.cljs +++ b/src/main/frontend/worker/db/migrate.cljs @@ -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 @@ -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)]])))) diff --git a/src/main/frontend/worker/handler/page/db_based/page.cljs b/src/main/frontend/worker/handler/page/db_based/page.cljs index fd0a885d0df..133b4f247c9 100644 --- a/src/main/frontend/worker/handler/page/db_based/page.cljs +++ b/src/main/frontend/worker/handler/page/db_based/page.cljs @@ -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? @@ -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