From 2ada687ecc1c75ade6ca4c97bf747d6e404171ba Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Fri, 18 Aug 2023 12:44:10 +0200 Subject: [PATCH] :sparkles: Show a confirmation dialog when an user tries to publish an empty library --- CHANGES.md | 1 + .../src/app/main/ui/workspace/libraries.cljs | 45 +++++++++++++------ frontend/translations/en.po | 9 ++++ frontend/translations/es.po | 9 ++++ 4 files changed, 50 insertions(+), 14 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7a46cd098..dfd4dde77 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -33,6 +33,7 @@ goolge and reduces the amount of request sent to google) - Set smooth/instant autoscroll depending on distance [GitHub #3377](https://github.com/penpot/penpot/issues/3377) - New component icon [Taiga #5290](https://tree.taiga.io/project/penpot/us/5290) +- Show a confirmation dialog when an user tries to publish an empty library [Taiga #5294](https://tree.taiga.io/project/penpot/us/5294) ### :bug: Bugs fixed diff --git a/frontend/src/app/main/ui/workspace/libraries.cljs b/frontend/src/app/main/ui/workspace/libraries.cljs index f6dd270aa..578a1c3cc 100644 --- a/frontend/src/app/main/ui/workspace/libraries.cljs +++ b/frontend/src/app/main/ui/workspace/libraries.cljs @@ -46,21 +46,22 @@ (defn- describe-library [components-count graphics-count colors-count typography-count] - (str - (str/join " · " - (cond-> [] - (pos? components-count) - (conj (tr "workspace.libraries.components" components-count)) + (let [all-zero? (and (zero? components-count) (zero? graphics-count) (zero? colors-count) (zero? typography-count))] + (str + (str/join " · " + (cond-> [] + (or all-zero? (pos? components-count)) + (conj (tr "workspace.libraries.components" components-count)) - (pos? graphics-count) - (conj (tr "workspace.libraries.graphics" graphics-count)) + (or all-zero? (pos? graphics-count)) + (conj (tr "workspace.libraries.graphics" graphics-count)) - (pos? colors-count) - (conj (tr "workspace.libraries.colors" colors-count)) + (or all-zero? (pos? colors-count)) + (conj (tr "workspace.libraries.colors" colors-count)) - (pos? typography-count) - (conj (tr "workspace.libraries.typography" typography-count)))) - "\u00A0")) + (or all-zero? (pos? typography-count)) + (conj (tr "workspace.libraries.typography" typography-count)))) + "\u00A0"))) (mf/defc describe-library-blocks [{:keys [components-count graphics-count colors-count typography-count] :as props}] @@ -125,6 +126,12 @@ media (:media library) typographies (:typographies library) + empty-library? (and + (zero? (count colors)) + (zero? (count components)) + (zero? (count media)) + (zero? (count typographies))) + shared-libraries (mf/with-memo [shared-libraries linked-libraries file-id search-term] (->> shared-libraries @@ -191,8 +198,18 @@ (mf/use-fn (mf/deps file-id) (fn [event] - (let [input-node (dom/event->target event)] - (st/emit! (dwl/set-file-shared file-id true)) + (let [input-node (dom/event->target event) + publish-library #(st/emit! (dwl/set-file-shared file-id true)) + cancel-publish #(st/emit! (modal/show :libraries-dialog {}))] + (if empty-library? + (st/emit! (modal/show + {:type :confirm + :title (tr "modals.publish-empty-library.title") + :message (tr "modals.publish-empty-library.message") + :accept-label (tr "modals.publish-empty-library.accept") + :on-accept publish-library + :on-cancel cancel-publish})) + (publish-library)) (dom/blur! input-node)))) unpublish diff --git a/frontend/translations/en.po b/frontend/translations/en.po index 7269bda33..e92eef71d 100644 --- a/frontend/translations/en.po +++ b/frontend/translations/en.po @@ -2142,6 +2142,15 @@ msgstr "Are you sure you want to delete this annotation?" msgid "modals.delete-component-annotation.title" msgstr "Delete annotation" +msgid "modals.publish-empty-library.title" +msgstr "Publish empty library" + +msgid "modals.publish-empty-library.message" +msgstr "Your library is empty. Are you sure you want to publish it?" + +msgid "modals.publish-empty-library.accept" +msgstr "Publish" + #: src/app/main/ui/dashboard/team.cljs msgid "notifications.invitation-email-sent" msgstr "Invitation sent successfully" diff --git a/frontend/translations/es.po b/frontend/translations/es.po index ceea530b4..815a2d7ee 100644 --- a/frontend/translations/es.po +++ b/frontend/translations/es.po @@ -2208,6 +2208,15 @@ msgstr "¿Seguro que quieres borrar esta nota?" msgid "modals.delete-component-annotation.title" msgstr "Borrar nota" +msgid "modals.publish-empty-library.title" +msgstr "Publicar biblioteca vacía" + +msgid "modals.publish-empty-library.message" +msgstr "Tu biblioteca está vacía. ¿Seguro que quieres publicarla?" + +msgid "modals.publish-empty-library.accept" +msgstr "Publicar" + #: src/app/main/ui/dashboard/team.cljs msgid "notifications.invitation-email-sent" msgstr "Invitación enviada con éxito"