Jelajahi Sumber

fix: Make bare graph valid for file graph import

Fixed blocks, pages and config.edn as part of LOG-2990
Gabriel Horner 2 tahun lalu
induk
melakukan
6e911798e7

+ 18 - 15
deps/graph-parser/src/logseq/graph_parser.cljs

@@ -8,7 +8,8 @@
             [logseq.graph-parser.config :as gp-config]
             [logseq.graph-parser.config :as gp-config]
             [logseq.graph-parser.date-time-util :as date-time-util]
             [logseq.graph-parser.date-time-util :as date-time-util]
             [logseq.graph-parser.extract :as extract]
             [logseq.graph-parser.extract :as extract]
-            [logseq.graph-parser.util :as gp-util]))
+            [logseq.graph-parser.util :as gp-util]
+            [logseq.db.sqlite.util :as sqlite-util]))
 
 
 (defn- retract-blocks-tx
 (defn- retract-blocks-tx
   [blocks retain-uuids]
   [blocks retain-uuids]
@@ -172,7 +173,8 @@ Options available:
                                   (seq))
                                   (seq))
                  ;; To prevent "unique constraint" on datascript
                  ;; To prevent "unique constraint" on datascript
               block-ids (set/union (set block-ids) (set block-refs-ids))
               block-ids (set/union (set block-ids) (set block-refs-ids))
-              pages (extract/with-ref-pages pages blocks)
+              pages (map #(-> % sqlite-util/block-with-timestamps (assoc :block/format :markdown))
+                         (extract/with-ref-pages pages blocks))
 
 
               ;; post-handling
               ;; post-handling
               whiteboard-pages (->> pages
               whiteboard-pages (->> pages
@@ -187,19 +189,20 @@ Options available:
                             (into {} (remove (comp pred key) m)))
                             (into {} (remove (comp pred key) m)))
               blocks (map (fn [block]
               blocks (map (fn [block]
                             (prn ::block block)
                             (prn ::block block)
-                            (cond
-                              (:block/pre-block? block)
-                              block
-
-                              :else
-                              (update-in block [:block/properties]
-                                         (fn [props]
-                                           (-> props
-                                               (update-keys (fn [k]
-                                                              (if-let [new-key (get-pid @conn k)]
-                                                                new-key
-                                                                k)))
-                                               (remove-keys keyword?))))))
+                            (sqlite-util/block-with-timestamps
+                             (cond
+                               (:block/pre-block? block)
+                               block
+
+                               :else
+                               (update-in block [:block/properties]
+                                          (fn [props]
+                                            (-> props
+                                                (update-keys (fn [k]
+                                                               (if-let [new-key (get-pid @conn k)]
+                                                                 new-key
+                                                                 k)))
+                                                (remove-keys keyword?)))))))
                           blocks)
                           blocks)
 
 
 
 

+ 3 - 2
src/main/frontend/components/imports.cljs

@@ -4,6 +4,7 @@
             [clojure.core.async :as async]
             [clojure.core.async :as async]
             [clojure.edn :as edn]
             [clojure.edn :as edn]
             [clojure.string :as string]
             [clojure.string :as string]
+            [datascript.core :as d]
             [frontend.components.onboarding.setups :as setups]
             [frontend.components.onboarding.setups :as setups]
             [frontend.components.repo :as repo]
             [frontend.components.repo :as repo]
             [frontend.components.svg :as svg]
             [frontend.components.svg :as svg]
@@ -20,7 +21,6 @@
             [frontend.ui :as ui]
             [frontend.ui :as ui]
             [frontend.util :as util]
             [frontend.util :as util]
             [frontend.util.fs :as fs-util]
             [frontend.util.fs :as fs-util]
-            [frontend.util.text :as text-util]
             [goog.functions :refer [debounce]]
             [goog.functions :refer [debounce]]
             [goog.object :as gobj]
             [goog.object :as gobj]
             [logseq.common.path :as path]
             [logseq.common.path :as path]
@@ -211,7 +211,8 @@
       (p/then (fn [content]
       (p/then (fn [content]
                 (when content
                 (when content
                   (p/do!
                   (p/do!
-                   (db-editor-handler/save-file! "logseq/config.edn" content))
+                   (db-editor-handler/save-file! "logseq/config.edn" content)
+                   (db/transact! [{:file/path "logseq/config.edn" :block/uuid (d/squuid)}]))
                   (edn/read-string content))))))
                   (edn/read-string content))))))
 
 
 
 

+ 3 - 2
src/main/frontend/handler/repo.cljs

@@ -558,8 +558,9 @@
            _ (op-mem-layer/<init-load-from-indexeddb! full-graph-name)
            _ (op-mem-layer/<init-load-from-indexeddb! full-graph-name)
            _ (start-repo-db-if-not-exists! full-graph-name)
            _ (start-repo-db-if-not-exists! full-graph-name)
            _ (state/add-repo! {:url full-graph-name})
            _ (state/add-repo! {:url full-graph-name})
-           initial-data (sqlite-create-graph/build-db-initial-data config/config-default-content)
-           _ (db/transact! full-graph-name initial-data)
+          ;; TODO: Enable initial-data without it being invalid
+          ;;  initial-data (sqlite-create-graph/build-db-initial-data config/config-default-content)
+          ;;  _ (db/transact! full-graph-name initial-data)
            _ (repo-config-handler/set-repo-config-state! full-graph-name config/config-default-content)
            _ (repo-config-handler/set-repo-config-state! full-graph-name config/config-default-content)
           ;; TODO: handle global graph
           ;; TODO: handle global graph
            _ (state/pub-event! [:init/commands])]
            _ (state/pub-event! [:init/commands])]