From dba8a5269eb3cc7bbec1ce640737e9367b4224c9 Mon Sep 17 00:00:00 2001 From: Edward Langley Date: Wed, 15 Apr 2026 04:16:09 -0700 Subject: [PATCH] refactor(records): use CategoryKind for column filtering, stabilize _Measure position - Filter records-mode columns by CategoryKind instead of string names - Simplify cell fetching: matching_cells already handles empty filters - Sort _Measure to always appear right before Value column Made-with: Cursor --- src/view/layout.rs | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/view/layout.rs b/src/view/layout.rs index 69403cc..37c457b 100644 --- a/src/view/layout.rs +++ b/src/view/layout.rs @@ -1,6 +1,7 @@ use std::rc::Rc; use crate::model::Model; +use crate::model::category::CategoryKind; use crate::model::cell::{CellKey, CellValue}; use crate::view::{Axis, View}; @@ -132,22 +133,12 @@ impl GridLayout { page_coords: Vec<(String, String)>, none_cats: Vec, ) -> Self { - // Filter cells by page_coords - let partial: Vec<(String, String)> = page_coords.clone(); - let mut records: Vec<(CellKey, CellValue)> = if partial.is_empty() { - model - .data - .iter_cells() - .map(|(k, v)| (k, v.clone())) - .collect() - } else { - model - .data - .matching_cells(&partial) - .into_iter() - .map(|(k, v)| (k, v.clone())) - .collect() - }; + let mut records: Vec<(CellKey, CellValue)> = model + .data + .matching_cells(&page_coords) + .into_iter() + .map(|(k, v)| (k, v.clone())) + .collect(); // Sort for deterministic ordering records.sort_by(|a, b| a.0.0.cmp(&b.0.0)); @@ -157,12 +148,22 @@ impl GridLayout { .collect(); // Synthesize col items: one per non-virtual category + "Value" - let cat_names: Vec = model + let mut cat_names: Vec = model .category_names() .into_iter() - .filter(|c| *c != "_Index" && *c != "_Dim") + .filter(|c| { + let kind = model.category(c).map(|cat| cat.kind); + !matches!(kind, Some(CategoryKind::VirtualIndex | CategoryKind::VirtualDim)) + }) .map(String::from) .collect(); + // _Measure goes last among category columns (right before Value) + cat_names.sort_by_key(|c| { + matches!( + model.category(c).map(|cat| cat.kind), + Some(CategoryKind::VirtualMeasure) + ) + }); let mut col_items: Vec = cat_names .iter() .map(|c| AxisEntry::DataItem(vec![c.clone()]))