From db7c4a926581c24662a5de44f27d4fdac898293a Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Mon, 24 Jul 2023 12:53:58 +0200 Subject: [PATCH] :bug: Fix export multiple images when only one of them has export settings --- CHANGES.md | 1 + .../sidebar/options/menus/exports.cljs | 41 +++++++++++++------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 5edc09ba2..20c84c94b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -87,6 +87,7 @@ - Fix absolute positioned layouts not showing flex properties [Taiga #5630](https://tree.taiga.io/project/penpot/issue/5630) - Fix text gradient handlers [Taiga #4047](https://tree.taiga.io/project/penpot/issue/4047) - Fix when user deletes one file during import it is impossible to finish importing of second file [Taiga #5656](https://tree.taiga.io/project/penpot/issue/5656) +- Fix export multiple images when only one of them has export settings [Taiga #5649](https://tree.taiga.io/project/penpot/issue/5649) ### :arrow_up: Deps updates diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/exports.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/exports.cljs index 191051640..879c49173 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/exports.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/exports.cljs @@ -26,18 +26,20 @@ (mf/defc exports-menu {::mf/wrap [#(mf/memo' % (mf/check-props ["ids" "values" "type" "page-id" "file-id"]))]} [{:keys [ids type values page-id file-id] :as props}] - (let [exports (:exports values []) + (let [exports (:exports values []) - state (mf/deref refs/export) - in-progress? (:in-progress state) + state (mf/deref refs/export) + in-progress? (:in-progress state) - sname (when (seqable? exports) - (let [shapes (wsh/lookup-shapes @st/state ids) - sname (-> shapes first :name) - suffix (-> exports first :suffix)] - (cond-> sname - (and (= 1 (count exports)) (some? suffix)) - (str suffix)))) + shapes-with-exports (->> (wsh/lookup-shapes @st/state ids) + (filter #(pos? (count (:exports %))))) + + sname (when (seqable? exports) + (let [sname (-> shapes-with-exports first :name) + suffix (-> exports first :suffix)] + (cond-> sname + (and (= 1 (count exports)) (some? suffix)) + (str suffix)))) scale-enabled? (mf/use-callback @@ -50,7 +52,22 @@ (fn [event] (dom/prevent-default event) (if (= :multiple type) - (st/emit! (de/show-workspace-export-dialog {:selected (reverse ids)})) + ;; I can select multiple shapes all of them with no export settings and one of them with only one + ;; In that situation we must export it directly + (if (and (= 1 (count shapes-with-exports)) (= 1 (-> shapes-with-exports first :exports count))) + (let [shape (-> shapes-with-exports first) + export (-> shape :exports first) + sname (:name shape) + suffix (:suffix export) + defaults {:page-id page-id + :file-id file-id + :name sname + :object-id (:id (first shapes-with-exports))}] + (cond-> sname + (some? suffix) + (str suffix)) + (st/emit! (de/request-simple-export {:export (merge export defaults)}))) + (st/emit! (de/show-workspace-export-dialog {:selected (reverse ids)}))) ;; In other all cases we only allowed to have a single ;; shape-id because multiple shape-ids are handled @@ -182,4 +199,4 @@ :disabled in-progress?} (if in-progress? (tr "workspace.options.exporting-object") - (tr "workspace.options.export-object" (c (count ids))))])])) + (tr "workspace.options.export-object" (c (count shapes-with-exports))))])]))