Bladeren bron

fix: setting config should update db not file

Fixes LOG-2748. Also fix config.edn being saved when invalid
which would result in confusing scenarios where an invalid config
could persist into other contexts like a settings change
Gabriel Horner 2 jaren geleden
bovenliggende
commit
231f5d7ac6

+ 1 - 1
src/main/frontend/handler/common/config_edn.cljs

@@ -36,7 +36,7 @@ nested keys or positional errors e.g. tuples"
   ([title body]
    (config-notification-show! title body :error))
   ([title body status]
-   (config-notification-show! title body status true))
+   (config-notification-show! title body status false))
   ([title body status clear?]
    (notification/show!
     [:.mb-2

+ 6 - 2
src/main/frontend/handler/config.cljs

@@ -3,8 +3,10 @@
   (:require [frontend.state :as state]
             [frontend.handler.file :as file-handler]
             [frontend.handler.repo-config :as repo-config-handler]
+            [frontend.handler.db-based.editor :as db-editor-handler]
             [frontend.db :as db]
-            [borkdude.rewrite-edn :as rewrite]))
+            [borkdude.rewrite-edn :as rewrite]
+            [frontend.config :as config]))
 
 (defn parse-repo-config
   "Parse repo configuration file content"
@@ -23,7 +25,9 @@
                        (reduce-kv (fn [a k v] (rewrite/assoc a k v)) (rewrite/parse-string "{}")))
             new-result (rewrite/assoc-in result ks v)
             new-content (str new-result)]
-        (file-handler/set-file-content! repo path new-content) nil))))
+        (if (config/db-based-graph? repo)
+          (db-editor-handler/save-file! path new-content)
+          (file-handler/set-file-content! repo path new-content)) nil))))
 
 (defn set-config!
   [k v]

+ 13 - 13
src/main/frontend/handler/db_based/editor.cljs

@@ -93,17 +93,17 @@
 (defn save-file!
   "This fn is the db version of file-handler/alter-file"
   [path content]
-  ;; Pre save
-  (when (= path "logseq/config.edn")
-    (config-edn-common-handler/detect-deprecations path content)
-    (config-edn-common-handler/validate-config-edn path content repo-config-schema/Config-edn))
+  (let [file-valid? (if (= path "logseq/config.edn")
+                      (do (config-edn-common-handler/detect-deprecations path content)
+                          (config-edn-common-handler/validate-config-edn path content repo-config-schema/Config-edn))
+                      true)]
 
-  (db/transact! [{:file/path path
-                  :file/content content}])
-
-  ;; Post save
-  (cond (= path "logseq/config.edn")
-        (p/let [_ (repo-config-handler/restore-repo-config! (state/get-current-repo) content)]
-          (state/pub-event! [:shortcut/refresh]))
-        (= path "logseq/custom.css")
-        (ui-handler/add-style-if-exists!)))
+    (when file-valid?
+      (db/transact! [{:file/path path
+                      :file/content content}])
+      ;; Post save
+      (cond (= path "logseq/config.edn")
+            (p/let [_ (repo-config-handler/restore-repo-config! (state/get-current-repo) content)]
+              (state/pub-event! [:shortcut/refresh]))
+            (= path "logseq/custom.css")
+            (ui-handler/add-style-if-exists!)))))