From 9fcddc37f68e2c22ed46bb08e2963a44d5e80470 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 6 May 2021 21:49:37 +0200 Subject: [PATCH 1/5] :bug: Fix problem with command --- CHANGES.md | 5 +++++ frontend/src/app/main/data/workspace/path/selection.cljs | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 2cbb124c3..75192a939 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,11 @@ ### :boom: Breaking changes ### :heart: Community contributions by (Thank you!) +## 1.5.2-alpha + +### :bug: Bugs fixed + +- Fix problem with `close-path` command [#917](https://github.com/penpot/penpot/issues/917) ## 1.5.1-alpha diff --git a/frontend/src/app/main/data/workspace/path/selection.cljs b/frontend/src/app/main/data/workspace/path/selection.cljs index 93bb59e66..dec4027ea 100644 --- a/frontend/src/app/main/data/workspace/path/selection.cljs +++ b/frontend/src/app/main/data/workspace/path/selection.cljs @@ -51,9 +51,9 @@ content (get-in state (st/get-path state :content)) selected-point? #(gsh/has-point-rect? selrect %) selected-points (get-in state [:workspace-local :edit-path id :selected-points]) - positions (into (if shift? selected-points #{}) - (comp (map (comp gpt/point :params)) + (comp (filter #(not (= (:command %) :close-path))) + (map (comp gpt/point :params)) (filter selected-point?)) content)] (cond-> state From 2c96ecac8718b7a1e8c598df5601babca47fbfb6 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 7 May 2021 11:50:31 +0200 Subject: [PATCH 2/5] :bug: Fix wrong query for obtain profile default project-id. --- CHANGES.md | 1 + backend/src/app/rpc/queries/profile.clj | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 75192a939..79a1f21ad 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ ### :bug: Bugs fixed - Fix problem with `close-path` command [#917](https://github.com/penpot/penpot/issues/917) +- Fix wrong query for obtain the profile default project-id ## 1.5.1-alpha diff --git a/backend/src/app/rpc/queries/profile.clj b/backend/src/app/rpc/queries/profile.clj index 8016b3d94..ee974c359 100644 --- a/backend/src/app/rpc/queries/profile.clj +++ b/backend/src/app/rpc/queries/profile.clj @@ -41,29 +41,27 @@ {:id uuid/zero :fullname "Anonymous User"})) -;; NOTE: this query make the assumption that union all preserves the -;; order so the first id will always be the team id and the second the -;; project_id; this is a postgresql behavior because UNION ALL works -;; like APPEND operation. - -(def ^:private sql:default-team-and-project - "select t.id +(def ^:private sql:default-profile-team + "select t.id, name from team as t inner join team_profile_rel as tp on (tp.team_id = t.id) where tp.profile_id = ? and tp.is_owner is true - and t.is_default is true - union all - select p.id + and t.is_default is true") + +(def ^:private sql:default-profile-project + "select p.id, name from project as p inner join project_profile_rel as tp on (tp.project_id = p.id) where tp.profile_id = ? and tp.is_owner is true - and p.is_default is true") + and p.is_default is true + and p.team_id = ?") (defn retrieve-additional-data [conn id] - (let [[team project] (db/exec! conn [sql:default-team-and-project id id])] + (let [team (db/exec-one! conn [sql:default-profile-team id]) + project (db/exec-one! conn [sql:default-profile-project id (:id team)])] {:default-team-id (:id team) :default-project-id (:id project)})) From 5e0101e424e9f5730e464a83e07f3188f1d3e0b5 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 7 May 2021 12:50:31 +0200 Subject: [PATCH 3/5] :bug: Fixes problem with edition state and paths --- frontend/src/app/main/data/workspace.cljs | 7 +++++-- frontend/src/app/main/data/workspace/path/edition.cljs | 10 +++++++--- frontend/src/app/main/data/workspace/path/helpers.cljs | 2 ++ frontend/src/app/main/data/workspace/path/tools.cljs | 5 ++++- frontend/src/app/main/data/workspace/path/undo.cljs | 3 ++- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 746abd5ec..0546fe18b 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -240,10 +240,13 @@ (ptk/reify ::finalize-page ptk/UpdateEvent (update [_ state] - (let [local (:workspace-local state)] + (let [local (-> (:workspace-local state) + (dissoc :edition) + (dissoc :edit-path) + (dissoc :selected))] (-> state (assoc-in [:workspace-cache page-id] local) - (dissoc :current-page-id :workspace-local :trimmed-page)))))) + (dissoc :current-page-id :workspace-local :trimmed-page :workspace-drawing)))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Workspace Page CRUD diff --git a/frontend/src/app/main/data/workspace/path/edition.cljs b/frontend/src/app/main/data/workspace/path/edition.cljs index ad4f5ce24..b2217ea5e 100644 --- a/frontend/src/app/main/data/workspace/path/edition.cljs +++ b/frontend/src/app/main/data/workspace/path/edition.cljs @@ -9,6 +9,7 @@ [app.common.data :as d] [app.common.geom.point :as gpt] [app.common.math :as mth] + [app.main.data.workspace.common :as dwc] [app.main.data.workspace.changes :as dch] [app.main.data.workspace.path.changes :as changes] [app.main.data.workspace.path.common :as common] @@ -63,9 +64,12 @@ [rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)] - (rx/of (dch/commit-changes rch uch {:commit-local? true}) - (selection/update-selection point-change) - (fn [state] (update-in state [:workspace-local :edit-path id] dissoc :content-modifiers :moving-nodes :moving-handler))))))) + (if (empty? new-content) + (rx/of (dch/commit-changes rch uch {:commit-local? true}) + dwc/clear-edition-mode) + (rx/of (dch/commit-changes rch uch {:commit-local? true}) + (selection/update-selection point-change) + (fn [state] (update-in state [:workspace-local :edit-path id] dissoc :content-modifiers :moving-nodes :moving-handler)))))))) (defn modify-content-point [content {dx :x dy :y} modifiers point] diff --git a/frontend/src/app/main/data/workspace/path/helpers.cljs b/frontend/src/app/main/data/workspace/path/helpers.cljs index 9f5fb0621..a1185b421 100644 --- a/frontend/src/app/main/data/workspace/path/helpers.cljs +++ b/frontend/src/app/main/data/workspace/path/helpers.cljs @@ -21,6 +21,8 @@ (defn end-path-event? [{:keys [type shift] :as event}] (or (= (ptk/type event) ::common/finish-path) (= (ptk/type event) :esc-pressed) + (= :app.main.data.workspace.common/clear-edition-mode (ptk/type event)) + (= :app.main.data.workspace/finalize-page (ptk/type event)) (= event :interrupt) ;; ESC (and (ms/mouse-double-click? event)))) diff --git a/frontend/src/app/main/data/workspace/path/tools.cljs b/frontend/src/app/main/data/workspace/path/tools.cljs index b1c49f754..2db369397 100644 --- a/frontend/src/app/main/data/workspace/path/tools.cljs +++ b/frontend/src/app/main/data/workspace/path/tools.cljs @@ -8,6 +8,7 @@ (:require [app.common.geom.point :as gpt] [app.main.data.workspace.changes :as dch] + [app.main.data.workspace.common :as dwc] [app.main.data.workspace.path.changes :as changes] [app.main.data.workspace.path.common :as common] [app.main.data.workspace.path.state :as st] @@ -34,7 +35,9 @@ new-content (-> (tool-fn (:content shape) points) (ups/close-subpaths)) [rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)] - (rx/of (dch/commit-changes rch uch {:commit-local? true}))))))) + (rx/of (dch/commit-changes rch uch {:commit-local? true}) + (when (empty? new-content) + dwc/clear-edition-mode))))))) (defn make-corner ([] diff --git a/frontend/src/app/main/data/workspace/path/undo.cljs b/frontend/src/app/main/data/workspace/path/undo.cljs index 061de999d..74c8fcb34 100644 --- a/frontend/src/app/main/data/workspace/path/undo.cljs +++ b/frontend/src/app/main/data/workspace/path/undo.cljs @@ -124,7 +124,8 @@ dissoc :undo-lock :undo-stack))))) (defn- stop-undo? [event] - (= :app.main.data.workspace.common/clear-edition-mode (ptk/type event))) + (or (= :app.main.data.workspace.common/clear-edition-mode (ptk/type event)) + (= :app.main.data.workspace/finalize-page (ptk/type event)))) (def path-content-ref (letfn [(selector [state] From 3bb3fcfbda9aae8746680cf2eafbe573c00acd34 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 7 May 2021 13:05:45 +0200 Subject: [PATCH 4/5] :bug: Fix problems with empty paths and shortcuts --- CHANGES.md | 1 + .../app/main/data/workspace/path/tools.cljs | 16 +-- frontend/src/app/util/path/tools.cljs | 109 +++++++++--------- 3 files changed, 64 insertions(+), 62 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 79a1f21ad..d7c96478f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ - Fix problem with `close-path` command [#917](https://github.com/penpot/penpot/issues/917) - Fix wrong query for obtain the profile default project-id +- Fix problems with empty paths and shortcuts [#923](https://github.com/penpot/penpot/issues/923) ## 1.5.1-alpha diff --git a/frontend/src/app/main/data/workspace/path/tools.cljs b/frontend/src/app/main/data/workspace/path/tools.cljs index 2db369397..a6771a54f 100644 --- a/frontend/src/app/main/data/workspace/path/tools.cljs +++ b/frontend/src/app/main/data/workspace/path/tools.cljs @@ -30,14 +30,16 @@ id (st/get-path-id state) page-id (:current-page-id state) shape (get-in state (st/get-path state)) + selected-points (get-in state [:workspace-local :edit-path id :selected-points] #{}) - points (or points selected-points) - new-content (-> (tool-fn (:content shape) points) - (ups/close-subpaths)) - [rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)] - (rx/of (dch/commit-changes rch uch {:commit-local? true}) - (when (empty? new-content) - dwc/clear-edition-mode))))))) + points (or points selected-points)] + (when-not (empty? points) + (let [new-content (-> (tool-fn (:content shape) points) + (ups/close-subpaths)) + [rch uch] (changes/generate-path-changes objects page-id shape (:content shape) new-content)] + (rx/of (dch/commit-changes rch uch {:commit-local? true}) + (when (empty? new-content) + dwc/clear-edition-mode))))))))) (defn make-corner ([] diff --git a/frontend/src/app/util/path/tools.cljs b/frontend/src/app/util/path/tools.cljs index ff8196027..c352196b5 100644 --- a/frontend/src/app/util/path/tools.cljs +++ b/frontend/src/app/util/path/tools.cljs @@ -8,14 +8,10 @@ (:require [app.common.data :as d] [app.common.geom.point :as gpt] - [app.common.geom.shapes.path :as gshp] - [app.util.svg :as usvg] - [cuerdas.core :as str] - [clojure.set :as set] [app.common.math :as mth] [app.util.path.commands :as upc] [app.util.path.geom :as upg] - )) + [clojure.set :as set])) (defn remove-line-curves "Remove all curves that have both handlers in the same position that the @@ -235,70 +231,73 @@ to keep everything consistent" [content points] - (let [content (d/with-prev content)] + (if (empty? points) + content - (loop [result [] - last-handler nil - [cur-cmd prev-cmd] (first content) - content (rest content)] + (let [content (d/with-prev content)] - (if (nil? cur-cmd) - ;; The result with be an array of arrays were every entry is a subpath - (->> result - ;; remove empty and only 1 node subpaths - (filter #(> (count %) 1)) - ;; flatten array-of-arrays plain array - (flatten) - (into [])) + (loop [result [] + last-handler nil + [cur-cmd prev-cmd] (first content) + content (rest content)] - (let [move? (= :move-to (:command cur-cmd)) - curve? (= :curve-to (:command cur-cmd)) + (if (nil? cur-cmd) + ;; The result with be an array of arrays were every entry is a subpath + (->> result + ;; remove empty and only 1 node subpaths + (filter #(> (count %) 1)) + ;; flatten array-of-arrays plain array + (flatten) + (into [])) - ;; When the old command was a move we start a subpath - result (if move? (conj result []) result) + (let [move? (= :move-to (:command cur-cmd)) + curve? (= :curve-to (:command cur-cmd)) - subpath (peek result) + ;; When the old command was a move we start a subpath + result (if move? (conj result []) result) - point (upc/command->point cur-cmd) - - old-prev-point (upc/command->point prev-cmd) - new-prev-point (upc/command->point (peek subpath)) + subpath (peek result) - remove? (contains? points point) + point (upc/command->point cur-cmd) - - ;; We store the first handler for the first curve to be removed to - ;; use it for the first handler of the regenerated path - cur-handler (cond - (and (not last-handler) remove? curve?) - (select-keys (:params cur-cmd) [:c1x :c1y]) + old-prev-point (upc/command->point prev-cmd) + new-prev-point (upc/command->point (peek subpath)) - (not remove?) - nil + remove? (contains? points point) - :else - last-handler) - cur-cmd (cond-> cur-cmd - ;; If we're starting a subpath and it's not a move make it a move - (and (not move?) (empty? subpath)) - (assoc :command :move-to - :params (select-keys (:params cur-cmd) [:x :y])) + ;; We store the first handler for the first curve to be removed to + ;; use it for the first handler of the regenerated path + cur-handler (cond + (and (not last-handler) remove? curve?) + (select-keys (:params cur-cmd) [:c1x :c1y]) - ;; If have a curve the first handler will be relative to the previous - ;; point. We change the handler to the new previous point - (and curve? (not (empty? subpath)) (not= old-prev-point new-prev-point)) - (update :params merge last-handler)) + (not remove?) + nil - head-idx (dec (count result)) + :else + last-handler) - result (cond-> result - (not remove?) - (update head-idx conj cur-cmd))] - (recur result - cur-handler - (first content) - (rest content))))))) + cur-cmd (cond-> cur-cmd + ;; If we're starting a subpath and it's not a move make it a move + (and (not move?) (empty? subpath)) + (assoc :command :move-to + :params (select-keys (:params cur-cmd) [:x :y])) + + ;; If have a curve the first handler will be relative to the previous + ;; point. We change the handler to the new previous point + (and curve? (not (empty? subpath)) (not= old-prev-point new-prev-point)) + (update :params merge last-handler)) + + head-idx (dec (count result)) + + result (cond-> result + (not remove?) + (update head-idx conj cur-cmd))] + (recur result + cur-handler + (first content) + (rest content)))))))) (defn join-nodes "Creates new segments between points that weren't previously" From 4405bd95f9055dc1da9a869034176b0a4a31a6d0 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 7 May 2021 13:15:48 +0200 Subject: [PATCH 5/5] :fire: Remove unused stacktrace. --- backend/src/app/loggers/mattermost.clj | 4 +--- version.txt | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/backend/src/app/loggers/mattermost.clj b/backend/src/app/loggers/mattermost.clj index ec5d8b52e..1366a7edf 100644 --- a/backend/src/app/loggers/mattermost.clj +++ b/backend/src/app/loggers/mattermost.clj @@ -65,9 +65,7 @@ "- detail: " (cfg/get :public-uri) "/dbg/error-by-id/" id "\n" "- profile-id: `" (:profile-id cdata) "`\n" "- host: `" host "`\n" - "- version: `" version "`\n" - (when error - (str "```\n" (:trace error) "\n```"))) + "- version: `" version "`\n") rsp (http/send! {:uri uri :method :post :headers {"content-type" "application/json"} diff --git a/version.txt b/version.txt index 1433486b4..32b4157fc 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.5.0-alpha +1.5.2-alpha