From 51fe27369ba330a5ad7e8798077bd82b4993bbf9 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Tue, 10 Oct 2023 18:07:15 +0200 Subject: [PATCH] :sparkles: Do not allow the creation of groups, masks nor boolean in copies --- common/src/app/common/pages/changes.cljc | 3 ++- common/src/app/common/pages/helpers.cljc | 2 +- .../partials/sidebar-element-options.scss | 5 ++++- .../src/app/main/data/workspace/bool.cljs | 18 ++++++++++++------ .../src/app/main/data/workspace/groups.cljs | 19 ++++++++++++------- .../data/workspace/path/shapes_to_path.cljs | 4 +++- .../sidebar/options/menus/component.cljs | 7 +++---- 7 files changed, 37 insertions(+), 21 deletions(-) diff --git a/common/src/app/common/pages/changes.cljc b/common/src/app/common/pages/changes.cljc index f0f773ec8d..8a32ef1205 100644 --- a/common/src/app/common/pages/changes.cljc +++ b/common/src/app/common/pages/changes.cljc @@ -109,7 +109,8 @@ [:parent-id ::sm/uuid] [:shapes :any] [:index {:optional true} [:maybe :int]] - [:after-shape {:optional true} :any]]] + [:after-shape {:optional true} :any] + [:component-swap {:optional true} :boolean]]] [:reorder-children [:map {:title "ReorderChildrenChange"} diff --git a/common/src/app/common/pages/helpers.cljc b/common/src/app/common/pages/helpers.cljc index 99a1562c5e..f4c1dc2418 100644 --- a/common/src/app/common/pages/helpers.cljc +++ b/common/src/app/common/pages/helpers.cljc @@ -531,7 +531,7 @@ (merge-path other-path item)))) [other-path last-item false])))) -(defn prev-path +(defn butlast-path "Remove the last item of the path." [path] (let [split (split-path path)] diff --git a/frontend/resources/styles/main/partials/sidebar-element-options.scss b/frontend/resources/styles/main/partials/sidebar-element-options.scss index cf88ddefd2..48d0a045a6 100644 --- a/frontend/resources/styles/main/partials/sidebar-element-options.scss +++ b/frontend/resources/styles/main/partials/sidebar-element-options.scss @@ -2668,8 +2668,10 @@ display: flex; align-items: center; margin-bottom: 0.5rem; + font-size: 12px; cursor: pointer; - svg, img { + svg, + img { background-color: $color-canvas; border-radius: $br4; border: 2px solid transparent; @@ -2697,6 +2699,7 @@ align-items: center; margin-bottom: 0.5rem; justify-content: space-between; + font-size: 12px; cursor: pointer; height: 24px; svg { diff --git a/frontend/src/app/main/data/workspace/bool.cljs b/frontend/src/app/main/data/workspace/bool.cljs index 1c0f1053c0..d0181e9b00 100644 --- a/frontend/src/app/main/data/workspace/bool.cljs +++ b/frontend/src/app/main/data/workspace/bool.cljs @@ -11,6 +11,7 @@ [app.common.pages.changes-builder :as pcb] [app.common.pages.helpers :as cph] [app.common.path.shapes-to-path :as stp] + [app.common.types.container :as ctn] [app.common.types.shape :as cts] [app.common.types.shape.layout :as ctl] [app.common.uuid :as uuid] @@ -92,7 +93,8 @@ ordered-indexes (cph/order-by-indexed-shapes objects ids) shapes (->> ordered-indexes (map (d/getf objects)) - (remove cph/frame-shape?))] + (remove cph/frame-shape?) + (remove #(ctn/has-any-copy-parent? objects %)))] (when-not (empty? shapes) (let [[boolean-data index] (create-bool-data bool-type name (reverse shapes) objects) @@ -114,7 +116,8 @@ (let [objects (wsh/lookup-page-objects state) change-to-bool (fn [shape] (group->bool shape bool-type objects))] - (rx/of (dch/update-shapes [shape-id] change-to-bool {:reg-objects? true})))))) + (when-not (ctn/has-any-copy-parent? objects (get objects shape-id)) + (rx/of (dch/update-shapes [shape-id] change-to-bool {:reg-objects? true}))))))) (defn bool-to-group [shape-id] @@ -124,14 +127,17 @@ (let [objects (wsh/lookup-page-objects state) change-to-group (fn [shape] (bool->group shape objects))] - (rx/of (dch/update-shapes [shape-id] change-to-group {:reg-objects? true})))))) + (when-not (ctn/has-any-copy-parent? objects (get objects shape-id)) + (rx/of (dch/update-shapes [shape-id] change-to-group {:reg-objects? true}))))))) (defn change-bool-type [shape-id bool-type] (ptk/reify ::change-bool-type ptk/WatchEvent - (watch [_ _ _] - (let [change-type + (watch [_ state _] + (let [objects (wsh/lookup-page-objects state) + change-type (fn [shape] (assoc shape :bool-type bool-type))] - (rx/of (dch/update-shapes [shape-id] change-type {:reg-objects? true})))))) + (when-not (ctn/has-any-copy-parent? objects (get objects shape-id)) + (rx/of (dch/update-shapes [shape-id] change-type {:reg-objects? true}))))))) diff --git a/frontend/src/app/main/data/workspace/groups.cljs b/frontend/src/app/main/data/workspace/groups.cljs index 33cb56f59b..51d1854e1a 100644 --- a/frontend/src/app/main/data/workspace/groups.cljs +++ b/frontend/src/app/main/data/workspace/groups.cljs @@ -12,6 +12,7 @@ [app.common.pages.changes-builder :as pcb] [app.common.pages.helpers :as cph] [app.common.types.component :as ctk] + [app.common.types.container :as ctn] [app.common.types.pages-list :as ctpl] [app.common.types.shape :as cts] [app.common.types.shape-tree :as ctst] @@ -226,8 +227,9 @@ (watch [it state _] (let [page-id (:current-page-id state) objects (wsh/lookup-page-objects state page-id) - selected (wsh/lookup-selected state) - selected (cph/clean-loops objects selected) + selected (->> (wsh/lookup-selected state) + (cph/clean-loops objects) + (remove #(ctn/has-any-copy-parent? objects (get objects %)))) shapes (shapes-for-grouping objects selected) parents (into #{} (map :parent-id) shapes)] (when-not (empty? shapes) @@ -264,7 +266,8 @@ (ctl/grid-layout? objects (:parent-id shape)) (pcb/update-shapes [(:parent-id shape)] ctl/assign-cells)))) - selected (wsh/lookup-selected state) + selected (->> (wsh/lookup-selected state) + (remove #(ctn/has-any-copy-parent? objects (get objects %)))) changes-list (sequence (keep prepare) selected) @@ -284,11 +287,12 @@ :origin it} undo-id (js/Symbol)] - (rx/of (dwu/start-undo-transaction undo-id) + (when-not (empty? selected) + (rx/of (dwu/start-undo-transaction undo-id) (dch/commit-changes changes) (ptk/data-event :layout/update parents) (dwu/commit-undo-transaction undo-id) - (dws/select-shapes child-ids)))))) + (dws/select-shapes child-ids))))))) (def mask-group (ptk/reify ::mask-group @@ -296,8 +300,9 @@ (watch [it state _] (let [page-id (:current-page-id state) objects (wsh/lookup-page-objects state page-id) - selected (wsh/lookup-selected state) - selected (cph/clean-loops objects selected) + selected (->> (wsh/lookup-selected state) + (cph/clean-loops objects) + (remove #(ctn/has-any-copy-parent? objects (get objects %)))) shapes (shapes-for-grouping objects selected) first-shape (first shapes)] (when-not (empty? shapes) diff --git a/frontend/src/app/main/data/workspace/path/shapes_to_path.cljs b/frontend/src/app/main/data/workspace/path/shapes_to_path.cljs index 5dbef4e97f..e82698eb9a 100644 --- a/frontend/src/app/main/data/workspace/path/shapes_to_path.cljs +++ b/frontend/src/app/main/data/workspace/path/shapes_to_path.cljs @@ -9,6 +9,7 @@ [app.common.pages.changes-builder :as pcb] [app.common.pages.helpers :as cph] [app.common.path.shapes-to-path :as upsp] + [app.common.types.container :as ctn] [app.main.data.workspace.changes :as dch] [app.main.data.workspace.state-helpers :as wsh] [beicon.core :as rx] @@ -20,7 +21,8 @@ (watch [it state _] (let [page-id (:current-page-id state) objects (wsh/lookup-page-objects state) - selected (wsh/lookup-selected state) + selected (->> (wsh/lookup-selected state) + (remove #(ctn/has-any-copy-parent? objects (get objects %)))) children-ids (into #{} diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs index d556be1ebe..d9f4619da8 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs @@ -17,7 +17,6 @@ [app.main.data.workspace.libraries :as dwl] [app.main.data.workspace.specialized-panel :as dwsp] [app.main.refs :as refs] - [app.main.render :refer [component-svg]] [app.main.store :as st] [app.main.ui.components.context-menu :refer [context-menu]] [app.main.ui.components.dropdown :refer [dropdown]] @@ -162,7 +161,7 @@ filters* (mf/use-state {:term "" :file-id (:component-file shape) - :path (cph/prev-path (:name shape))}) + :path (cph/butlast-path (:name shape))}) filters (deref filters*) components (-> (get-in libraries [(:file-id filters) :data :components]) @@ -173,7 +172,7 @@ (filter #(str/includes? (str/lower (:name %)) (str/lower (:term filters))) components)) groups (->> (map :path components) - (filter #(= (cph/prev-path (:path %)) (:path filters))) + (filter #(= (cph/butlast-path (:path %)) (:path filters))) (remove str/empty?) distinct (map #(hash-map :name %))) @@ -222,7 +221,7 @@ on-go-back (mf/use-fn (mf/deps (:path filters)) - #(swap! filters* assoc :path (cph/prev-path (:path filters)))) + #(swap! filters* assoc :path (cph/butlast-path (:path filters)))) on-enter-group (mf/use-fn #(swap! filters* assoc :path %))