Procházet zdrojové kódy

start fix lint warnings and tests

Tienson Qin před 2 roky
rodič
revize
7f0747ca9f

+ 1 - 1
deps/outliner/src/logseq/outliner/datascript.cljs

@@ -76,7 +76,7 @@
 
 (defn transact!
   [txs tx-meta {:keys [repo conn unlinked-graph? after-transact-fn set-state-fn] :as opts}]
-  (let [db-based? (sqlite-util/db-based-graph? repo)
+  (let [db-based? (and repo (sqlite-util/db-based-graph? repo))
         txs (map (fn [m]
                    (if (map? m)
                      (dissoc m :block/children :block/meta :block/top? :block/bottom? :block/anchor

+ 4 - 4
src/main/frontend/components/settings.cljs

@@ -743,7 +743,7 @@
      [:p (t :settings-page/git-confirm)])])
 
 (rum/defc settings-advanced < rum/reactive
-  [current-repo]
+  []
   (let [instrument-disabled? (state/sub :instrument/disabled?)
         developer-mode? (state/sub [:ui/developer-mode?])
         https-agent-opts (state/sub [:electron/user-cfgs :settings/agent])]
@@ -756,8 +756,8 @@
      (clear-cache-row t)
 
      (ui/admonition
-       :warning
-       [:p (t :settings-page/clear-cache-warning)])]))
+      :warning
+      [:p (t :settings-page/clear-cache-warning)])]))
 
 (rum/defc sync-enabled-switcher
   [enabled?]
@@ -1195,7 +1195,7 @@
          (assets/settings-content)
 
          :advanced
-         (settings-advanced current-repo)
+         (settings-advanced)
 
          :features
          (settings-features)

+ 0 - 1
src/main/frontend/db/conn.cljs

@@ -8,7 +8,6 @@
             [frontend.util.text :as text-util]
             [logseq.graph-parser.text :as text]
             [logseq.db :as ldb]
-            [logseq.db.frontend.schema :as db-schema]
             [logseq.common.util :as common-util]
             [logseq.db.sqlite.util :as sqlite-util]))
 

+ 1 - 2
src/main/frontend/fs/sync.cljs

@@ -514,8 +514,7 @@
   (let [path-string? (string? (first paths))
         f (if path-string?
             fs-util/include-reserved-chars?
-            #(fs-util/include-reserved-chars? (-relative-path %)))
-        reserved-paths (filter f paths)]
+            #(fs-util/include-reserved-chars? (-relative-path %)))]
     (vec (remove f paths))))
 
 (defn- diffs->filetxns

+ 11 - 12
src/main/frontend/handler/draw.cljs

@@ -25,18 +25,17 @@
   (let [path file
         repo (state/get-current-repo)]
     (when repo
-      (let [repo-dir (config/get-repo-dir repo)]
-        (->
-         (p/do!
-          (create-draws-directory! repo)
-          (db/transact! repo
-                        [{:file/path path
-                          :block/name (util/page-name-sanity-lc file)
-                          :block/file {:file/path path}
-                          :block/journal? false}]))
-         (p/catch (fn [error]
-                    (prn "Write file failed, path: " path ", data: " data)
-                    (js/console.dir error))))))))
+      (->
+       (p/do!
+        (create-draws-directory! repo)
+        (db/transact! repo
+                      [{:file/path path
+                        :block/name (util/page-name-sanity-lc file)
+                        :block/file {:file/path path}
+                        :block/journal? false}]))
+       (p/catch (fn [error]
+                  (prn "Write file failed, path: " path ", data: " data)
+                  (js/console.dir error)))))))
 
 (defn load-excalidraw-file
   [file ok-handler]

+ 1 - 1
src/main/frontend/util.cljc

@@ -1084,7 +1084,7 @@
 
 (defmacro profile
   [k & body]
-  `(frontend.worker.util/profile ~k ~@body))
+  `(worker-util/profile ~k ~@body))
 
 #?(:clj
    (defmacro with-time

+ 1 - 1
src/main/frontend/worker/file/page_rename.cljs

@@ -37,7 +37,7 @@
           content)
         (string/replace old-ref new-ref))))
 
