0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-01 17:41:50 -05:00

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.exceptions :as ex]
[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.config :as cf]
[app.db :as db]
@ -43,7 +43,7 @@
(def schema:props
[:map {:title "ProfileProps"}
[:plugins {:optional true} schema:plugin-data]
[:plugins {:optional true} schema:plugin-registry]
[:newsletter-updates {:optional true} ::sm/boolean]
[:newsletter-news {:optional true} ::sm/boolean]
[:onboarding-team-id {:optional true} ::sm/uuid]

View file

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

View file

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

View file

@ -5548,10 +5548,12 @@ msgstr "Discover [more plugins](%s)"
msgid "workspace.plugins.empty-plugins"
msgstr "No plugins installed yet"
#: src/app/main/ui/workspace/plugins.cljs:175
msgid "workspace.plugins.error.url"
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
msgid "workspace.plugins.install"
msgstr "Install"

View file

@ -5535,10 +5535,12 @@ msgstr "Descubre [más extensiones](%s)"
msgid "workspace.plugins.empty-plugins"
msgstr "No se encuentran extensiones"
#: src/app/main/ui/workspace/plugins.cljs:175
msgid "workspace.plugins.error.url"
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
msgid "workspace.plugins.install"
msgstr "Instalar"