[WC-3505]: Gallery pagination design properties are not applied - #2388
[WC-3505]: Gallery pagination design properties are not applied#2388yordan-st wants to merge 10 commits into
Conversation
267ca2a to
b97098c
Compare
There was a problem hiding this comment.
I don't know - did you tried to read this file by yourself @yordan-st ? 😄
IMO, this file full of unnecessary TS gymnastics. The logic should be more straightforward.
We have 3 placements and 3 elements and it probably not going to change anytime soon.
For example:
if (zones[zone] === null) {
zones[zone] = occupant;
} else {
zones.end = occupant;
}Wrapping loop around this if is very unnecessary. We can duplicate the check and do it inside param check.
In more detail:
Instead of if (params.hasCounter) { displaceable.push("counter"); } we can if (params.hasCounter) { zones[zone] = occupant; }
Also, I think word "occupant" is very alian for me here , let's use html slang instead and use word "element".
What also imporatant, instead of leaving big comment explaining dsiplacing, let's declare data sructure similar to natural zones (also rename it to default_slots) where each element has primary slot and fallback slot. (fallback would be end for both ,counter and loadmore).
TLDR:
- Reduce TS types to minimu, let's keep BarSlots (BarZones) and other required typoes
- Avoid loops, let's use ifs and direct slot (zone) check
iobuhov
left a comment
There was a problem hiding this comment.
One of the biggest changes I need is to replace word "zone" with "slot". Slot is more known term in frontend to denote areas where you can put your elements.
Please rewrite spec, comments, variables and other identifiers. Word "zone" is bit too alien.
| loadMore: null | ||
| }; | ||
|
|
||
| const render = (occupant: BarOccupant | null): ReactNode => (occupant ? occupants[occupant] : null); |
There was a problem hiding this comment.
rename to getElementForSlot
| hasPagination: showPagination || showCustomPagination | ||
| }); | ||
|
|
||
| const occupants: Record<BarOccupant, ReactNode> = { |
There was a problem hiding this comment.
rename occupants to elements
| hasPagination: showPagination || showCustomPagination | ||
| }); | ||
|
|
||
| const occupants: Record<BarOccupant, ReactNode> = { |
There was a problem hiding this comment.
This structure has problem (as well previous code) - SelectionCounter always get rendered - even if it's not visible. Solution would be extract his to small component that has switch case that returns one element. Also you can wrap Pagination to "FooterPagination" that combines "showCustomPagination" and normal Pagination. Same applies to TopBar. By default new component should return null.
This is "early" optimization, but it just also makes our intent more clear. Also
Pull request type
Bug fix (non-breaking change which fixes an issue)
Description
Gallery's
Paginationdesign property (Left / Center) has done nothing since the pagination overhaul. Its CSS keyed off a.widget-gallery-paginationwrapper that the overhaul deleted, so pagination was always right-aligned regardless of the setting.Restoring it is not a CSS change. Pagination now lives in a three-zone flex bar (
*-start/*-middle/*-end) where the zone, not the bar, decides position, and those zones are already used by the selection counter and the load more button. Overridingjustify-contentinside the end zone would centre pagination at ~83% of the bar width, and doing it with CSSorderor grid placement would reorder visually while leaving DOM order fixed — a WCAG 2.4.3 (Focus Order) and 1.3.2 (Meaningful Sequence) defect for a paging control.So placement is decided in markup by a pure function,
resolveZones:*-start*-middle*-middle*-start*-endThe rule is total: at most three occupants, three zones, and custom pagination replaces the built-in bar rather than adding to it, so at most one occupant is ever displaced. Displacement was chosen over wrapping to a second row because the counter appears dynamically at
selected > 0— wrapping would shift the page the moment a user selects their first item.The same result drives the footer, the top bar and the editor preview, so they cannot drift apart. That drift is what produced the second and third fixes below.
Also fixed here
Position of paginationat runtime — it always rendered below the gallery.Above gridnow renders it in the top bar.Bothrenders it once in the footer, because awidgetsplaceholder rendered twice would duplicate widget instances, DOM ids and state;check()now surfaces a warning explaining that.Design property changes (
data-widgets)Paginationis now a toggle button group with Atlas align icons, matching every other alignment control in Studio Pro, and gains an explicitRightoption.CE6083andCE6087in every existing app until a developer runs "Update all renamed design properties in project". Verified in Studio Pro during development..widget-gallery-paginationrules removed;fc-middle/tb-middleare now real flex zones so Center is centred by construction rather than incidentally.Accessibility note, intended: DOM order stays start → middle → end, so alignment now also determines tab and reading order —
Leftputs the paging controls before the Clear selection button. Visual and focus order stay in agreement, which the CSS-only alternatives could not achieve.Not in this PR: DataGrid 2's
-padding-topcontainer-query typo and its identical custom-pagination position bug ship separately so Gallery and DataGrid 2 changes stay reviewable apart. [WC-3547 Data Grid 2: Stack top bar in narrow containers](#2389 (comment))Tests: 145 unit tests pass (was 131).
resolveZonesis covered by an exhaustive 24-combination invariant pass; the bar components are asserted against real rendered DOM per zone.Planning artifacts:
packages/pluggableWidgets/gallery-web/openspec/changes/fix-gallery-pagination-placement/.What should be covered while testing?
Build both packages into a test project:
Pagination= Paging buttons. For each of Left / Center / Right, checkPosition of pagination= Below grid, Above grid, Both. Pagination should sit hard left, truly centred on the bar, or hard right, in both bars.Show selection count= Bottom. Select an item. With Left, pagination takes the left slot and the count moves right; with Center, the count stays left. Repeat withShow selection count= Top against the top bar.Pagination= Load more,Show total counton, selection active. Center should give: count left, paging status centred, Load more right.Above grid(renders in the top bar),Below grid(footer),Both(footer only, plus a warning on the widget in Studio Pro). Confirm alignment moves the custom widgets too.