Skip to content

Commit d6c8c8b

Browse files
authored
Fix snapshot ordering for multi-slot container elements (baserow#5366)
* Regenerating the builder-related templates, as the order+id combination was proving difficult to replicate on the graph side. * Lint fix
1 parent 33a66ba commit d6c8c8b

51 files changed

Lines changed: 1053 additions & 1035 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backend/src/baserow/contrib/builder/application_types.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,24 +586,42 @@ def serialize_for_regression_testing(self, builder: Builder) -> dict:
586586
keyed by page name. Used by snapshot tests to detect element-hierarchy
587587
regressions across template changes.
588588
589+
Children are grouped by slot (place_in_container) and slots are ordered by
590+
the minimum ``order`` value among their members, so the output is stable
591+
regardless of cross-slot insertion history.
592+
589593
:param builder: The builder application instance to serialize.
590594
:return: A dict mapping page names to their element-tree representation.
591595
"""
596+
from collections import defaultdict
597+
592598
from baserow.contrib.builder.elements.handler import ElementHandler
593599
from baserow.contrib.builder.pages.handler import PageHandler
594600

595601
result = {}
596602
for page in PageHandler().get_pages(builder):
597603
elements = list(ElementHandler().get_elements(page))
598-
# Elements are already ordered by (order, id) via Element.Meta.ordering.
604+
599605
by_parent: dict[int | None, list] = {}
600606
for el in elements:
601607
by_parent.setdefault(el.parent_element_id, []).append(el)
602608

603609
def build_tree(parent_id):
610+
children = by_parent.get(parent_id, [])
611+
by_slot: dict[str, list] = defaultdict(list)
612+
for el in children:
613+
by_slot[el.place_in_container or ""].append(el)
614+
ordered = []
615+
for slot in sorted(
616+
by_slot, key=lambda s: min(e.order for e in by_slot[s])
617+
):
618+
ordered.extend(sorted(by_slot[slot], key=lambda e: (e.order, e.id)))
604619
return [
605-
{"type": el.get_type().type, "children": build_tree(el.id)}
606-
for el in by_parent.get(parent_id, [])
620+
{
621+
"type": element.get_type().type,
622+
"children": build_tree(element.id),
623+
}
624+
for element in ordered
607625
]
608626

609627
result[page.name] = build_tree(None)

backend/tests/baserow/core/templates/__snapshots__/ab-testing.ambr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
dict({
5656
'children': list([
5757
]),
58-
'type': 'link',
58+
'type': 'text',
5959
}),
6060
dict({
6161
'children': list([
@@ -125,7 +125,7 @@
125125
dict({
126126
'children': list([
127127
]),
128-
'type': 'text',
128+
'type': 'link',
129129
}),
130130
]),
131131
'type': 'column',

backend/tests/baserow/core/templates/__snapshots__/ab_agency_theme.ambr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@
170170
]),
171171
'type': 'iframe',
172172
}),
173+
dict({
174+
'children': list([
175+
]),
176+
'type': 'text',
177+
}),
173178
dict({
174179
'children': list([
175180
dict({
@@ -190,11 +195,6 @@
190195
]),
191196
'type': 'form_container',
192197
}),
193-
dict({
194-
'children': list([
195-
]),
196-
'type': 'text',
197-
}),
198198
]),
199199
'type': 'column',
200200
}),
@@ -429,7 +429,7 @@
429429
dict({
430430
'children': list([
431431
]),
432-
'type': 'text',
432+
'type': 'link',
433433
}),
434434
dict({
435435
'children': list([
@@ -459,7 +459,7 @@
459459
dict({
460460
'children': list([
461461
]),
462-
'type': 'link',
462+
'type': 'text',
463463
}),
464464
dict({
465465
'children': list([

backend/tests/baserow/core/templates/__snapshots__/ab_baserow_theme.ambr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@
170170
]),
171171
'type': 'iframe',
172172
}),
173+
dict({
174+
'children': list([
175+
]),
176+
'type': 'text',
177+
}),
173178
dict({
174179
'children': list([
175180
dict({
@@ -190,11 +195,6 @@
190195
]),
191196
'type': 'form_container',
192197
}),
193-
dict({
194-
'children': list([
195-
]),
196-
'type': 'text',
197-
}),
198198
]),
199199
'type': 'column',
200200
}),
@@ -429,7 +429,7 @@
429429
dict({
430430
'children': list([
431431
]),
432-
'type': 'text',
432+
'type': 'link',
433433
}),
434434
dict({
435435
'children': list([
@@ -459,7 +459,7 @@
459459
dict({
460460
'children': list([
461461
]),
462-
'type': 'link',
462+
'type': 'text',
463463
}),
464464
dict({
465465
'children': list([

backend/tests/baserow/core/templates/__snapshots__/ab_coral_theme.ambr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@
170170
]),
171171
'type': 'iframe',
172172
}),
173+
dict({
174+
'children': list([
175+
]),
176+
'type': 'text',
177+
}),
173178
dict({
174179
'children': list([
175180
dict({
@@ -190,11 +195,6 @@
190195
]),
191196
'type': 'form_container',
192197
}),
193-
dict({
194-
'children': list([
195-
]),
196-
'type': 'text',
197-
}),
198198
]),
199199
'type': 'column',
200200
}),
@@ -429,7 +429,7 @@
429429
dict({
430430
'children': list([
431431
]),
432-
'type': 'text',
432+
'type': 'link',
433433
}),
434434
dict({
435435
'children': list([
@@ -459,7 +459,7 @@
459459
dict({
460460
'children': list([
461461
]),
462-
'type': 'link',
462+
'type': 'text',
463463
}),
464464
dict({
465465
'children': list([

backend/tests/baserow/core/templates/__snapshots__/ab_corporate_theme.ambr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@
170170
]),
171171
'type': 'iframe',
172172
}),
173+
dict({
174+
'children': list([
175+
]),
176+
'type': 'text',
177+
}),
173178
dict({
174179
'children': list([
175180
dict({
@@ -190,11 +195,6 @@
190195
]),
191196
'type': 'form_container',
192197
}),
193-
dict({
194-
'children': list([
195-
]),
196-
'type': 'text',
197-
}),
198198
]),
199199
'type': 'column',
200200
}),
@@ -429,7 +429,7 @@
429429
dict({
430430
'children': list([
431431
]),
432-
'type': 'text',
432+
'type': 'link',
433433
}),
434434
dict({
435435
'children': list([
@@ -459,7 +459,7 @@
459459
dict({
460460
'children': list([
461461
]),
462-
'type': 'link',
462+
'type': 'text',
463463
}),
464464
dict({
465465
'children': list([

backend/tests/baserow/core/templates/__snapshots__/ab_eclipse_theme.ambr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@
170170
]),
171171
'type': 'iframe',
172172
}),
173+
dict({
174+
'children': list([
175+
]),
176+
'type': 'text',
177+
}),
173178
dict({
174179
'children': list([
175180
dict({
@@ -190,11 +195,6 @@
190195
]),
191196
'type': 'form_container',
192197
}),
193-
dict({
194-
'children': list([
195-
]),
196-
'type': 'text',
197-
}),
198198
]),
199199
'type': 'column',
200200
}),
@@ -429,7 +429,7 @@
429429
dict({
430430
'children': list([
431431
]),
432-
'type': 'text',
432+
'type': 'link',
433433
}),
434434
dict({
435435
'children': list([
@@ -459,7 +459,7 @@
459459
dict({
460460
'children': list([
461461
]),
462-
'type': 'link',
462+
'type': 'text',
463463
}),
464464
dict({
465465
'children': list([

backend/tests/baserow/core/templates/__snapshots__/ab_education_theme.ambr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@
170170
]),
171171
'type': 'iframe',
172172
}),
173+
dict({
174+
'children': list([
175+
]),
176+
'type': 'text',
177+
}),
173178
dict({
174179
'children': list([
175180
dict({
@@ -190,11 +195,6 @@
190195
]),
191196
'type': 'form_container',
192197
}),
193-
dict({
194-
'children': list([
195-
]),
196-
'type': 'text',
197-
}),
198198
]),
199199
'type': 'column',
200200
}),
@@ -429,7 +429,7 @@
429429
dict({
430430
'children': list([
431431
]),
432-
'type': 'text',
432+
'type': 'link',
433433
}),
434434
dict({
435435
'children': list([
@@ -459,7 +459,7 @@
459459
dict({
460460
'children': list([
461461
]),
462-
'type': 'link',
462+
'type': 'text',
463463
}),
464464
dict({
465465
'children': list([

backend/tests/baserow/core/templates/__snapshots__/ab_finance_theme.ambr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@
170170
]),
171171
'type': 'iframe',
172172
}),
173+
dict({
174+
'children': list([
175+
]),
176+
'type': 'text',
177+
}),
173178
dict({
174179
'children': list([
175180
dict({
@@ -190,11 +195,6 @@
190195
]),
191196
'type': 'form_container',
192197
}),
193-
dict({
194-
'children': list([
195-
]),
196-
'type': 'text',
197-
}),
198198
]),
199199
'type': 'column',
200200
}),
@@ -429,7 +429,7 @@
429429
dict({
430430
'children': list([
431431
]),
432-
'type': 'text',
432+
'type': 'link',
433433
}),
434434
dict({
435435
'children': list([
@@ -459,7 +459,7 @@
459459
dict({
460460
'children': list([
461461
]),
462-
'type': 'link',
462+
'type': 'text',
463463
}),
464464
dict({
465465
'children': list([

backend/tests/baserow/core/templates/__snapshots__/ab_forest_theme.ambr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@
170170
]),
171171
'type': 'iframe',
172172
}),
173+
dict({
174+
'children': list([
175+
]),
176+
'type': 'text',
177+
}),
173178
dict({
174179
'children': list([
175180
dict({
@@ -190,11 +195,6 @@
190195
]),
191196
'type': 'form_container',
192197
}),
193-
dict({
194-
'children': list([
195-
]),
196-
'type': 'text',
197-
}),
198198
]),
199199
'type': 'column',
200200
}),
@@ -429,7 +429,7 @@
429429
dict({
430430
'children': list([
431431
]),
432-
'type': 'text',
432+
'type': 'link',
433433
}),
434434
dict({
435435
'children': list([
@@ -459,7 +459,7 @@
459459
dict({
460460
'children': list([
461461
]),
462-
'type': 'link',
462+
'type': 'text',
463463
}),
464464
dict({
465465
'children': list([

0 commit comments

Comments
 (0)