Merge pull request #4136 from Spinnich/feat/platforms-search-fields

feat(v2): search platforms by slug, folder, category and family
This commit is contained in:
Georges-Antoine Assi
2026-08-07 16:06:04 -04:00
committed by GitHub
20 changed files with 170 additions and 5 deletions

View File

@@ -62,6 +62,7 @@
"reset-filters": "Нулирай филтрите",
"rom-count": "{n} ROM | {n} ROM-а",
"scan-platform": "Сканирай платформата",
"search-placeholder": "Търси по име, слъг, папка, категория…",
"search-platform": "Търси платформа",
"settings": "Настройки",
"show": "Покажи",

View File

@@ -62,6 +62,7 @@
"reset-filters": "Obnovit filtry",
"rom-count": "{n} ROMů | {n} ROM | {n} ROMy | {n} ROMů",
"scan-platform": "Skenovat platformu",
"search-placeholder": "Hledat podle názvu, slugu, složky, kategorie…",
"search-platform": "Hledat platformu",
"settings": "Nastavení",
"show": "Zobrazit",

View File

@@ -62,6 +62,7 @@
"reset-filters": "Filter zurücksetzen",
"rom-count": "{n} ROM | {n} ROMs",
"scan-platform": "Plattform scannen",
"search-placeholder": "Nach Name, Slug, Verzeichnis, Kategorie suchen…",
"search-platform": "Plattform suchen",
"settings": "Einstellungen",
"show": "Anzeigen",

View File

@@ -62,6 +62,7 @@
"reset-filters": "Reset filters",
"rom-count": "{n} ROM | {n} ROMs",
"scan-platform": "Scan platform",
"search-placeholder": "Search by name, slug, folder, category…",
"search-platform": "Search platform",
"settings": "Settings",
"show": "Show",

View File

@@ -62,6 +62,7 @@
"reset-filters": "Reset filters",
"rom-count": "{n} ROM | {n} ROMs",
"scan-platform": "Scan platform",
"search-placeholder": "Search by name, slug, folder, category…",
"search-platform": "Search platform",
"settings": "Settings",
"show": "Show",

View File

@@ -62,6 +62,7 @@
"reset-filters": "Restablecer filtros",
"rom-count": "{n} ROM | {n} ROMs",
"scan-platform": "Escanear plataforma",
"search-placeholder": "Buscar por nombre, slug, carpeta, categoría…",
"search-platform": "Buscar plataforma",
"settings": "Ajustes",
"show": "Mostrar",

View File

@@ -62,6 +62,7 @@
"reset-filters": "Réinitialiser les filtres",
"rom-count": "{n} ROM | {n} ROMs",
"scan-platform": "Analyser la plateforme",
"search-placeholder": "Rechercher par nom, slug, dossier, catégorie…",
"search-platform": "Recherche dans la plateforme",
"settings": "Paramètres",
"show": "Afficher",

View File

@@ -62,6 +62,7 @@
"reset-filters": "Szűrők visszaállítása",
"rom-count": "{n} ROM | {n} ROM",
"scan-platform": "Platform szkennelése",
"search-placeholder": "Keresés név, slug, mappa, kategória szerint…",
"search-platform": "Platform keresése",
"settings": "Beállítások",
"show": "Megjelenítés",

View File

@@ -62,6 +62,7 @@
"reset-filters": "Resetta filtri",
"rom-count": "{n} ROM | {n} ROM",
"scan-platform": "Scansiona piattaforma",
"search-placeholder": "Cerca per nome, slug, cartella, categoria…",
"search-platform": "Cerca Piattafroma",
"settings": "Impostazioni",
"show": "Mostra",

View File

@@ -62,6 +62,7 @@
"reset-filters": "フィルタをリセット",
"rom-count": "{n}件のROM | {n}件のROM",
"scan-platform": "プラットフォームをスキャン",
"search-placeholder": "名前、スラッグ、フォルダ、カテゴリで検索…",
"search-platform": "プラットフォームを検索",
"settings": "設定",
"show": "表示",

View File

@@ -62,6 +62,7 @@
"reset-filters": "필터 초기화",
"rom-count": "{n}개 ROM | {n}개 ROM",
"scan-platform": "플랫폼 스캔",
"search-placeholder": "이름, 슬러그, 폴더, 분류로 검색…",
"search-platform": "플랫폼 검색",
"settings": "설정",
"show": "표시",

View File

