feat: drag-reorder slots
pool.reorder() permutes slots (validated permutation) and keeps the active selection on its slot; exposed via /grid_pool/reorder. The grid thumbnails are drag handles; dropping on another cell reorders. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -131,3 +131,23 @@ def test_set_mask_writes_sidecar(tmp_path):
|
||||
def test_set_mask_out_of_range_noop(tmp_path):
|
||||
m = pool.set_mask(str(tmp_path), "p1", 0, b"x")
|
||||
assert m["slots"] == []
|
||||
|
||||
|
||||
def test_reorder_slots_and_fixes_active(tmp_path):
|
||||
pool.add_image(str(tmp_path), "p1", b"a", ts=1)
|
||||
pool.add_image(str(tmp_path), "p1", b"b", ts=2)
|
||||
pool.add_image(str(tmp_path), "p1", b"c", ts=3)
|
||||
pool.set_active(str(tmp_path), "p1", 2) # active = img_0003
|
||||
m = pool.reorder(str(tmp_path), "p1", [2, 0, 1]) # new order: c, a, b
|
||||
assert [s["image"] for s in m["slots"]] == ["img_0003.png", "img_0001.png", "img_0002.png"]
|
||||
assert m["active"] == 0 # active followed its slot
|
||||
|
||||
|
||||
def test_reorder_invalid_is_noop(tmp_path):
|
||||
pool.add_image(str(tmp_path), "p1", b"a", ts=1)
|
||||
pool.add_image(str(tmp_path), "p1", b"b", ts=2)
|
||||
# not a permutation of range(2) -> unchanged
|
||||
assert [s["image"] for s in pool.reorder(str(tmp_path), "p1", [0])["slots"]] == \
|
||||
["img_0001.png", "img_0002.png"]
|
||||
assert [s["image"] for s in pool.reorder(str(tmp_path), "p1", [0, 5])["slots"]] == \
|
||||
["img_0001.png", "img_0002.png"]
|
||||
|
||||
@@ -29,3 +29,11 @@ def test_handle_set_mask(tmp_path):
|
||||
m = handlers.handle_set_mask(base, "p1", 0, b"MASKBYTES")
|
||||
assert m["slots"][0]["mask"] == "img_0001.mask.png"
|
||||
assert (tmp_path / "p1" / "img_0001.mask.png").read_bytes() == b"MASKBYTES"
|
||||
|
||||
|
||||
def test_handle_reorder(tmp_path):
|
||||
base = str(tmp_path)
|
||||
handlers.handle_add(base, "p1", _png_bytes(), "png", ts=1)
|
||||
handlers.handle_add(base, "p1", _png_bytes(), "png", ts=2)
|
||||
m = handlers.handle_reorder(base, "p1", [1, 0])
|
||||
assert [s["image"] for s in m["slots"]] == ["img_0002.png", "img_0001.png"]
|
||||
|
||||
Reference in New Issue
Block a user