Browse Source

enhance: Allow commands to marked as :db-graph?

so that file graphs get a helpful notification that the command
can't be used instead of failing weirdly. Also remove unused
db-graph-enabled?
Gabriel Horner 9 months ago
parent
commit
77a64701c2
2 changed files with 26 additions and 10 deletions
  1. 0 3
      src/main/frontend/config.cljs
  2. 26 7
      src/main/frontend/modules/shortcut/config.cljs

+ 0 - 3
src/main/frontend/config.cljs

@@ -79,9 +79,6 @@
   []
   (and lsp-enabled? (global-config-enabled?)))
 
-;; TODO: switch to `logseq-team` group check later @zhiyuan
-(def db-graph-enabled? true)
-
 ;; :TODO: How to do this?
 ;; (defonce desktop? ^boolean goog.DESKTOP)
 

+ 26 - 7
src/main/frontend/modules/shortcut/config.cljs

@@ -358,31 +358,37 @@
                                              :fn      #(state/pub-event! [:editor/toggle-own-number-list (state/get-selection-block-ids)])}
 
    :editor/add-property                     {:binding (if mac? "mod+p" "ctrl+alt+p")
+                                             :db-graph? true
                                              :fn      (fn [e]
                                                         (when e (util/stop e))
                                                         (state/pub-event! [:editor/new-property {}]))}
 
    :editor/add-property-deadline            {:binding "p d"
+                                             :db-graph? true
                                              :selection? true
                                              :fn      (fn []
                                                         (state/pub-event! [:editor/new-property {:property-key "Deadline"}]))}
 
    :editor/add-property-status              {:binding "p s"
+                                             :db-graph? true
                                              :selection? true
                                              :fn      (fn []
                                                         (state/pub-event! [:editor/new-property {:property-key "Status"}]))}
 
    :editor/add-property-priority            {:binding "p p"
+                                             :db-graph? true
                                              :selection? true
                                              :fn      (fn []
                                                         (state/pub-event! [:editor/new-property {:property-key "Priority"}]))}
 
    :editor/add-property-icon                {:binding "p i"
+                                             :db-graph? true
                                              :selection? true
                                              :fn      (fn []
                                                         (state/pub-event! [:editor/new-property {:property-key "Icon"}]))}
 
    :editor/toggle-display-all-properties    {:binding "p t"
+                                             :db-graph? true
                                              :fn      ui-handler/toggle-show-empty-hidden-properties!}
 
    :ui/toggle-brackets                      {:binding "t b"
@@ -456,13 +462,11 @@
                                              :binding []}
 
    :graph/db-add                            {:fn #(state/pub-event! [:graph/new-db-graph])
-                                             ;; TODO: Remove this once feature is released
-                                             :inactive (not config/db-graph-enabled?)
                                              :binding false}
 
    :graph/db-save                           {:fn #(state/pub-event! [:graph/save-db-to-disk])
-                                             ;; TODO: Remove `(not config/db-graph-enabled?)` check once feature is released
-                                             :inactive (or (not config/db-graph-enabled?) (not (util/electron?)))
+                                             :inactive (not (util/electron?))
+                                             :db-graph? true
                                              :binding "mod+s"}
 
    :graph/re-index                          {:fn      (fn []
@@ -610,14 +614,17 @@
                        :fn :frontend.handler.common.developer/show-page-ast}
 
    :dev/export-block-data {:binding []
+                           :db-graph? true
                            :inactive (not (state/developer-mode?))
                            :fn :frontend.handler.common.developer/export-block-data}
 
    :dev/import-block-data {:binding []
+                           :db-graph? true
                            :inactive (not (state/developer-mode?))
                            :fn :frontend.handler.common.developer/import-block-data}
 
    :dev/validate-db   {:binding []
+                       :db-graph? true
                        :inactive (not (state/developer-mode?))
                        :fn :frontend.handler.common.developer/validate-db}})
 
@@ -638,6 +645,15 @@
       (resolved-fn)
       (throw (ex-info (str "Unable to resolve " keyword-fn " to a fn") {})))))
 
+(defn- wrap-fn-with-db-graph-only-warning
+  "Wraps DB graph only commands so they are only run in DB graphs and warned
+   when in file graphs"
+  [f]
+  (fn []
+    (if (config/db-based-graph? (state/get-current-repo))
+      (f)
+      (notification/show! "This command is only for DB graphs." :warning true nil 3000))))
+
 (defn- wrap-fn-with-file-graph-only-warning
   "Wraps file graph only commands so they are only run in file graphs and warned
    when in DB graphs"
@@ -665,9 +681,12 @@
                    (assoc v :fn (resolve-fn (:fn v)))
                    v)]))
        (map (fn [[k v]]
-              [k (if (:file-graph? v)
-                   (update v :fn wrap-fn-with-file-graph-only-warning)
-                   v)]))
+              [k (cond (:file-graph? v)
+                       (update v :fn wrap-fn-with-file-graph-only-warning)
+                       (:db-graph? v)
+                       (update v :fn wrap-fn-with-db-graph-only-warning)
+                       :else
+                       v)]))
        (into {})))
 
 ;; This is the only var that should be publicly expose :fn functionality