@@ -62,6 +62,7 @@
"reset-filters": "Zresetuj filtry",
"rom-count": "{n} ROM | {n} ROM-y | {n} ROM-ów",
"scan-platform": "Skanuj platformę",
"search-placeholder": "Szukaj po nazwie, slugu, folderze, kategorii…",
"search-platform": "Szukaj platformy",
"settings": "Ustawienia",
"show": "Pokaż",

View File

@@ -62,6 +62,7 @@
"reset-filters": "Redefinir filtros",
"rom-count": "{n} ROM | {n} ROMs",
"scan-platform": "Varrer plataforma",
"search-placeholder": "Buscar por nome, slug, pasta, categoria…",
"search-platform": "Buscar plataforma",
"settings": "Configurações",
"show": "Mostrar",

View File

@@ -62,6 +62,7 @@
"reset-filters": "Resetează filtrele",
"rom-count": "{n} ROM | {n} ROM-uri",
"scan-platform": "Scanează platforma",
"search-placeholder": "Caută după nume, slug, folder, categorie…",
"search-platform": "Căutare în platformă",
"settings": "Setări",
"show": "Afișează",

View File

@@ -62,6 +62,7 @@
"reset-filters": "Сбросить фильтры",
"rom-count": "{n} ROM | {n} ROM-ов",
"scan-platform": "Сканировать платформу",
"search-placeholder": "Поиск по названию, слагу, папке, категории…",
"search-platform": "Поиск платформы",
"settings": "Настройки",
"show": "Показать",

View File

@@ -62,6 +62,7 @@
"reset-filters": "Filtreleri sıfırla",
"rom-count": "{n} ROM | {n} ROM",
"scan-platform": "Platformu tara",
"search-placeholder": "Ad, slug, klasör, kategori ile ara…",
"search-platform": "Platform ara",
"settings": "Ayarlar",
"show": "Göster",

View File

@@ -62,6 +62,7 @@
"reset-filters": "重置筛选器",
"rom-count": "{n} 个 ROM | {n} 个 ROM",
"scan-platform": "扫描平台",
"search-placeholder": "按名称、Slug、文件夹、分类搜索…",
"search-platform": "搜索平台",
"settings": "设置",
"show": "显示",

View File

@@ -62,6 +62,7 @@
"reset-filters": "重置篩選器",
"rom-count": "{n} 個 ROM | {n} 個 ROM",
"scan-platform": "掃描平台",
"search-placeholder": "依名稱、網址關鍵字、資料夾、分類搜尋…",
"search-platform": "搜尋平台",
"settings": "設定",
"show": "顯示",

View File

