mirror of
https://github.com/penpot/penpot.git
synced 2026-11-21 01:22:01 +00:00
🐛 Add a grid track to a board built without track lists
The schema and the file builder accept a grid board without `:layout-grid-rows` or `:layout-grid-columns`. Adding a child to such a board assigns it a cell, which adds a first track to a nil list, and `d/add-at-index` asserts on anything but a vector, so the edit crashed. Start a missing track list from an empty one. The regression asserts before the fix and passes after it: the child gets row 1, column 1 and each list one default track. Full common passes lint, JVM, JavaScript and formatting: JVM 2076 tests / 33907 assertions; JavaScript 2012 / 32502. Compare lower-quantile milliseconds with the saved baseline; keep that baseline unchanged. The machine/JVM warning makes ratios rough. No world is flagged. World Baseline Now Ratio Main into 10 copies 1.790 1.003 0.56 Main into 100 copies 15.415 9.979 0.65 Main into 1000 copies 153.086 102.913 0.67 Three nesting levels 35.215 21.423 0.61 Dependency chain 68.931 36.376 0.53 Library update 83.083 46.632 0.56 Many plain shapes 4.837 2.303 0.48 Variant switch 32.052 21.650 0.68 AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
2a71cf0292
commit
15f654aa1d
@ -809,7 +809,8 @@
|
||||
layout-grid-cells))]
|
||||
|
||||
(-> parent
|
||||
(update tracks-prop d/add-at-index new-index value)
|
||||
;; A grid built without track lists starts from none.
|
||||
(update tracks-prop #(d/add-at-index (or % []) new-index value))
|
||||
(assoc :layout-grid-cells layout-grid-cells)))))
|
||||
|
||||
(defn add-grid-column
|
||||
|
||||
@ -176,6 +176,26 @@
|
||||
(t/is (= [[1 1] [2 1] [1 2]] (child-coords row row-ids)))
|
||||
(t/is (= (child-coords row row-ids) (child-coords absent absent-ids)))))
|
||||
|
||||
(t/deftest a-grid-without-track-lists-assigns-its-children
|
||||
;; Library imports may build a grid board without track lists.
|
||||
(let [board-id (uuid/next)
|
||||
child-id (uuid/next)
|
||||
state (-> (fb/create-state)
|
||||
(fb/add-file {:name "Grid file"})
|
||||
(fb/add-page {:name "Page 1"})
|
||||
(fb/add-board {:id board-id :name "Grid" :x 0 :y 0 :width 200 :height 200
|
||||
:layout :grid})
|
||||
(fb/add-shape {:id child-id :type :rect :name "Rect" :x 0 :y 0 :width 10 :height 10}))
|
||||
objects (fb/get-current-objects state)
|
||||
board (get objects board-id)
|
||||
after (layout/assign-cells board objects)]
|
||||
(t/is (nil? (:layout-grid-rows board)))
|
||||
(t/is (= [layout/default-track-value] (:layout-grid-rows after)))
|
||||
(t/is (= [layout/default-track-value] (:layout-grid-columns after)))
|
||||
(t/is (= [1 1] ((juxt :row :column) (layout/get-cell-by-shape-id after child-id))))
|
||||
(t/is (= [layout/default-track-value] (:layout-grid-columns (layout/add-grid-column board layout/default-track-value))))
|
||||
(t/is (= [layout/default-track-value] (:layout-grid-rows (layout/add-grid-row board layout/default-track-value))))))
|
||||
|
||||
(t/deftest fitting-a-grid-with-no-tracks-clears-empty-cells
|
||||
(doseq [rows [0 1] columns [0 1] :when (or (zero? rows) (zero? columns))]
|
||||
(let [cell (make-cell :row 1 :column 1)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user