mirror of
https://github.com/logseq/logseq.git
synced 2026-06-02 11:21:22 +00:00
enhance: finish making import data form undo/redoable
Add current block support and error handling. Also update most uses of build-import to call d/transact! once afterwards. Previously I think we needed separate transacts because of new properties but that is no longer the case
This commit is contained in:
committed by
Gabriel Horner
parent
fe619d3a92
commit
487cbb2bc9
@@ -1,7 +1,6 @@
|
||||
(ns frontend.handler.db-based.import
|
||||
"Handles DB graph imports"
|
||||
(:require [cljs.pprint :as pprint]
|
||||
[clojure.edn :as edn]
|
||||
(:require [clojure.edn :as edn]
|
||||
[datascript.core :as d]
|
||||
[frontend.config :as config]
|
||||
[frontend.db :as db]
|
||||
@@ -111,38 +110,29 @@
|
||||
import-block? (::sqlite-export/block export-map)
|
||||
block (when import-block?
|
||||
(if-let [eid (:block-id (first (state/get-editor-args)))]
|
||||
(db/entity [:block/uuid eid])
|
||||
(let [ent (db/entity [:block/uuid eid])]
|
||||
(if-not (:block/page ent)
|
||||
{:error "Can't import block into a non-block entity. Please import block elsewhere."}
|
||||
(merge (select-keys ent [:block/uuid])
|
||||
{:block/page (select-keys (:block/page ent) [:block/uuid])})))
|
||||
(notification/show! "No block found" :warning)))]
|
||||
(if (= ::invalid-import export-map)
|
||||
(notification/show! "The submitted EDN data is invalid! Please fix and try again." :warning)
|
||||
(p/do!
|
||||
;; TODO: Error handling?
|
||||
(ui-outliner-tx/transact!
|
||||
{:outliner-op :batch-import-edn}
|
||||
(outliner-op/batch-import-edn! export-map (when block {:current-block block})))
|
||||
(shui/dialog-close-all!))
|
||||
#_(let [{:keys [init-tx block-props-tx misc-tx error] :as txs}
|
||||
(safe-build-edn-import export-map (when block {:current-block block}))]
|
||||
(pprint/pprint txs)
|
||||
(if error
|
||||
(notification/show! error :error)
|
||||
;; TODO: When not import-block, use metadata that supports undo
|
||||
(let [tx-meta (if import-block? {:outliner-op :save-block} {::sqlite-export/imported-data? true})
|
||||
repo (state/get-current-repo)]
|
||||
(-> (p/do
|
||||
(db/transact! repo init-tx tx-meta)
|
||||
(when (seq block-props-tx)
|
||||
(db/transact! repo block-props-tx tx-meta))
|
||||
(when (seq misc-tx)
|
||||
(db/transact! repo misc-tx tx-meta))
|
||||
(when-not import-block?
|
||||
(ui-handler/re-render-root!)
|
||||
(notification/show! "Import successful!" :success)))
|
||||
(p/catch (fn [e]
|
||||
(js/console.error "Import EDN error: " e)
|
||||
(notification/show! "An unexpected error occurred during import. See the javascript console for details." :error))))))
|
||||
;; Also close cmd-k
|
||||
(shui/dialog-close-all!)))))
|
||||
(cond (or (= ::invalid-import export-map) (not (map? export-map)))
|
||||
(notification/show! "The submitted EDN data is invalid! Please fix and try again." :warning)
|
||||
(:error block)
|
||||
(do
|
||||
(notification/show! (:error block) :error)
|
||||
(shui/dialog-close-all!))
|
||||
:else
|
||||
(p/let [{:keys [error]}
|
||||
(ui-outliner-tx/transact!
|
||||
{:outliner-op :batch-import-edn}
|
||||
(outliner-op/batch-import-edn! export-map (when block {:current-block block})))]
|
||||
;; Also close cmd-k
|
||||
(shui/dialog-close-all!)
|
||||
(ui-handler/re-render-root!)
|
||||
(if error
|
||||
(notification/show! error :error)
|
||||
(notification/show! "Import successful!" :success))))))
|
||||
|
||||
(defn ^:export import-edn-data-dialog
|
||||
"Displays dialog which allows users to paste and import sqlite.build EDN Data"
|
||||
|
||||
Reference in New Issue
Block a user