-(defn- replace-tag-ref!
+(defn replace-tag-ref!
   [content old-name new-name]
   (let [old-tag (common-util/format "#%s" old-name)
         new-tag (if (re-find #"[\s\t]+" new-name)

+ 1 - 2
src/main/frontend/worker/rtc/core.cljs

@@ -26,8 +26,7 @@
             [frontend.worker.rtc.op-mem-layer :as op-mem-layer]
             [frontend.worker.rtc.ws :as ws]
             [promesa.core :as p]
-            [cljs-bean.core :as bean]
-            [frontend.worker.react :as worker-react]))
+            [cljs-bean.core :as bean]))
 
 
 ;;                     +-------------+

+ 3 - 3
src/test/frontend/db/name_sanity_test.cljs

@@ -2,7 +2,7 @@
   (:require [cljs.test :refer [deftest testing is are]]
             [clojure.string :as string]
             [logseq.common.util :as common-util]
-            [frontend.handler.file-based.page :as file-page-handler]
+            [frontend.worker.handler.page.rename :as worker-page-rename]
             [frontend.handler.conversion :as conversion-handler]
             [frontend.util.fs :as fs-util]
             [frontend.worker.file.util :as wfu]))
@@ -47,8 +47,8 @@
   (mapv test-page-name fs-util/windows-reserved-filebodies))
 
 (deftest new-path-computation-tests
-  (is (= (#'file-page-handler/compute-new-file-path "/data/app/dsal dsalfjk aldsaf.jkl" "ddd") "/data/app/ddd.jkl"))
-  (is (= (#'file-page-handler/compute-new-file-path "c://data/a sdfpp/dsal dsalf% * _ dsaf.mnk" "c d / f") "c://data/a sdfpp/c d / f.mnk")))
+  (is (= (#'worker-page-rename/compute-new-file-path "/data/app/dsal dsalfjk aldsaf.jkl" "ddd") "/data/app/ddd.jkl"))
+  (is (= (#'worker-page-rename/compute-new-file-path "c://data/a sdfpp/dsal dsalf% * _ dsaf.mnk" "c d / f") "c://data/a sdfpp/c d / f.mnk")))
 
 (deftest break-change-conversion-tests
   (let [conv-legacy #(:target (#'conversion-handler/calc-previous-name :legacy :triple-lowbar %))]

+ 4 - 5
src/test/frontend/handler/db_based/page_test.cljs

@@ -1,6 +1,5 @@
 (ns frontend.handler.db-based.page-test
-  (:require [frontend.handler.db-based.page :as db-page-handler]
-            [clojure.test :refer [deftest is testing use-fixtures]]
+  (:require [clojure.test :refer [deftest is testing use-fixtures]]
             [frontend.test.helper :as test-helper]
             [datascript.core :as d]
             [frontend.handler.page :as page-handler]
@@ -28,7 +27,7 @@
 (deftest rename-test
   (testing "Case change"
     (let [page (db/entity [:block/name "test"])]
-      (db-page-handler/rename! "test" "Test" false false)
+      (page-handler/rename! "test" "Test")
       (let [entity (db/entity [:block/name "test"])]
         (is (= "Test" (:block/original-name entity)))
         ;; db id not changed
@@ -36,7 +35,7 @@
 
   (testing "Name changed"
     (let [page (db/entity [:block/name "test"])]
-      (db-page-handler/rename! "Test" "New name" false false)
+      (page-handler/rename! "Test" "New name")
       (let [entity (db/entity [:block/name "new name"])]
         (is (= "New name" (:block/original-name entity)))
         (is (= (:db/id page) (:db/id entity))))))
@@ -45,7 +44,7 @@
     (with-redefs [gdom/getElement (constantly #js {:id nil})
                   editor-handler/edit-block! (constantly nil)]
       (page-handler/create! "Existing page" {:redirect? false :create-first-block? true})
-      (db-page-handler/rename! "New name" "Existing page" false false)
+      (page-handler/rename! "New name" "Existing page")
       (let [e1 (db/entity [:block/name "new name"])
             e2 (db/entity [:block/name "existing page"])]
       ;; Old page deleted

+ 25 - 25
src/test/frontend/handler/file_based/page_property_test.cljs

@@ -1,76 +1,76 @@
 (ns frontend.handler.file-based.page-property-test
   (:require [cljs.test :refer [are deftest testing]]
-            [frontend.handler.file-based.page-property :as file-page-property]))
+            [frontend.handler.file-based.property.util :as property-util]))
 
 (deftest test-insert-property
   (testing "add org page property"
     (are [x y] (= x y)
-      (file-page-property/insert-property :org "" :title "title")
+      (property-util/insert-property :org "" :title "title")
       "#+title: title"
 
-      (file-page-property/insert-property :org "hello" :title "title")
+      (property-util/insert-property :org "hello" :title "title")
       "#+title: title\nhello"
 
-      (file-page-property/insert-property :org "#+title: title\nhello" :title "new title")
+      (property-util/insert-property :org "#+title: title\nhello" :title "new title")
       "#+title: new title\nhello"
 
-      (file-page-property/insert-property :org "#+title: title\nhello" :alias "alias1")
+      (property-util/insert-property :org "#+title: title\nhello" :alias "alias1")
       "#+alias: alias1\n#+title: title\nhello"
 
-      (file-page-property/insert-property :org "#+title: title\n#+alias: alias1\nhello" :alias "alias2")
+      (property-util/insert-property :org "#+title: title\n#+alias: alias1\nhello" :alias "alias2")
       "#+title: title\n#+alias: alias2\nhello"
 
-      (file-page-property/insert-property :org "#+title: title\n#+alias: alias1, alias2\nhello" :alias "alias3")
+      (property-util/insert-property :org "#+title: title\n#+alias: alias1, alias2\nhello" :alias "alias3")
       "#+title: title\n#+alias: alias3\nhello"))
 
   (testing "add markdown page property"
     (are [x y] (= x y)
-      (file-page-property/insert-property :markdown "" :title "title")
+      (property-util/insert-property :markdown "" :title "title")
       "title:: title"
 
-      (file-page-property/insert-property :markdown "hello" :title "title")
+      (property-util/insert-property :markdown "hello" :title "title")
       "title:: title\nhello"
 
-      (file-page-property/insert-property :markdown "title:: title\nhello" :title "new title")
+      (property-util/insert-property :markdown "title:: title\nhello" :title "new title")
       "title:: new title\nhello"
 
-      (file-page-property/insert-property :markdown "title:: title\nhello" :alias "alias1")
+      (property-util/insert-property :markdown "title:: title\nhello" :alias "alias1")
       "alias:: alias1\ntitle:: title\nhello"
 
-      (file-page-property/insert-property :markdown "title:: title\nalias:: alias1\nhello" :alias "alias2")
+      (property-util/insert-property :markdown "title:: title\nalias:: alias1\nhello" :alias "alias2")
       "title:: title\nalias:: alias2\nhello"
 
-      (file-page-property/insert-property :markdown "title:: title\nalias:: alias1, alias2\nhello" :alias "alias3")
+      (property-util/insert-property :markdown "title:: title\nalias:: alias1, alias2\nhello" :alias "alias3")
       "title:: title\nalias:: alias3\nhello"
 
-      (file-page-property/insert-property :markdown "title:: title\nalias:: alias1, alias2\nhello" :aliases "aliases1")
+      (property-util/insert-property :markdown "title:: title\nalias:: alias1, alias2\nhello" :aliases "aliases1")
       "aliases:: aliases1\ntitle:: title\nalias:: alias1, alias2\nhello"
 
-      (file-page-property/insert-property :markdown "title:: title\nalias:: alias1, alias2\naliases:: aliases1\nhello" :aliases "aliases2")
+      (property-util/insert-property :markdown "title:: title\nalias:: alias1, alias2\naliases:: aliases1\nhello" :aliases "aliases2")
       "title:: title\nalias:: alias1, alias2\naliases:: aliases2\nhello")))
 
 (deftest test-insert-properties
   (testing "add org page properties"
     (are [x y] (= x y)
 
-      (file-page-property/insert-properties :org "" {:title "title"})
+      (property-util/insert-properties :org "" {:title "title"})
       "#+title: title"
 
-      (file-page-property/insert-properties :org "hello" {:title "title"})
+      (property-util/insert-properties :org "hello" {:title "title"})
       "#+title: title\nhello"
 
-      (file-page-property/insert-properties :org "#+title: title\nhello"
+      (property-util/insert-properties :org "#+title: title\nhello"
                                   {:title "new title"
                                    :alias "alias1"})
       "#+alias: alias1\n#+title: new title\nhello"
 
-      (file-page-property/insert-properties :org "#+title: title\n#+alias: alias1\nhello"
+      (property-util/insert-properties :org "#+title: title\n#+alias: alias1\nhello"
                                   {:title "new title"
                                    :alias "alias2"
                                    :aliases "aliases1"})
       "#+aliases: aliases1\n#+title: new title\n#+alias: alias2\nhello"
 
-      (file-page-property/insert-properties :org "#+title: title\n#+alias: alias1, alias2\n#+aliases: aliases1\nhello"
+      (property-util/insert-properties :org "#+title: title\n#+alias: alias1, alias2\n#+aliases: aliases1\nhello"
                                   {:title "new title"
                                    :alias "alias2"
                                    :aliases "aliases1"})
@@ -78,24 +78,24 @@
 
   (testing "add markdown page properties"
     (are [x y] (= x y)
-      (file-page-property/insert-properties :markdown "" {:title "title"})
+      (property-util/insert-properties :markdown "" {:title "title"})
       "title:: title"
 
-      (file-page-property/insert-properties :markdown "hello" {:title "title"})
+      (property-util/insert-properties :markdown "hello" {:title "title"})
       "title:: title\nhello"
 
-      (file-page-property/insert-properties :markdown "title:: title\nhello"
+      (property-util/insert-properties :markdown "title:: title\nhello"
                                   {:title "new title"
                                    :alias "alias1"})
       "alias:: alias1\ntitle:: new title\nhello"
 
-      (file-page-property/insert-properties :markdown "title:: title\nalias:: alias1\nhello"
+      (property-util/insert-properties :markdown "title:: title\nalias:: alias1\nhello"
                                   {:title "new title"
                                    :alias "alias2"
                                    :aliases "aliases1"})
       "aliases:: aliases1\ntitle:: new title\nalias:: alias2\nhello"
 
-      (file-page-property/insert-properties :markdown "title:: title\nalias:: alias1, alias2\naliases:: aliases1\nhello"
+      (property-util/insert-properties :markdown "title:: title\nalias:: alias1, alias2\naliases:: aliases1\nhello"
                                   {:title "new title"
                                    :alias "alias2"
                                    :aliases "aliases1"})

+ 4 - 4
src/test/frontend/handler/file_based/page_test.cljs

@@ -4,7 +4,7 @@
   (:require [cljs.test :refer [deftest are]]
             [clojure.string :as string]
             [frontend.util :as util]
-            [frontend.handler.file-based.page :as file-page-handler]))
+            [frontend.worker.file.page-rename :as page-rename]))
 
 (defn- replace-page-ref!
   [content old-name new-name]
@@ -36,7 +36,7 @@
   (when (and (string? content) (string? old-name) (string? new-name))
     (-> content
         (replace-page-ref! old-name new-name)
-        (file-page-handler/replace-tag-ref! old-name new-name))))
+        (page-rename/replace-tag-ref! old-name new-name))))
 
 (deftest test-replace-page-ref!
   (are [x y] (= (let [[content old-name new-name] x]
@@ -48,7 +48,7 @@
 
     ["bla [[file:./foo.org][foo]] bla" "foo" "bar"]
     "bla [[file:./bar.org][bar]] bla"
-    
+
     ["bla [[file:./logseq.foo.org][logseq/foo]] bla" "logseq/foo" "logseq/bar"]
     "bla [[file:./logseq.bar.org][logseq/bar]] bla"
 
@@ -66,7 +66,7 @@
 
 (deftest test-replace-tag-ref!
   (are [x y] (= (let [[content old-name new-name] x]
-                  (file-page-handler/replace-tag-ref! content old-name new-name))
+                  (page-rename/replace-tag-ref! content old-name new-name))
                 y)
     ["#foo" "foo" "bar"] "#bar"
     ["#foo" "foo" "new bar"] "#[[new bar]]"

+ 2 - 2
src/test/frontend/handler/repo_conversion_test.cljs

@@ -7,7 +7,7 @@
             [logseq.graph-parser.test.docs-graph-helper :as docs-graph-helper]
             [logseq.common.config :as common-config]
             [frontend.test.helper :as test-helper]
-            [frontend.handler.file-based.page :as file-page-handler]
+            [frontend.worker.handler.page.rename :as worker-page-rename]
             [frontend.handler.conversion :as conversion-handler]
             [frontend.handler.repo :as repo-handler]
             [frontend.db.conn :as conn]
@@ -123,7 +123,7 @@
     (if rename-target
       #_:clj-kondo/ignore
       (do #_(prn "conversion triple-lowbar: " original-body " -> " rename-target)
-       (#'file-page-handler/compute-new-file-path path rename-target))
+       (#'worker-page-rename/compute-new-file-path path rename-target))
       path)))
 
 (defn- convert-graph-files-path