From 0f994842473ac8ddcece862dd2cd1069197542e0 Mon Sep 17 00:00:00 2001 From: Sam Dornan Date: Thu, 17 Sep 2026 17:41:17 -0500 Subject: [PATCH] fix(v2): right-align the list-view quantity columns (#4603) --- .../v2/components/Gallery/GameListHeader.vue | 8 +- .../src/v2/components/Gallery/GameListRow.vue | 59 ++++-- .../Gallery/GameListSkeletonParity.test.ts | 184 +++++++++++++++++- .../Gallery/GameListSkeletonRow.vue | 13 +- .../src/v2/components/Gallery/listColumns.ts | 26 ++- 5 files changed, 263 insertions(+), 27 deletions(-) diff --git a/frontend/src/v2/components/Gallery/GameListHeader.vue b/frontend/src/v2/components/Gallery/GameListHeader.vue index a8e0fae48..8a92443c5 100644 --- a/frontend/src/v2/components/Gallery/GameListHeader.vue +++ b/frontend/src/v2/components/Gallery/GameListHeader.vue @@ -138,7 +138,7 @@ function handleClick(col: ListColumn) { .game-list-header { display: grid; align-items: center; - gap: 0 var(--r-space-3); + gap: 0 var(--r-space-5); padding: 0 var(--r-space-3); height: var(--r-list-header-h); background: var(--r-color-bg-elevated); @@ -175,6 +175,12 @@ function handleClick(col: ListColumn) { text-align: end; } +/* End-aligned labels hug the right edge, so the sort glyph goes on the + label's left. Appending it would shove the label sideways on click. */ +.game-list-header__cell--end .game-list-header__icon { + order: -1; +} + .game-list-header__cell--sortable { cursor: pointer; } diff --git a/frontend/src/v2/components/Gallery/GameListRow.vue b/frontend/src/v2/components/Gallery/GameListRow.vue index 7da67f676..77c88e329 100644 --- a/frontend/src/v2/components/Gallery/GameListRow.vue +++ b/frontend/src/v2/components/Gallery/GameListRow.vue @@ -38,6 +38,7 @@ import { activeProviders } from "@/v2/utils/metadataProviders"; import { getListColumns, getListGridTemplate, + type ListColumn, LIST_COVER_HEIGHT_PX, LIST_COVER_WIDTH_PX, LIST_TITLE_SKELETON_BARS, @@ -125,6 +126,16 @@ const gridStyle = computed(() => ({ })); const titleSkeletonGapStyle = { gap: `${LIST_TITLE_SKELETON_GAP_PX}px` }; +/** Alignment / figure modifiers for a cell, read off the column config so + * the body cannot drift from the header above it. */ +function cellModifiers(key: ListColumn["key"]) { + const column = columns.value.find((col) => col.key === key); + return { + "game-list-row__cell--end": column?.align === "end", + "game-list-row__cell--num": column?.numeric === true, + }; +} + const platformMeta = computed(() => { const item = rom.value; if (!item || item.platform_id == null) return null; @@ -367,13 +378,27 @@ function onRowPointerEnd() { -
+
{{ rom.fs_size_bytes ? formatBytes(rom.fs_size_bytes) : "—" }}
-
{{ formatDate(rom.created_at) }}
-
{{ releaseDate(rom) }}
-
{{ ratingValue(rom) }}
-
{{ lengthValue(rom) }}
+
+ {{ formatDate(rom.created_at) }} +
+
+ {{ releaseDate(rom) }} +
+
+ {{ ratingValue(rom) }} +
+
+ {{ lengthValue(rom) }} +
@@ -426,7 +451,7 @@ function onRowPointerEnd() { />
-
+
-
+
@@ -505,7 +535,7 @@ function onRowPointerEnd() { .game-list-row { display: grid; align-items: center; - gap: 0 var(--r-space-3); + gap: 0 var(--r-space-5); padding: 0 var(--r-space-3); height: var(--r-list-row-h); border-bottom: 1px solid var(--r-color-border); @@ -565,9 +595,16 @@ function onRowPointerEnd() { text-overflow: ellipsis; } +/* Quantities and dates pin to the column's right edge, so the digits line up + down the column instead of stepping with the unit or month width. */ .game-list-row__cell--end { - display: flex; - justify-content: flex-end; + text-align: end; +} + +/* Tabular figures for the digit columns: proportional digits make the + column ragged even at a fixed width. */ +.game-list-row__cell--num { + font-variant-numeric: tabular-nums; } /* Cover sits in its own fixed-width column (centred) so the title/meta diff --git a/frontend/src/v2/components/Gallery/GameListSkeletonParity.test.ts b/frontend/src/v2/components/Gallery/GameListSkeletonParity.test.ts index 403a20d83..408b188a9 100644 --- a/frontend/src/v2/components/Gallery/GameListSkeletonParity.test.ts +++ b/frontend/src/v2/components/Gallery/GameListSkeletonParity.test.ts @@ -1,9 +1,11 @@ import { mount } from "@vue/test-utils"; import { createPinia, setActivePinia } from "pinia"; import { beforeEach, describe, expect, it, vi } from "vitest"; +import type { RomMetadataSchema, RomUserSchema } from "@/__generated__"; +import type { SimpleRom } from "@/v2/stores/galleryRoms"; import GameListRow from "./GameListRow.vue"; import GameListSkeletonRow from "./GameListSkeletonRow.vue"; -import { LIST_COVER_TRACK_PX } from "./listColumns"; +import { getListColumns, LIST_COVER_TRACK_PX } from "./listColumns"; vi.mock("vue-i18n", () => ({ useI18n: () => ({ t: (key: string) => key, locale: { value: "en" } }), @@ -24,20 +26,196 @@ function shapes(row: HTMLElement): string[][] { ); } +/** Per-column right-edge flag, in column order. */ +function rightEdges(row: HTMLElement): boolean[] { + return Array.from(row.children).map((cell) => + Array.from(cell.classList).some((name) => name.endsWith("--end")), + ); +} + +/** Per-column tabular-figure flag, in column order. */ +function tabularFigures(row: HTMLElement): boolean[] { + return Array.from(row.children).map((cell) => + cell.classList.contains("game-list-row__cell--num"), + ); +} + +const ROM_USER: RomUserSchema = { + id: 1, + user_id: 1, + rom_id: 1, + created_at: "2026-01-02T00:00:00Z", + updated_at: "2026-01-02T00:00:00Z", + last_played: null, + is_main_sibling: true, + backlogged: false, + now_playing: false, + hidden: false, + rating: 0, + difficulty: 0, + completion: 0, + status: null, +}; + +const METADATUM: RomMetadataSchema = { + rom_id: 1, + genres: [], + franchises: [], + collections: [], + companies: [], + publishers: [], + developers: [], + game_modes: [], + age_ratings: [], + player_count: "1", + first_release_date: Date.UTC(1995, 7, 11), + average_rating: 9.1, +}; + +/** A complete `SimpleRom`, so a new required field breaks the build instead of + * hiding behind a cast. Tests override only the fields they read. */ +const ROM_DEFAULTS: SimpleRom = { + id: 1, + igdb_id: null, + sgdb_id: null, + moby_id: null, + ss_id: null, + ra_id: null, + launchbox_id: null, + hasheous_id: null, + tgdb_id: null, + flashpoint_id: null, + hltb_id: null, + demozoo_id: null, + pouet_id: null, + csdb_id: null, + steam_id: null, + gamelist_id: null, + libretro_id: null, + platform_id: 1, + platform_slug: "snes", + platform_fs_slug: "snes", + platform_custom_name: null, + platform_display_name: "Super Nintendo", + fs_name: "Chrono Trigger.sfc", + fs_name_no_tags: "Chrono Trigger", + fs_name_no_ext: "Chrono Trigger", + fs_extension: "sfc", + fs_path: "snes/Chrono Trigger.sfc", + fs_size_bytes: 4_194_304, + name: "Chrono Trigger", + name_sort_key: "chrono trigger", + slug: "chrono-trigger", + summary: null, + alternative_names: [], + youtube_video_id: null, + metadatum: METADATUM, + igdb_metadata: null, + moby_metadata: null, + ss_metadata: null, + launchbox_metadata: null, + hasheous_metadata: null, + flashpoint_metadata: null, + hltb_metadata: { main_story: 23 }, + demozoo_metadata: null, + pouet_metadata: null, + csdb_metadata: null, + steam_metadata: null, + gamelist_metadata: null, + manual_metadata: null, + path_cover_small: null, + path_cover_large: null, + url_cover: null, + has_manual: false, + has_soundtrack: false, + path_manual: null, + url_manual: null, + path_video: null, + is_unidentified: false, + is_identified: true, + revision: null, + regions: ["USA"], + languages: ["en"], + tags: [], + crc_hash: null, + md5_hash: null, + sha1_hash: null, + ra_hash: null, + title_id: null, + save_target: null, + save_target_layout: null, + has_simple_single_file: true, + has_nested_single_file: false, + has_multiple_files: false, + full_path: "/romm/library/snes/Chrono Trigger.sfc", + created_at: "2026-01-02T00:00:00Z", + updated_at: "2026-01-02T00:00:00Z", + missing_from_fs: false, + is_physical: false, + has_file_on_disk: true, + upc: null, + has_notes: false, + rom_user: ROM_USER, + merged_screenshots: [], + merged_ra_metadata: null, + files: [], + sibling_roms: [], +}; + +function rom(overrides: Partial = {}): SimpleRom { + return { ...ROM_DEFAULTS, ...overrides }; +} + +function mountHydratedRow() { + return mount(GameListRow, { + props: { rom: rom() }, + global: { + stubs: { + GameActionBtn: true, + GameCard: true, + RCheckbox: true, + RChip: true, + RPlatformIcon: true, + RTooltip: true, + SiblingBadge: true, + }, + }, + }); +} + describe("list-mode skeleton row", () => { beforeEach(() => { setActivePinia(createPinia()); }); it("paints the bootstrap row's per-column shapes", () => { - // The bootstrap row hands over to the pending rows mid-load, so a shape - // that drifts between them moves the placeholders. + // A shape that drifts across the mid-load handover moves the placeholders. const pending = mount(GameListRow, { props: { position: 0 } }).element; const bootstrap = mount(GameListSkeletonRow).element; expect(shapes(pending)).toEqual(shapes(bootstrap)); }); + it("pins the quantity columns to the right edge in every flavour", () => { + // A cell that stops reading the column config drops left under its header. + const expected = getListColumns(true).map((col) => col.align === "end"); + const pending = mount(GameListRow, { props: { position: 0 } }).element; + const hydrated = mountHydratedRow().element; + const bootstrap = mount(GameListSkeletonRow).element; + + expect(rightEdges(pending)).toEqual(expected); + expect(rightEdges(hydrated)).toEqual(expected); + expect(rightEdges(bootstrap)).toEqual(expected); + }); + + it("renders the numeric columns in tabular figures", () => { + // Only the hydrated row has digits; nothing else catches a dropped `--num`. + const expected = getListColumns(true).map((col) => col.numeric === true); + const hydrated = mountHydratedRow().element; + + expect(tabularFigures(hydrated)).toEqual(expected); + }); + it("sizes the cover column off the art cap, not the measured ratios", () => { const grid = (row: HTMLElement) => row.style.gridTemplateColumns; const pending = mount(GameListRow, { props: { position: 0 } }).element; diff --git a/frontend/src/v2/components/Gallery/GameListSkeletonRow.vue b/frontend/src/v2/components/Gallery/GameListSkeletonRow.vue index 6e103b3eb..f64f332fb 100644 --- a/frontend/src/v2/components/Gallery/GameListSkeletonRow.vue +++ b/frontend/src/v2/components/Gallery/GameListSkeletonRow.vue @@ -93,7 +93,11 @@ const titleGapStyle = { gap: `${LIST_TITLE_SKELETON_GAP_PX}px` };
-
+
@@ -104,7 +108,7 @@ const titleGapStyle = { gap: `${LIST_TITLE_SKELETON_GAP_PX}px` }; .r-glr-skel { display: grid; align-items: center; - gap: 0 var(--r-space-3); + gap: 0 var(--r-space-5); padding: 0 var(--r-space-3); height: var(--r-list-row-h); border-bottom: 1px solid var(--r-color-border); @@ -114,9 +118,10 @@ const titleGapStyle = { gap: `${LIST_TITLE_SKELETON_GAP_PX}px` }; min-width: 0; } +/* Placeholders sit on the same edge as the value they stand in for, so + nothing shifts when the row hydrates. */ .r-glr-skel__cell--end { - display: flex; - justify-content: flex-end; + text-align: end; } /* Centre the cover block to match the real row. */ diff --git a/frontend/src/v2/components/Gallery/listColumns.ts b/frontend/src/v2/components/Gallery/listColumns.ts index bc3d971f6..7e871a3ef 100644 --- a/frontend/src/v2/components/Gallery/listColumns.ts +++ b/frontend/src/v2/components/Gallery/listColumns.ts @@ -37,7 +37,12 @@ export interface ListColumn { label: string; /** Whether the column header is clickable to toggle sort. */ sortable: boolean; + /** Column alignment, read by the header label, the value cells and the + * actions cell; the structural cells lay themselves out. */ align?: "start" | "end"; + /** Digit-bearing value, rendered in tabular figures so the column reads + * as a grid. */ + numeric?: boolean; /** Skeleton placeholder width (px) for this column's loading state. * `undefined` means the column owns a custom skeleton shape — the * title column paints cover + meta lines, the actions column paints @@ -71,35 +76,40 @@ export function getListColumns(showPlatform: boolean): readonly ListColumn[] { key: "fs_size_bytes", label: "Size", sortable: true, - align: "start", + align: "end", + numeric: true, skeletonWidth: 60, }, { key: "created_at", label: "Added", sortable: true, - align: "start", + align: "end", + numeric: true, skeletonWidth: 64, }, { key: "first_release_date", label: "Released", sortable: true, - align: "start", + align: "end", + numeric: true, skeletonWidth: 40, }, { key: "average_rating", label: "Rating", sortable: true, - align: "start", + align: "end", + numeric: true, skeletonWidth: 32, }, { key: "hltb_main_story", label: "Length", sortable: true, - align: "start", + align: "end", + numeric: true, skeletonWidth: 40, }, { @@ -125,7 +135,7 @@ export function getListColumns(showPlatform: boolean): readonly ListColumn[] { // natural min-width (below) derive from the same numbers. const LIST_SELECT_TRACK_PX = 36; const LIST_PLATFORM_TRACK_PX = 200; -const LIST_METRIC_TRACKS_PX = [88, 96, 84, 56, 72, 110, 110, 88]; +const LIST_METRIC_TRACKS_PX = [88, 96, 96, 56, 72, 110, 110, 88]; /** Minimum width of the title column so it stays readable when the row is * scrolled horizontally on a narrow viewport (instead of collapsing to 0). */ export const LIST_TITLE_MIN_PX = 200; @@ -166,10 +176,10 @@ export function getListGridTemplate(showPlatform: boolean): string { return `${LIST_SELECT_TRACK_PX}px ${LIST_COVER_TRACK_PX}px minmax(${LIST_TITLE_MIN_PX}px, 1.6fr)${platformTrack} ${metrics}`; } -// The row/header grids also carry a `--r-space-3` column gap and a +// The row/header grids also carry a `--r-space-5` column gap and a // `--r-space-3` inline padding on each side (see GameListRow / GameListHeader), // which add to the natural width alongside the tracks. -const LIST_GRID_GAP_PX = 12; // --r-space-3 +const LIST_GRID_GAP_PX = 20; // --r-space-5 const LIST_ROW_PAD_X_PX = 12; // --r-space-3 (each side) /** The row's natural (minimum) width = every fixed track + the title's floor +