From aa5e62a417096df5cf878b769e301b1d861012ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?andr=C3=A9s=20gonz=C3=A1lez?= Date: Tue, 24 Nov 2026 15:15:46 +0100 Subject: [PATCH] :bug: Fix SVG upload frame when the selection is inside a group (#13282) * :bug: Fix SVG upload frame when the selection is inside a group With a shape selected inside a group, an uploaded or pasted SVG goes into that group, but its frame-id came from the board under the drop point. When the two boards differ, the save fails with invalid-frame. Take the frame from the group instead. AI-assisted-by: claude-opus-5-5 * :bug: Keep SVG upload frame aligned with its parent Keep the SVG upload frame and parent from the same source. When a shape inside a group was selected, the frame for the new SVG came from the board under the cursor while the parent came from the group, so saving failed with invalid-frame. The parent and frame now come from one shared predicate, which also prevents a repeat of the original drift between two copies of the condition. Add the board-parent test for the frame branch this change rewrote, and make the group checker assert that the SVG exists and that its frame is the expected one. Add mutation evidence for both. AI-assisted-by: deepseek-v4.1-flash --------- Co-authored-by: Luis de Dios --- .../app/main/data/workspace/svg_upload.cljs | 21 ++-- .../logic/pasting_in_containers_test.cljs | 107 ++++++++++++++++++ 2 files changed, 120 insertions(+), 8 deletions(-) diff --git a/frontend/src/app/main/data/workspace/svg_upload.cljs b/frontend/src/app/main/data/workspace/svg_upload.cljs index 48a84f0b30..3f438739f7 100644 --- a/frontend/src/app/main/data/workspace/svg_upload.cljs +++ b/frontend/src/app/main/data/workspace/svg_upload.cljs @@ -88,15 +88,20 @@ base-id (:parent-id base) - frame-id (or frame-id - (if (or selected-frame? (empty? selected) - (not= :frame (dm/get-in objects [base-id :type]))) - (ctst/top-nested-frame objects position) - base-id)) + keep-parent? (not (or selected-frame? (empty? selected) (nil? base))) - parent-id (if (or selected-frame? (empty? selected) (nil? base)) - frame-id - base-id) + frame-id (or frame-id + (cond + (not keep-parent?) + (ctst/top-nested-frame objects position) + + (= :frame (dm/get-in objects [base-id :type])) + base-id + + :else + (dm/get-in objects [base-id :frame-id]))) + + parent-id (if keep-parent? base-id frame-id) [new-shape new-children] (sb/create-svg-shapes id svg-data position objects frame-id parent-id selected true) diff --git a/frontend/test/frontend_tests/logic/pasting_in_containers_test.cljs b/frontend/test/frontend_tests/logic/pasting_in_containers_test.cljs index 46602ebf2c..3a14c80b4b 100644 --- a/frontend/test/frontend_tests/logic/pasting_in_containers_test.cljs +++ b/frontend/test/frontend_tests/logic/pasting_in_containers_test.cljs @@ -5,6 +5,7 @@ ;; Copyright (c) KALEIDOS SUBSIDIARY SL (ns frontend-tests.logic.pasting-in-containers-test (:require + [app.common.data :as d] [app.common.geom.point :as gpt] [app.common.test-helpers.components :as cthc] [app.common.test-helpers.compositions :as ctho] @@ -16,6 +17,7 @@ [app.common.types.component :as ctk] [app.common.uuid :as uuid] [app.main.data.workspace :as dw] + [app.main.data.workspace.groups :as dwgr] [app.main.data.workspace.selection :as dws] [app.main.data.workspace.shapes :as dwsh] [app.main.data.workspace.svg-upload :as dwsvg] @@ -998,6 +1000,111 @@ (t/is (some? created')) (t/is (= (:id frame-blue) (:parent-id created'))))))))) +(defn- svg-upload-in-group-events + "Group `rect`, select it again inside the group and upload an SVG at + `position`." + [rect position] + (let [svg-data {:name "test.svg" + :attrs {:width 100 :height 100} + :content [{:tag :rect + :attrs {:x "10" :y "10" :width "20" :height "20"}}]}] + [(dws/select-shapes (d/ordered-set (:id rect))) + (dwgr/group-selected) + (dws/select-shapes (d/ordered-set (:id rect))) + (dwsvg/add-svg-shapes nil svg-data position nil)])) + +(defn- check-svg-in-group + [new-state expected-frame-id] + (let [file' (ths/get-file-from-state new-state) + objects (:objects (cthf/current-page file')) + svg' (->> (vals objects) + (filter #(= (:name %) "test")) + first) + parent' (get objects (:parent-id svg'))] + ;; The shape is created inside the group, with the group's frame + (t/is (some? svg')) + (t/is (= :group (:type parent'))) + (t/is (= expected-frame-id (:frame-id svg'))) + (t/is (= (:frame-id parent') (:frame-id svg'))) + (cthf/validate-file! file'))) + +(t/deftest svg-upload-in-group-inside-board-uses-group-frame + "Uploading an SVG with a selection inside a grouped board child keeps the board as frame, even with the cursor outside it" + (t/async + done + (let [;; ==== Setup + file (-> (cthf/sample-file :file1) + (ctho/add-frame :board {:name "board" :x 0 :y 0 :width 500 :height 500}) + (cths/add-sample-shape :rect1 :parent-label :board + :x 10 :y 10 :width 50 :height 50)) + store (ths/setup-store file) + + ;; ==== Action + events (svg-upload-in-group-events (cths/get-shape file :rect1) + (gpt/point 2000 2000))] + + (ths/run-store + store done events + (fn [new-state] + (check-svg-in-group new-state (:id (cths/get-shape file :board)))))))) + +(t/deftest svg-upload-in-group-at-root-uses-group-frame + "Uploading an SVG with a selection inside a group at the root keeps the root as frame, even with the cursor over a board" + (t/async + done + (let [;; ==== Setup + file (-> (cthf/sample-file :file1) + (ctho/add-frame :board {:name "board" :x 1000 :y 1000 :width 500 :height 500}) + (cths/add-sample-shape :rect1 :x 10 :y 10 :width 50 :height 50)) + store (ths/setup-store file) + + ;; ==== Action + events (svg-upload-in-group-events (cths/get-shape file :rect1) + (gpt/point 1200 1200))] + + (ths/run-store + store done events + (fn [new-state] + (check-svg-in-group new-state uuid/zero)))))) + +(t/deftest svg-upload-in-board-keeps-parent-board + "Uploading an SVG with a shape selected directly in a board keeps that board as frame, even with the cursor over another board" + (t/async + done + (let [;; ==== Setup + file (-> (cthf/sample-file :file1) + (ctho/add-frame :board-a {:name "board-a" :x 0 :y 0 :width 500 :height 500}) + (ctho/add-frame :board-b {:name "board-b" :x 1000 :y 1000 :width 500 :height 500}) + (cths/add-sample-shape :rect1 :parent-label :board-a + :x 10 :y 10 :width 50 :height 50)) + store (ths/setup-store file) + + ;; ==== Action + svg-data {:name "test.svg" + :attrs {:width 100 :height 100} + :content [{:tag :rect + :attrs {:x "10" :y "10" :width "20" :height "20"}}]} + + events [(dws/select-shapes (d/ordered-set (:id (cths/get-shape file :rect1)))) + (dwsvg/add-svg-shapes nil svg-data (gpt/point 1200 1200) nil)]] + + (ths/run-store + store done events + (fn [new-state] + (let [;; ==== Get + file' (ths/get-file-from-state new-state) + objects (:objects (cthf/current-page file')) + svg' (->> (vals objects) + (filter #(= (:name %) "test")) + first) + board-a (cths/get-shape file :board-a)] + + ;; ==== Check + (t/is (some? svg')) + (t/is (= (:id board-a) (:frame-id svg'))) + (t/is (= (:id board-a) (:parent-id svg'))) + (cthf/validate-file! file'))))))) + (t/deftest props-paste-with-unloaded-page-is-noop "Pasting props while the page is not loaded is ignored instead of crashing" (t/async