Fixed plugin registration props

This commit is contained in:
alonso.torres 2024-09-16 15:46:02 +02:00
parent 214733c880
commit 9bca42c14a
6 changed files with 71 additions and 27 deletions

View file

@ -10,7 +10,7 @@
[app.common.data :as d] [app.common.data :as d]
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.common.schema :as sm] [app.common.schema :as sm]
[app.common.types.plugins :refer [schema:plugin-data]] [app.common.types.plugins :refer [schema:plugin-registry]]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.config :as cf] [app.config :as cf]
[app.db :as db] [app.db :as db]
@ -43,7 +43,7 @@
(def schema:props (def schema:props
[:map {:title "ProfileProps"} [:map {:title "ProfileProps"}
[:plugins {:optional true} schema:plugin-data] [:plugins {:optional true} schema:plugin-registry]
[:newsletter-updates {:optional true} ::sm/boolean] [:newsletter-updates {:optional true} ::sm/boolean]
[:newsletter-news {:optional true} ::sm/boolean] [:newsletter-news {:optional true} ::sm/boolean]
[:onboarding-team-id {:optional true} ::sm/uuid] [:onboarding-team-id {:optional true} ::sm/uuid]

View file

@ -29,3 +29,25 @@
schema:string]]) schema:string]])
(sm/register! ::plugin-data schema:plugin-data) (sm/register! ::plugin-data schema:plugin-data)
(def ^:private schema:registry-entry
[:map
[:plugin-id :string]
[:name :string]
[:description {:optional true} :string]
[:host :string]
[:code :string]
[:icon {:optional true} :string]
[:permissions [:set :string]]])
(def schema:plugin-registry
[:map
[:ids [:vector :string]]
[:data
[:map-of {:gen/max 5}
:string
schema:registry-entry]]])
(sm/register! ::plugin-registry schema:plugin-registry)
(sm/register! ::registry-entry schema:registry-entry)

View file

