🐛 Switch a variant set's layout between flex and grid in place

A variant set board or a variant main that already had a layout kept it
when the user picked the other type (Shift+A / Ctrl+Shift+A or the
context menu). `create-layout` sends a shape with a layout to
`create-layout-from-selection`, which refused any selection holding a
variant container or a variant, before reaching its in-place branch.

The refusal now applies only when the selection would be wrapped in a
new board; a single shape with a layout switches it in place.

Found by the components Qase run (PENPOT-2422).

Test: `create-layout-switches-a-variant-container-layout`,
`create-layout-switches-a-variant-main-layout` (groups-test).

AI-assisted-by: claude-opus-5-5
This commit is contained in:
alonso.torres 2026-11-19 09:46:31 +01:00
parent ccd43b4fc8
commit b7ee5d30ec
2 changed files with 37 additions and 1 deletions

View File

@ -209,7 +209,9 @@
new-shape-id (uuid/next)
undo-id (js/Symbol)]
(if (or has-variant? has-container? crosses-set?)
;; Only a selection that gets wrapped in a new board is refused; a
;; shape that already has a layout switches it in place.
(if (and (not has-layout?) (or has-variant? has-container? crosses-set?))
(rx/empty)
(rx/concat
(rx/of (dwu/start-undo-transaction undo-id))

View File

@ -664,6 +664,40 @@
(t/is (= (:id board) (:parent-id main')))))
:commits commits))))
(t/deftest create-layout-switches-a-variant-container-layout
(t/async
done
(let [file (-> (variant-file)
(cths/update-shape :variant :layout :flex))
commits (atom [])]
(run file
[(dws/select-shapes (d/ordered-set (cthi/id :variant)))
(dwsl/create-layout :grid)]
done
(fn [state]
(let [board' (cths/get-shape (ths/get-file-from-state state) :variant)]
(t/is (pos? (count @commits)))
(t/is (ctl/grid-layout? board'))
(t/is (ctk/is-variant-container? board'))))
:commits commits))))
(t/deftest create-layout-switches-a-variant-main-layout
(t/async
done
(let [file (-> (variant-file)
(cths/update-shape :root1 :layout :grid))
commits (atom [])]
(run file
[(dws/select-shapes (d/ordered-set (cthi/id :root1)))
(dwsl/create-layout :flex)]
done
(fn [state]
(let [main' (cths/get-shape (ths/get-file-from-state state) :root1)]
(t/is (pos? (count @commits)))
(t/is (ctl/flex-layout? main'))
(t/is (ctk/is-variant? main'))))
:commits commits))))
(t/deftest create-layout-of-one-nested-child-commits
(t/async
done