diff --git a/deps/graph-parser/package.json b/deps/graph-parser/package.json index 97780b5c4b..cd269ea842 100644 --- a/deps/graph-parser/package.json +++ b/deps/graph-parser/package.json @@ -10,6 +10,6 @@ "mldoc": "^1.5.8" }, "scripts": { - "test": "nbb-logseq -cp test -m nextjournal.test-runner" + "test": "nbb-logseq -cp test:../outliner/src -m nextjournal.test-runner" } } diff --git a/deps/graph-parser/src/logseq/graph_parser/exporter.cljs b/deps/graph-parser/src/logseq/graph_parser/exporter.cljs index 702a0ccb74..3b09b1bc28 100644 --- a/deps/graph-parser/src/logseq/graph_parser/exporter.cljs +++ b/deps/graph-parser/src/logseq/graph_parser/exporter.cljs @@ -159,12 +159,10 @@ (assoc :logseq.task/status status-ident) (update :block/content string/replace-first (re-pattern (str marker "\\s*")) "") (update :block/tags (fnil conj []) :logseq.class/task) + ;; FIXME: block/refs property calculation should be handled by a listener (update :block/refs (fn [refs] (into (remove #(= marker (:block/original-name %)) refs) - [:logseq.class/task :logseq.task/status status-ident]))) - (update :block/path-refs (fn [refs] - (into (remove #(= marker (:block/original-name %)) refs) - [:logseq.class/task :logseq.task/status status-ident]))) + [:logseq.class/task :logseq.task/status]))) (dissoc :block/marker))) block)) @@ -181,12 +179,10 @@ (-> block (assoc :logseq.task/priority priority-value) (update :block/content string/replace-first (re-pattern (str "\\[#" priority "\\]" "\\s*")) "") + ;; FIXME: block/refs property calculation should be handled by a listener (update :block/refs (fn [refs] (into (remove #(= priority (:block/original-name %)) refs) - [:logseq.task/priority priority-value]))) - (update :block/path-refs (fn [refs] - (into (remove #(= priority (:block/original-name %)) refs) - [:logseq.task/priority priority-value]))) + [:logseq.task/priority]))) (dissoc :block/priority))) block)) @@ -212,7 +208,6 @@ (-> block (assoc :logseq.task/deadline [:block/uuid (:block/uuid deadline-page)]) (update :block/refs (fnil into []) [:logseq.task/deadline [:block/uuid (:block/uuid deadline-page)]]) - (update :block/path-refs (fnil into []) [:logseq.task/deadline [:block/uuid (:block/uuid deadline-page)]]) (dissoc :block/deadline :block/scheduled :block/repeated?)) :properties-tx (when-not existing-journal-page [deadline-page])}) {:block block :properties-tx []})) @@ -573,10 +568,7 @@ (cond-> block (and (seq property-classes) (seq (:block/refs block*))) ;; remove unused, nonexistent property page - (update :block/refs (fn [refs] (remove #(property-classes (keyword (:block/name %))) refs))) - (and (seq property-classes) (seq (:block/path-refs block*))) - ;; remove unused, nonexistent property page - (update :block/path-refs (fn [refs] (remove #(property-classes (keyword (:block/name %))) refs)))) + (update :block/refs (fn [refs] (remove #(property-classes (keyword (:block/name %))) refs)))) :properties-tx properties-tx})) (defn- update-block-refs @@ -905,7 +897,7 @@ {:keys [property-pages-tx property-page-properties-tx] pages-tx' :pages-tx} (split-pages-and-properties-tx pages-tx old-properties existing-pages (:import-state options)) ;; Necessary to transact new property entities first so that block+page properties can be transacted next - main-props-tx-report (d/transact! conn property-pages-tx) + main-props-tx-report (d/transact! conn property-pages-tx {:new-graph? true}) ;; Build indices pages-index (map #(select-keys % [:block/uuid]) pages-tx') @@ -922,11 +914,12 @@ tx (concat whiteboard-pages pages-index page-properties-tx property-page-properties-tx pages-tx' blocks-index blocks-tx) tx' (common-util/fast-remove-nils tx) ;; _ (when (not (seq whiteboard-pages)) (cljs.pprint/pprint {:tx tx'})) - main-tx-report (d/transact! conn tx') + ;; :new-graph? needed for :block/path-refs to be calculated + main-tx-report (d/transact! conn tx' {:new-graph? true}) upstream-properties-tx (build-upstream-properties-tx @conn @(:upstream-properties tx-options) (:import-state options) log-fn) - upstream-tx-report (when (seq upstream-properties-tx) (d/transact! conn upstream-properties-tx))] + upstream-tx-report (when (seq upstream-properties-tx) (d/transact! conn upstream-properties-tx {:new-graph? true}))] ;; Return all tx-reports that occurred in this fn as UI needs to know what changed [main-props-tx-report main-tx-report upstream-tx-report])) diff --git a/deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs b/deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs index 9403682085..a629b3f5fa 100644 --- a/deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs +++ b/deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs @@ -4,6 +4,7 @@ [logseq.graph-parser.test.docs-graph-helper :as docs-graph-helper] [datascript.core :as d] [clojure.string :as string] + [clojure.set :as set] ["path" :as node-path] ["fs" :as fs] [logseq.common.graph :as common-graph] @@ -16,7 +17,8 @@ [logseq.db.frontend.property :as db-property] [logseq.db.frontend.property.type :as db-property-type] [logseq.common.config :as common-config] - [logseq.db :as ldb])) + [logseq.db :as ldb] + [logseq.outliner.db-pipeline :as db-pipeline])) ;; Helpers ;; ======= @@ -149,6 +151,8 @@ (p/let [file-graph-dir "test/resources/exporter-test-graph" conn (d/create-conn db-schema/schema-for-db-based-graph) _ (d/transact! conn (sqlite-create-graph/build-db-initial-data "{}")) + ;; Simulate frontend path-refs being calculated + _ (db-pipeline/add-listener conn) assets (atom []) {:keys [import-state]} (import-file-graph-to-db file-graph-dir conn {:assets assets})] @@ -338,6 +342,23 @@ count)) "A block with different case of same ref names has 1 distinct ref")) + (testing "block refs and path-refs" + (let [block (find-block-by-content @conn "old todo block")] + (is (set/subset? + #{:logseq.task/status :logseq.class/task} + (->> block + :block/path-refs + (map #(:db/ident (d/entity @conn (:db/id %)))) + set)) + "Correct :block/refs") + (is (set/subset? + #{:logseq.task/status :logseq.class/task} + (->> block + :block/path-refs + (map #(:db/ident (d/entity @conn (:db/id %)))) + set)) + "Correct :block/path-refs"))) + (testing "whiteboards" (let [block-with-props (find-block-by-content @conn #"block with props")] (is (= {:user.property/prop-num 10}