@ -91,7 +91,9 @@
input-status* (mf/use-state nil) ;; :error-url :error-manifest :success input-status* (mf/use-state nil) ;; :error-url :error-manifest :success
input-status @input-status* input-status @input-status*
error? (contains? #{:error-url :error-manifest} input-status) error-url? (= :error-url input-status)
error-manifest? (= :error-manifest input-status)
error? (or error-url? error-manifest?)
handle-close-dialog handle-close-dialog
(mf/use-callback (mf/use-callback
@ -117,17 +119,20 @@
(rx/subs! (rx/subs!
(fn [body] (fn [body]
(reset! fetching-manifest? false) (reset! fetching-manifest? false)
(let [plugin (preg/parse-manifest plugin-url body)] (if-let [plugin (preg/parse-manifest plugin-url body)]
(st/emit! (ptk/event ::ev/event {::ev/name "install-plugin" :name (:name plugin) :url plugin-url})) (do
(modal/show! (st/emit! (ptk/event ::ev/event {::ev/name "install-plugin" :name (:name plugin) :url plugin-url}))
:plugin-permissions (modal/show!
{:plugin plugin :plugin-permissions
:on-accept {:plugin plugin
#(do :on-accept
(preg/install-plugin! plugin) #(do
(modal/show! :plugin-management {}))}) (preg/install-plugin! plugin)
(reset! input-status* :success) (modal/show! :plugin-management {}))})
(reset! plugin-url* ""))) (reset! input-status* :success)
(reset! plugin-url* ""))
;; Cannot get the manifest
(reset! input-status* :error-manifest)))
(fn [_] (fn [_]
(reset! fetching-manifest? false) (reset! fetching-manifest? false)
(reset! input-status* :error-url)))))) (reset! input-status* :error-url))))))
@ -170,10 +175,14 @@
:disabled @fetching-manifest? :disabled @fetching-manifest?
:on-click handle-install-click} (tr "workspace.plugins.install")]] :on-click handle-install-click} (tr "workspace.plugins.install")]]
(when error? (when error-url?
[:div {:class (stl/css-case :info true :error error?)} [:div {:class (stl/css-case :info true :error error?)}
(tr "workspace.plugins.error.url")]) (tr "workspace.plugins.error.url")])
(when error-manifest?
[:div {:class (stl/css-case :info true :error error?)}
(tr "workspace.plugins.error.manifest")])
[:> i18n/tr-html* [:> i18n/tr-html*
{:class (stl/css :discover) {:class (stl/css :discover)
:on-click #(st/emit! (ptk/event ::ev/event {::ev/name "open-plugins-list"})) :on-click #(st/emit! (ptk/event ::ev/event {::ev/name "open-plugins-list"}))

View file

@ -9,6 +9,8 @@
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.data.macros :as dm] [app.common.data.macros :as dm]
[app.common.schema :as sm]
[app.common.types.plugins :as ctp]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.repo :as rp] [app.main.repo :as rp]
[app.main.store :as st] [app.main.store :as st]
@ -51,19 +53,26 @@
(and (= name (:name plugin)) (and (= name (:name plugin))
(= origin (:host plugin)))))) (= origin (:host plugin))))))
plugin-id (d/nilv (:plugin-id prev-plugin) (str (uuid/next)))] plugin-id (d/nilv (:plugin-id prev-plugin) (str (uuid/next)))
{:plugin-id plugin-id
:name name manifest
:description desc (d/without-nils
:host origin {:plugin-id plugin-id
:code code :name name
:icon icon :description desc
:permissions (into #{} (map str) permissions)})) :host origin
:code code
:icon icon
:permissions (into #{} (map str) permissions)})]
(when (sm/validate ::ctp/registry-entry manifest)
manifest)))
(defn save-to-store (defn save-to-store
[] []
(->> (rp/cmd! :update-profile-props {:props {:plugins @registry}}) ;; TODO: need this for the transition to the new schema. We can remove eventually
(rx/subs! identity))) (let [registry (update @registry :data d/update-vals d/without-nils)]
(->> (rp/cmd! :update-profile-props {:props {:plugins registry}})
(rx/subs! identity))))
(defn load-from-store (defn load-from-store
[] []

View file

@ -5548,10 +5548,12 @@ msgstr "Discover [more plugins](%s)"
msgid "workspace.plugins.empty-plugins" msgid "workspace.plugins.empty-plugins"
msgstr "No plugins installed yet" msgstr "No plugins installed yet"
#: src/app/main/ui/workspace/plugins.cljs:175
msgid "workspace.plugins.error.url" msgid "workspace.plugins.error.url"
msgstr "The plugin doesn't exist or the URL is not correct." msgstr "The plugin doesn't exist or the URL is not correct."
msgid "workspace.plugins.error.manifest"
msgstr "The plugin manifest is incorrect."
#: src/app/main/ui/workspace/plugins.cljs:171 #: src/app/main/ui/workspace/plugins.cljs:171
msgid "workspace.plugins.install" msgid "workspace.plugins.install"
msgstr "Install" msgstr "Install"

View file

@ -5535,10 +5535,12 @@ msgstr "Descubre [más extensiones](%s)"
msgid "workspace.plugins.empty-plugins" msgid "workspace.plugins.empty-plugins"
msgstr "No se encuentran extensiones" msgstr "No se encuentran extensiones"
#: src/app/main/ui/workspace/plugins.cljs:175
msgid "workspace.plugins.error.url" msgid "workspace.plugins.error.url"
msgstr "La extensión no existe o la url no es correcta." msgstr "La extensión no existe o la url no es correcta."
msgid "workspace.plugins.error.manifest"
msgstr "El manifiesto de la expansión es incorrecto."
#: src/app/main/ui/workspace/plugins.cljs:171 #: src/app/main/ui/workspace/plugins.cljs:171
msgid "workspace.plugins.install" msgid "workspace.plugins.install"
msgstr "Instalar" msgstr "Instalar"