Search the champion table by name and known aliases (#18)
CI / core (pull_request) Successful in 1m9s
CI / core (push) Successful in 36s

A search field above the table filters the rows as the user types, with the
state filter and the sort kept. A row matches when the normalized query (case,
accents, spaces and punctuation ignored) is part of its name or Data Dragon id,
or equals one of its aliases exactly. The aliases come from the U.GG and
Liquipedia inventory researched for the ticket and are stored locally by
Data Dragon id.

Not measured yet against the rule #1 budgets (release build, reference machine).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit was merged in pull request #42.
This commit is contained in:
nessarandClaude Sonnet 5.5 committed 2026-11-17 23:34:11 +01:00
1 parent 0fbbc81b71
commit 3edfa629d4
7 files changed
+467 -28

No files matched your search

+5
View File
@@ -69,6 +69,11 @@ impl ChampionTable {
self.resort();
}
#[cfg(test)]
pub(crate) fn names(&self) -> Vec<String> {
self.rows.iter().map(|r| r.champion.name.clone()).collect()
}
/// Column and `descending`.
fn sorted_by(&self) -> (SortKey, bool) {
self.sort
+129 -22
View File
@@ -4,14 +4,15 @@ use std::sync::Arc;
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
use arena_tracker_core::{
Account, ChallengeSummary, Charts, Format, ProgressCheck, Scope, SeasonScope, StateFilter,
Statistics, Status, SyncProgress, Tracker, UpdateProblem,
Account, ChallengeSummary, ChampionSearch, Charts, Format, ProgressCheck, Scope, SeasonScope,
StateFilter, Statistics, Status, SyncProgress, Tracker, UpdateProblem,
};
use gpui_kit::base::async_util::{Receiver, Sender};
use gpui_kit::component::StyledExt as _;
use gpui_kit::component::alert::Alert;
use gpui_kit::component::button::Button;
use gpui_kit::component::chart::{AreaChart, BarChart};
use gpui_kit::component::input::{Input, InputEvent, InputState};
use gpui_kit::component::select::{Select, SelectEvent, SelectItem, SelectState};
use gpui_kit::component::tab::{Tab, TabBar};
use gpui_kit::component::{ActiveTheme as _, Disableable as _, IndexPath, Sizable as _};
@@ -104,6 +105,9 @@ pub struct StatsPage {
season: SeasonScope,
format: Option<Format>,
filter: StateFilter,
/// Kept and reapplied whenever the table's rows are rebuilt.
search: ChampionSearch,
search_input: Entity<InputState>,
stats: Option<Statistics>,
stats_error: Option<String>,
stored: Option<usize>,
@@ -171,10 +175,18 @@ impl StatsPage {
let format_names = vec![SharedString::from(ALL_FORMATS)];
let format_select = cx
.new(|cx| SelectState::new(format_names.clone(), Some(IndexPath::new(0)), window, cx));
let search_input =
cx.new(|cx| InputState::new(window, cx).placeholder("Rechercher un champion"));
let charts = cx.new(|_| ChartsRow::new());
let table = cx.new(|_| ChampionTable::new());
let subscriptions = vec![
cx.subscribe(&search_input, |this, input, event: &InputEvent, cx| {
if matches!(event, InputEvent::Change) {
this.search = ChampionSearch::new(&input.read(cx).value());
this.refresh_table(cx);
}
}),
cx.subscribe_in(
&account_select,
window,
@@ -253,6 +265,8 @@ impl StatsPage {
season,
format: None,
filter: StateFilter::All,
search: ChampionSearch::new(""),
search_input,
stats: None,
stats_error: None,
stored: None,
@@ -537,7 +551,10 @@ impl StatsPage {
fn refresh_table(&mut self, cx: &mut Context<Self>) {
let rows = self.stats.iter().flat_map(|s| &s.rows);
let rows = rows.filter(|row| self.filter.keeps(row)).cloned().collect();
let rows = rows
.filter(|row| self.filter.keeps(row) && self.search.matches(&row.champion))
.cloned()
.collect();
let in_season = self.in_season();
self.table.update(cx, |table, cx| {
table.set_rows(rows, in_season);
@@ -940,17 +957,30 @@ impl Render for StatsPage {
)
.when(shown("tabs"), |page| {
page.child(
TabBar::new("state-filter")
.segmented()
.selected_index(selected.unwrap_or(0))
.children(options.iter().map(|(label, _)| Tab::new().label(*label)))
.on_click(cx.listener(|this, ix: &usize, _, cx| {
if let Some((_, filter)) = filters(this.in_season()).get(*ix) {
this.filter = *filter;
this.refresh_table(cx);
cx.notify();
}
})),
div()
.h_flex()
.items_center()
.justify_between()
.gap_3()
.child(
TabBar::new("state-filter")
.segmented()
.selected_index(selected.unwrap_or(0))
.children(options.iter().map(|(label, _)| Tab::new().label(*label)))
.on_click(cx.listener(|this, ix: &usize, _, cx| {
if let Some((_, filter)) = filters(this.in_season()).get(*ix) {
this.filter = *filter;
this.refresh_table(cx);
cx.notify();
}
})),
)
.child(
Input::new(&self.search_input)
.cleanable(true)
.w(px(260.))
.min_w(px(150.)),
),
)
})
.when(shown("table"), |page| {
@@ -966,20 +996,19 @@ mod tests {
use std::rc::Rc;
use std::sync::Arc;
use arena_tracker_core::{RiotApi, Tracker};
use arena_tracker_core::{
Champion, ChampionRow, ChampionState, Charts, RiotApi, StateFilter, Statistics, Tracker,
};
use gpui_kit::base::async_util::unbounded;
use gpui_kit::{
AppContext as _, Bounds, Modifiers, TestAppContext, VisualTestContext, WindowBounds,
WindowOptions, point, px, size,
AppContext as _, Bounds, Entity, Modifiers, TestAppContext, VisualTestContext,
WindowBounds, WindowOptions, point, px, size,
};
use super::StatsPage;
use crate::champion_table::tests::row;
// No test can time a frame: this guards the cache that keeps hovering cheap instead (rule #1,
// #31). It runs with the app's tests on Windows; CI only builds the core.
#[gpui::test]
fn hovering_the_table_does_not_render_the_charts(cx: &mut TestAppContext) {
fn open_page(cx: &mut TestAppContext) -> (Entity<StatsPage>, VisualTestContext) {
cx.update(gpui_kit::init);
let tracker = Arc::new(
Tracker::open(
@@ -1004,7 +1033,85 @@ mod tests {
})
.unwrap()
});
let cx = &mut VisualTestContext::from_window(window, cx);
(page, VisualTestContext::from_window(window, cx))
}
#[gpui::test]
fn typing_in_the_search_field_filters_the_table(cx: &mut TestAppContext) {
let (page, cx) = open_page(cx);
let cx = &mut { cx };
let champion = |id, key: &str, name: &str| ChampionRow {
champion: Champion {
id,
key: key.into(),
name: name.into(),
},
..row(name)
};
page.update(cx, |page, _| {
page.stats = Some(Statistics {
challenge: None,
rows: vec![
ChampionRow {
state: Some(ChampionState::Completed),
..champion(4, "TwistedFate", "Twisted Fate")
},
ChampionRow {
state: Some(ChampionState::NeverPlayed),
..champion(86, "Garen", "Garen")
},
ChampionRow {
state: Some(ChampionState::NeverPlayed),
matches: 5,
..champion(107, "Rengar", "Rengar")
},
],
charts: Charts {
placements: Vec::new(),
completed_over_time: Vec::new(),
attempts_to_complete: [0; 5],
},
formats: Vec::new(),
});
});
let (input, table) = page.read_with(cx, |p, _| (p.search_input.clone(), p.table.clone()));
let names = |cx: &mut VisualTestContext| table.read_with(cx, |table, _| table.names());
cx.update(|window, cx| input.update(cx, |input, cx| input.focus(window, cx)));
cx.simulate_input("ren");
assert_eq!(names(cx), ["Rengar", "Garen"]);
// The clear button's own path: it empties the field and the table follows.
cx.update(|window, cx| input.update(cx, |input, cx| input.clean(window, cx)));
assert_eq!(names(cx).len(), 3);
cx.simulate_input("TF");
assert_eq!(names(cx), ["Twisted Fate"]);
cx.simulate_input("z");
assert!(names(cx).is_empty());
cx.update(|window, cx| input.update(cx, |input, cx| input.clean(window, cx)));
cx.simulate_input(" ");
assert_eq!(names(cx).len(), 3);
// Combined with a state filter, the table keeps its sort (most Matches first).
cx.update(|window, cx| input.update(cx, |input, cx| input.clean(window, cx)));
cx.simulate_input("ren");
page.update(cx, |page, cx| {
page.filter = StateFilter::Completed;
page.refresh_table(cx);
});
assert!(names(cx).is_empty());
page.update(cx, |page, cx| {
page.filter = StateFilter::NeverPlayed;
page.refresh_table(cx);
});
assert_eq!(names(cx), ["Rengar", "Garen"]);
}
// No test can time a frame: this guards the cache that keeps hovering cheap instead (rule #1,
// #31). It runs with the app's tests on Windows; CI only builds the core.
#[gpui::test]
fn hovering_the_table_does_not_render_the_charts(cx: &mut TestAppContext) {
let (page, cx) = open_page(cx);
let cx = &mut { cx };
let (table, charts) =
page.read_with(cx, |page, _| (page.table.clone(), page.charts.clone()));
// Enough rows to fill the table, under the points hovered below.