@@ -12,8 +12,9 @@ vi.mock("vue-i18n", () => ({
// Plain object rather than a reactive route: every test sets the query
// before mounting, which is when the view reads it.
const { routeState } = vi.hoisted(() => ({
const { routeState, searchState } = vi.hoisted(() => ({
routeState: { query: {} as Record<string, string> },
searchState: { term: "" },
}));
vi.mock("vue-router", async (importOriginal) => ({
@@ -103,14 +104,19 @@ vi.mock("@/v2/composables/usePlatformPlayable", () => ({
}));
vi.mock("@/v2/composables/useTileSearchUrl", () => ({
useTileSearchUrl: () => ref(""),
useTileSearchUrl: () => ref(searchState.term),
}));
vi.mock("@/v2/composables/useWrapGridNav", () => ({
useWrapGridNav: vi.fn(),
}));
function platform(id: number, displayName: string, romCount: number): Platform {
function platform(
id: number,
displayName: string,
romCount: number,
overrides: Partial<Platform> = {},
): Platform {
return {
id,
display_name: displayName,
@@ -118,6 +124,7 @@ function platform(id: number, displayName: string, romCount: number): Platform {
slug: displayName.toLowerCase().replaceAll(" ", "-"),
fs_slug: displayName.toLowerCase().replaceAll(" ", "-"),
rom_count: romCount,
...overrides,
} as Platform;
}
@@ -125,6 +132,7 @@ describe("PlatformsIndex", () => {
beforeEach(() => {
setActivePinia(createPinia());
routeState.query = {};
searchState.term = "";
});
it("hides empty platforms by default", () => {
@@ -158,4 +166,133 @@ describe("PlatformsIndex", () => {
expect(wrapper.text()).toContain("platform.no-platforms-with-games");
});
describe("search", () => {
function seed() {
storePlatforms().set([
platform(1, "PlayStation", 30, {
slug: "ps",
fs_slug: "psx",
category: "console",
family_name: "PlayStation",
}),
platform(2, "Nintendo 64", 12, {
slug: "n64",
fs_slug: "nintendo-64",
category: "console",
family_name: "Nintendo",
}),
platform(3, "Game Boy Advance", 5, {
slug: "gba",
fs_slug: "gba-roms",
category: "portable_console",
family_name: "Nintendo",
}),
]);
}
it("matches on the display name", () => {
seed();
searchState.term = "advance";
const wrapper = mount(PlatformsIndex);
expect(wrapper.text()).toContain("Game Boy Advance 5");
expect(wrapper.text()).not.toContain("PlayStation 30");
expect(wrapper.text()).not.toContain("Nintendo 64 12");
});
it("matches on the slug", () => {
seed();
searchState.term = "n64";
const wrapper = mount(PlatformsIndex);
expect(wrapper.text()).toContain("Nintendo 64 12");
expect(wrapper.text()).not.toContain("PlayStation 30");
expect(wrapper.text()).not.toContain("Game Boy Advance 5");
});
it("matches on the folder name", () => {
seed();
searchState.term = "psx";
const wrapper = mount(PlatformsIndex);
expect(wrapper.text()).toContain("PlayStation 30");
expect(wrapper.text()).not.toContain("Nintendo 64 12");
expect(wrapper.text()).not.toContain("Game Boy Advance 5");
});
it("matches on the raw category", () => {
seed();
searchState.term = "portable_console";
const wrapper = mount(PlatformsIndex);
expect(wrapper.text()).toContain("Game Boy Advance 5");
expect(wrapper.text()).not.toContain("PlayStation 30");
expect(wrapper.text()).not.toContain("Nintendo 64 12");
});
// The category the user reads is the prettified label, so typing what
// the list column and the group heading show has to match too.
it("matches on the prettified category label", () => {
seed();
searchState.term = "portable console";
const wrapper = mount(PlatformsIndex);
expect(wrapper.text()).toContain("Game Boy Advance 5");
expect(wrapper.text()).not.toContain("PlayStation 30");
expect(wrapper.text()).not.toContain("Nintendo 64 12");
});
it("matches on the family name", () => {
seed();
searchState.term = "nintendo";
const wrapper = mount(PlatformsIndex);
expect(wrapper.text()).toContain("Game Boy Advance 5");
expect(wrapper.text()).toContain("Nintendo 64 12");
expect(wrapper.text()).not.toContain("PlayStation 30");
});
it("ignores case and surrounding whitespace", () => {
seed();
searchState.term = " PSX ";
const wrapper = mount(PlatformsIndex);
expect(wrapper.text()).toContain("PlayStation 30");
expect(wrapper.text()).not.toContain("Nintendo 64 12");
});
it("reports no results when nothing matches any field", () => {
seed();
searchState.term = "sega";
const wrapper = mount(PlatformsIndex);
expect(wrapper.text()).toContain("platform.no-platforms-search");
expect(wrapper.text()).not.toContain("PlayStation 30");
});
it("tolerates platforms with no category or family", () => {
storePlatforms().set([
platform(1, "Arcade", 7, {
slug: "arcade",
fs_slug: "arcade",
category: null,
family_name: null,
}),
]);
searchState.term = "arcade";
const wrapper = mount(PlatformsIndex);
expect(wrapper.text()).toContain("Arcade 7");
});
});
});

View File

@@ -277,11 +277,21 @@ onMounted(() => {
}
});
// Category contributes both the raw IGDB value and the prettified label, since
// the label is what the UI shows ("Portable console") while the raw
// value is what the rest of the app stores ("portable_console").
function searchFields(p: Platform): string[] {
const fields = [p.display_name, p.slug, p.fs_slug];
if (p.category) fields.push(p.category, prettifyPlatformCategory(p.category));
if (p.family_name) fields.push(p.family_name);
return fields;
}
const filtered = computed<Platform[]>(() => {
const term = searchTerm.value.trim().toLowerCase();
if (!term) return visiblePlatforms.value;
return visiblePlatforms.value.filter((p) =>
p.display_name.toLowerCase().includes(term),
searchFields(p).some((field) => field.toLowerCase().includes(term)),
);
});
@@ -479,7 +489,7 @@ const groupedBuckets = computed<Bucket[] | null>(() => {
:group-by-items="platformGroupByItems"
:segment-filters="segmentFilters"
show-search
:search-placeholder="t('platform.search-platform')"
:search-placeholder="t('platform.search-placeholder')"
@update:group-by="groupBy = $event"
@update:layout="layout = $event"
@update:sort-dir="gridSortDir = $event"