فهرست منبع

fix: enable built-in properties for file graph import

invalid built-in properties were being created by the bug in LOG-2998.
Also cleaned up TODO around reusing new-db!
Part of LOG-2990
Gabriel Horner 2 سال پیش
والد
کامیت
2861337bab
2فایلهای تغییر یافته به همراه9 افزوده شده و 40 حذف شده
  1. 2 3
      src/main/frontend/components/imports.cljs
  2. 7 37
      src/main/frontend/handler/repo.cljs

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

@@ -211,8 +211,7 @@
       (p/then (fn [content]
                 (when content
                   (p/do!
-                   (db-editor-handler/save-file! "logseq/config.edn" content)
-                   (db/transact! [{:file/path "logseq/config.edn" :block/uuid (d/squuid)}]))
+                   (db-editor-handler/save-file! "logseq/config.edn" content))
                   (edn/read-string content))))))
 
 
@@ -264,7 +263,7 @@
                             (state/set-state! :graph/importing :folder)
                             (state/set-state! [:graph/importing-state :current-page] (str graph-name " Assets"))
                             (async/go
-                              (async/<! (p->c (repo-handler/new-empty-db! graph-name)))
+                              (async/<! (p->c (repo-handler/new-db! graph-name {:file-graph-import? true})))
                               (let [repo (state/get-current-repo)
                                     db-conn (db/get-db repo false)]
                                 (async/<! (p->c (import-config-file! config-file)))

+ 7 - 37
src/main/frontend/handler/repo.cljs

@@ -520,7 +520,7 @@
   (let [full-graph-name (string/lower-case (str config/db-version-prefix graph-name))]
     (some #(= (string/lower-case (:url %)) full-graph-name) (state/get-repos))))
 
-(defn- create-db [full-graph-name]
+(defn- create-db [full-graph-name {:keys [file-graph-import?]}]
   (->
    (p/let [_ (persist-db/<new full-graph-name)
            _ (op-mem-layer/<init-load-from-indexeddb! full-graph-name)
@@ -532,7 +532,7 @@
            _ (repo-config-handler/set-repo-config-state! full-graph-name config/config-default-content)
           ;; TODO: handle global graph
            _ (state/pub-event! [:init/commands])
-           _ (state/pub-event! [:page/create (date/today) {:redirect? false}])]
+           _ (when-not file-graph-import? (state/pub-event! [:page/create (date/today) {:redirect? false}]))]
      (js/setTimeout ui-handler/re-render-root! 100)
      (prn "New db created: " full-graph-name))
    (p/catch (fn [error]
@@ -541,41 +541,11 @@
 
 (defn new-db!
   "Handler for creating a new database graph"
-  [graph]
-  (let [full-graph-name (str config/db-version-prefix graph)]
-    (if (graph-already-exists? graph)
-      (state/pub-event! [:notification/show
-                         {:content (str "The graph '" graph "' already exists. Please try again with another name.")
-                          :status :error}])
-      (create-db full-graph-name))))
-
-;; TODO: clean up and merge logic with new-db!
-(defn- create-empty-db
-  "No today page creation, no redirect to home"
-  [full-graph-name]
-  (->
-   (p/let [_ (persist-db/<new full-graph-name)
-           _ (op-mem-layer/<init-load-from-indexeddb! full-graph-name)
-           _ (start-repo-db-if-not-exists! full-graph-name)
-           _ (state/add-repo! {:url full-graph-name})
-          ;; 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)
-          ;; TODO: handle global graph
-           _ (state/pub-event! [:init/commands])]
-     (prn "New db created: " full-graph-name))
-   (p/catch (fn [error]
-              (notification/show! "Create graph failed." :error)
-              (js/console.error error)))))
-
-(defn new-empty-db!
-  "New database graph with empty content, for importing"
-  [graph]
-   (let [full-graph-name (str config/db-version-prefix graph)
-         graph-already-exists? (some #(= (:url %) full-graph-name) (state/get-repos))]
-     (if graph-already-exists?
+  ([graph] (new-db! graph {}))
+  ([graph opts]
+   (let [full-graph-name (str config/db-version-prefix graph)]
+     (if (graph-already-exists? graph)
        (state/pub-event! [:notification/show
                           {:content (str "The graph '" graph "' already exists. Please try again with another name.")
                            :status :error}])
-       (create-empty-db full-graph-name))))
+       (create-db full-graph-name opts)))))