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?
This commit is contained in:
Gabriel Horner
2025-01-29 11:53:43 -05:00
parent 085872ea64
commit 77a64701c2
2 changed files with 26 additions and 10 deletions

View File

@@ -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