GUI round 3: Excel-style filters, status row colours, icon controls, context menu, live theme
build-test-release / release (push) Successful in 7m10s
build-test-release / release (push) Successful in 7m10s
Addresses the round-3 feedback batch:
- Right-click now works: a context menu (open selected in browser, select all,
clear) pops up from the table. It was never wired before. (The live-config
intersection over the selection remains a follow-up; no dead menu items.)
- Selection is readable again in both themes: the alt-row/zebra CSS hack (which
painted row backgrounds over the native highlight, leaving white-on-white) is
gone; the native selection highlight shows through.
- Row text is coloured by status (green = hashing, amber = slow, grey = not
hashing), which also separates rows without fragile GTK zebra striping.
- Dark mode: KPI cards and rows follow the system theme (no more white boxes in
dark mode); a system-colour-changed event repaints them live if the OS toggles
light/dark while the app is open.
- Play / Pause / Stop are coloured media icons (green triangle / amber bars /
red square) instead of text buttons.
- Filter panel redesigned Excel-style: a column dropdown at the top selects the
column; controls adapt to its type. Text columns: a value checklist ("is any
of") or a predicate (contains / does not contain / begins with / ends with /
equals). Numeric columns: between / = / != / > / >= / < / <=. Filters AND
across columns; edits held in a working copy, committed on Apply.
- Auto-rescan label shortened to "Rescan (s):" so the value field has room.
Table: replaced wxDataViewListCtrl with a raw wxDataViewCtrl + a custom
AttrListStore (per-row foreground via GetAttrByRow), which keeps in-table column
drag while enabling status row colours. New wx-rs bridge primitives: wxChoice
dropdown, coloured media buttons (drawn on a transparent bitmap via
wxGraphicsContext), a wxEVT_SYS_COLOUR_CHANGED event, destroy_children, and
call_after (deferred rebuilds). Patches 0002/0003 regenerated + round-trip
validated.
Model: ColFilter { Values, Text{op}, Num{op} } with TextOp/NumOp and
passes_filters -> ColFilter::matches; Column::num_value for numeric filtering.
Review fixes (one review pass):
- Deferred the two rebuilds that destroyed a control from inside its own event
(filter op-dropdown change; column drag-reorder) via call_after, avoiding a
use-after-free.
- num_value returns None for a blank-displaying value-type cell (Hashrate,
Power, ChipTemp, ...), so "ChipTemp <= 50" no longer matches a miner with no
temperature reading.
- Value checklist maps a checked entry back to its real value by index, so a
literal "(blank)" value is not confused with an empty cell.
Verified off-screen: 45 unit tests, headless self-test (14 checks), and
interaction screenshots of selection, right-click, the text/numeric filter, the
comparator swap, and dark mode.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Y8h447BPyJR4fioYZvQ9bh
This commit is contained in:
+150
-11
@@ -353,6 +353,22 @@ impl Column {
|
||||
)
|
||||
}
|
||||
|
||||
/// The numeric value used for numeric filtering, or `None` for a text column
|
||||
/// or a blank/missing cell (so `> 0` never matches an absent metric). A
|
||||
/// "blank" cell is exactly one the table renders empty -- several value-type
|
||||
/// columns store an absent reading as 0.0, which `cell()` blanks; mirror that
|
||||
/// here so a filter like "ChipTemp <= 50" cannot match a miner with no
|
||||
/// temperature reading.
|
||||
pub fn num_value(&self, r: &MinerRow) -> Option<f64> {
|
||||
if !self.is_numeric() || self.cell(r).is_empty() {
|
||||
return None;
|
||||
}
|
||||
match self.sort_key(r) {
|
||||
SortKey::Num(v) if v.is_finite() => Some(v),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sort key. Numeric columns compare by their underlying number (absent =
|
||||
/// -inf so blanks sort to the bottom of a descending sort); others compare
|
||||
/// as lowercase strings.
|
||||
@@ -474,14 +490,78 @@ pub enum SortKey {
|
||||
Str(String),
|
||||
}
|
||||
|
||||
/// Text-column filter operators (Excel-style text filters).
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum TextOp {
|
||||
Contains,
|
||||
NotContains,
|
||||
BeginsWith,
|
||||
EndsWith,
|
||||
Equals,
|
||||
}
|
||||
|
||||
/// Numeric-column filter operators (Excel-style number filters).
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum NumOp {
|
||||
Between,
|
||||
Eq,
|
||||
Ne,
|
||||
Gt,
|
||||
Ge,
|
||||
Lt,
|
||||
Le,
|
||||
}
|
||||
|
||||
/// One column's active filter. Text columns can filter by a value checklist
|
||||
/// ("is any of") or a text predicate; numeric columns by a numeric predicate.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ColFilter {
|
||||
Values(HashSet<String>),
|
||||
Text { op: TextOp, needle: String },
|
||||
Num { op: NumOp, a: f64, b: f64 },
|
||||
}
|
||||
|
||||
impl ColFilter {
|
||||
/// Does `r`'s value in `col` satisfy this filter?
|
||||
pub fn matches(&self, col: Column, r: &MinerRow) -> bool {
|
||||
match self {
|
||||
ColFilter::Values(set) => set.contains(&col.cell(r)),
|
||||
ColFilter::Text { op, needle } => {
|
||||
let hay = col.cell(r).to_lowercase();
|
||||
let n = needle.to_lowercase();
|
||||
match op {
|
||||
TextOp::Contains => hay.contains(&n),
|
||||
TextOp::NotContains => !hay.contains(&n),
|
||||
TextOp::BeginsWith => hay.starts_with(&n),
|
||||
TextOp::EndsWith => hay.ends_with(&n),
|
||||
TextOp::Equals => hay == n,
|
||||
}
|
||||
}
|
||||
ColFilter::Num { op, a, b } => {
|
||||
let Some(v) = col.num_value(r) else { return false };
|
||||
let (a, b) = (*a, *b);
|
||||
match op {
|
||||
NumOp::Between => v >= a.min(b) && v <= a.max(b),
|
||||
NumOp::Eq => v == a,
|
||||
NumOp::Ne => v != a,
|
||||
NumOp::Gt => v > a,
|
||||
NumOp::Ge => v >= a,
|
||||
NumOp::Lt => v < a,
|
||||
NumOp::Le => v <= a,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Display state: order, visibility, sort, filter.
|
||||
pub struct ViewState {
|
||||
/// Model column order as displayed (Ip is always the first visible column).
|
||||
pub order: Vec<Column>,
|
||||
pub visible: HashSet<Column>,
|
||||
pub sort: Option<(Column, bool)>, // (column, ascending)
|
||||
/// Per-column allowed values; None = unfiltered.
|
||||
pub filters: HashMap<Column, HashSet<String>>,
|
||||
/// Active per-column filters (AND across columns); empty = unfiltered.
|
||||
pub filters: HashMap<Column, ColFilter>,
|
||||
}
|
||||
|
||||
impl Default for ViewState {
|
||||
@@ -532,11 +612,9 @@ impl ViewState {
|
||||
.collect();
|
||||
}
|
||||
|
||||
/// Rows that pass every active filter (AND across columns, OR within one).
|
||||
/// Rows that pass every active filter (AND across columns).
|
||||
pub fn passes_filters(&self, r: &MinerRow) -> bool {
|
||||
self.filters
|
||||
.iter()
|
||||
.all(|(col, allowed)| allowed.contains(&col.cell(r)))
|
||||
self.filters.iter().all(|(col, f)| f.matches(*col, r))
|
||||
}
|
||||
|
||||
/// Filtered + sorted rows in display order.
|
||||
@@ -684,7 +762,7 @@ mod tests {
|
||||
let mut view = ViewState::default();
|
||||
let mut allowed = HashSet::new();
|
||||
allowed.insert("slow".to_string());
|
||||
view.filters.insert(Column::Status, allowed);
|
||||
view.filters.insert(Column::Status, ColFilter::Values(allowed));
|
||||
let idx = view.view(&rows);
|
||||
assert_eq!(idx.len(), 1);
|
||||
assert_eq!(rows[idx[0]].ip, "10.255.1.149");
|
||||
@@ -938,8 +1016,8 @@ mod tests {
|
||||
MinerRow { ip: "10.0.0.3".into(), is_mining: false, model: "A".into(), ..Default::default() },
|
||||
];
|
||||
let mut view = ViewState::default();
|
||||
view.filters.insert(Column::Status, HashSet::from(["hashing".to_string()]));
|
||||
view.filters.insert(Column::Model, HashSet::from(["A".to_string()]));
|
||||
view.filters.insert(Column::Status, ColFilter::Values(HashSet::from(["hashing".to_string()])));
|
||||
view.filters.insert(Column::Model, ColFilter::Values(HashSet::from(["A".to_string()])));
|
||||
let idx = view.view(&rows);
|
||||
assert_eq!(idx.len(), 1, "only the hashing AND model-A row passes");
|
||||
assert_eq!(rows[idx[0]].ip, "10.0.0.1");
|
||||
@@ -951,7 +1029,7 @@ mod tests {
|
||||
let mut view = ViewState::default();
|
||||
view.filters.insert(
|
||||
Column::Status,
|
||||
HashSet::from(["slow".to_string(), "not hashing".to_string()]),
|
||||
ColFilter::Values(HashSet::from(["slow".to_string(), "not hashing".to_string()])),
|
||||
);
|
||||
let idx = view.view(&rows);
|
||||
// fixtures: 1 slow + 2 not-hashing.
|
||||
@@ -1027,7 +1105,7 @@ mod tests {
|
||||
use std::time::Instant;
|
||||
let rows = synthetic_fleet(5000);
|
||||
let mut view = ViewState::default();
|
||||
view.filters.insert(Column::Model, HashSet::from(["Model-3".to_string()]));
|
||||
view.filters.insert(Column::Model, ColFilter::Values(HashSet::from(["Model-3".to_string()])));
|
||||
view.sort = Some((Column::Hashrate, false));
|
||||
let iters = 200u32;
|
||||
let t = Instant::now();
|
||||
@@ -1057,4 +1135,65 @@ mod tests {
|
||||
println!("bench_upsert_cold_start_population: {n} rows cold-start = {:?}", elapsed);
|
||||
assert!(elapsed.as_millis() < 2000, "cold-start upsert regressed: {elapsed:?} for {n} rows");
|
||||
}
|
||||
|
||||
// ---- Excel-style column filters (round 3) ----
|
||||
|
||||
#[test]
|
||||
fn text_filter_operators_are_case_insensitive() {
|
||||
let r = MinerRow { firmware: "WMOS H616".into(), ..Default::default() };
|
||||
let c = Column::Firmware;
|
||||
let t = |op, needle: &str| ColFilter::Text { op, needle: needle.into() }.matches(c, &r);
|
||||
assert!(t(TextOp::Contains, "wmos"));
|
||||
assert!(!t(TextOp::Contains, "vnish"));
|
||||
assert!(!t(TextOp::NotContains, "wmos"));
|
||||
assert!(t(TextOp::NotContains, "vnish"));
|
||||
assert!(t(TextOp::BeginsWith, "WMOS"));
|
||||
assert!(!t(TextOp::BeginsWith, "616"));
|
||||
assert!(t(TextOp::EndsWith, "h616"));
|
||||
assert!(t(TextOp::Equals, "wmos h616"));
|
||||
assert!(!t(TextOp::Equals, "wmos"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numeric_filter_operators() {
|
||||
let r = MinerRow { hashrate_ths: 100.0, is_mining: true, ..Default::default() };
|
||||
let c = Column::Hashrate;
|
||||
let n = |op, a: f64, b: f64| ColFilter::Num { op, a, b }.matches(c, &r);
|
||||
assert!(n(NumOp::Gt, 50.0, 0.0));
|
||||
assert!(!n(NumOp::Gt, 150.0, 0.0));
|
||||
assert!(n(NumOp::Ge, 100.0, 0.0));
|
||||
assert!(n(NumOp::Lt, 150.0, 0.0));
|
||||
assert!(n(NumOp::Le, 100.0, 0.0));
|
||||
assert!(n(NumOp::Eq, 100.0, 0.0));
|
||||
assert!(n(NumOp::Ne, 99.0, 0.0));
|
||||
assert!(n(NumOp::Between, 90.0, 110.0));
|
||||
assert!(n(NumOp::Between, 110.0, 90.0), "bounds are order-agnostic");
|
||||
assert!(!n(NumOp::Between, 0.0, 50.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn num_value_none_for_text_and_blank() {
|
||||
let r = MinerRow { firmware: "x".into(), efficiency: 0.0, ..Default::default() };
|
||||
assert_eq!(Column::Firmware.num_value(&r), None, "text column");
|
||||
assert_eq!(Column::Ip.num_value(&r), None, "IP is text, not numeric");
|
||||
assert_eq!(Column::Efficiency.num_value(&r), None, "blank numeric -> None");
|
||||
let r2 = MinerRow { hashrate_ths: 42.0, ..Default::default() };
|
||||
assert_eq!(Column::Hashrate.num_value(&r2), Some(42.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numeric_filter_excludes_blank_cells() {
|
||||
// A blank-displaying value-type cell (absent reading stored as 0.0) must
|
||||
// not match a numeric predicate -- it has no value to compare.
|
||||
let blank = MinerRow { hashrate_ths: 0.0, chip_temp_c: 0.0, power_w: 0.0, is_mining: false, ..Default::default() };
|
||||
assert_eq!(Column::Hashrate.num_value(&blank), None);
|
||||
assert_eq!(Column::ChipTemp.num_value(&blank), None);
|
||||
assert_eq!(Column::Power.num_value(&blank), None);
|
||||
// "<= 50" and "<= 1000" must NOT match a miner with no temp / power.
|
||||
assert!(!ColFilter::Num { op: NumOp::Le, a: 50.0, b: 0.0 }.matches(Column::ChipTemp, &blank));
|
||||
assert!(!ColFilter::Num { op: NumOp::Lt, a: 1000.0, b: 0.0 }.matches(Column::Power, &blank));
|
||||
// A real reading still matches.
|
||||
let live = MinerRow { chip_temp_c: 45.0, is_mining: true, ..Default::default() };
|
||||
assert!(ColFilter::Num { op: NumOp::Le, a: 50.0, b: 0.0 }.matches(Column::ChipTemp, &live));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user