Skip to content

Commit

Permalink
Merge pull request penpot#4852 from penpot/alotor-plugins-7
Browse files Browse the repository at this point in the history
✨ Small improvements over plugin manager
  • Loading branch information
niwinz authored Jul 8, 2024
2 parents 6f8ce1f + 2cc3f65 commit 1b05e7a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
11 changes: 11 additions & 0 deletions frontend/src/app/main/ui/workspace/plugins.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
plugin-url* (mf/use-state "")
plugin-url @plugin-url*

fetching-manifest? (mf/use-state false)

input-status* (mf/use-state nil) ;; :error-url :error-manifest :success
input-status @input-status*

Expand All @@ -106,13 +108,15 @@
(mf/use-callback
(mf/deps plugins-state plugin-url)
(fn []
(reset! fetching-manifest? true)
(->> (http/send! {:method :get
:uri plugin-url
:omit-default-headers true
:response-type :json})
(rx/map :body)
(rx/subs!
(fn [body]
(reset! fetching-manifest? false)
(let [plugin (plugins/parser-manifest plugin-url body)]
(st/emit! (ptk/event ::ev/event {::ev/name "install-plugin" :name (:name plugin) :url plugin-url}))
(modal/show!
Expand All @@ -125,6 +129,7 @@
(reset! input-status* :success)
(reset! plugin-url* "")))
(fn [_]
(reset! fetching-manifest? false)
(reset! input-status* :error-url))))))

handle-open-plugin
Expand Down Expand Up @@ -161,12 +166,18 @@
:class (stl/css-case :input-error error?)}]

[:button {:class (stl/css :primary-button)
:disabled @fetching-manifest?
:on-click handle-install-click} (tr "workspace.plugins.install")]]

(when error?
[:div {:class (stl/css-case :info true :error error?)}
(tr "workspace.plugins.error.url")])

[:> i18n/tr-html*
{:class (stl/css :discover)
:on-click #(st/emit! (ptk/event ::ev/event {::ev/name "open-plugins-list"}))
:content (tr "workspace.plugins.discover" cf/plugins-list-uri)}]

[:hr]

(if (empty? plugins-state)
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/app/main/ui/workspace/plugins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ div.input-error {
gap: $s-4;

svg {
margin-top: calc(-1 * var($s-2));
margin-top: calc(-1 * $s-2);
width: $s-12;
height: $s-12;
stroke: $da-primary;
Expand Down Expand Up @@ -262,3 +262,13 @@ div.input-error {
display: flex;
gap: $s-12;
}

.discover {
@include bodySmallTypography;
color: $df-secondary;
margin-top: $s-24;

a {
color: $da-primary;
}
}
7 changes: 6 additions & 1 deletion frontend/src/app/plugins/register.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@

(defn install-plugin!
[plugin]
(let [plugins (vec (conj (seq @pluginsdb) plugin))]
(let [plugins (as-> @pluginsdb $
(remove (fn [{:keys [name host]}]
(and (= name (:name plugin))
(= host (:host plugin)))) $)
(conj $ plugin)
(vec $))]
(reset! pluginsdb plugins)
(save-to-store plugins)))

Expand Down
5 changes: 3 additions & 2 deletions frontend/src/app/util/i18n.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,11 @@

(mf/defc tr-html*
{::mf/props :obj}
[{:keys [content class tag-name]}]
[{:keys [content class tag-name on-click]}]
(let [tag-name (d/nilv tag-name "p")]
[:> tag-name {:dangerouslySetInnerHTML #js {:__html content}
:className class}]))
:className class
:on-click on-click}]))

;; DEPRECATED
(defn use-locale
Expand Down
7 changes: 6 additions & 1 deletion frontend/translations/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -5282,7 +5282,7 @@ msgid "workspace.plugins.menu.title"
msgstr "Plugins"

msgid "workspace.toolbar.plugins"
msgstr "Plugins"
msgstr "Plugins (%s)"

msgid "workspace.plugins.menu.plugins-manager"
msgstr "Plugins manager"
Expand Down Expand Up @@ -5310,3 +5310,8 @@ msgstr "Read your libraries and assets."

msgid "workspace.plugins.permissions.library-write"
msgstr "Read and modify your libraries and assets."

#, markdown
msgid "workspace.plugins.discover"
msgstr ""
"Discover [more plugins](%s)"
7 changes: 6 additions & 1 deletion frontend/translations/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -5362,7 +5362,7 @@ msgid "workspace.plugins.title"
msgstr "Extensiones"

msgid "workspace.toolbar.plugins"
msgstr "Extensiones"
msgstr "Extensiones (%s)"

msgid "workspace.plugins.search-placeholder"
msgstr "Intruduzca URL de la extensión"
Expand Down Expand Up @@ -5414,3 +5414,8 @@ msgstr "Leer la información de sus bibliotecas y recursos."

msgid "workspace.plugins.permissions.library-write"
msgstr "Leer y modificar la información de sus bibliotecas y recursos."

#, markdown
msgid "workspace.plugins.discover"
msgstr ""
"Descubre [más extensiones](%s)"

0 comments on commit 1b05e7a

Please sign in to comment.