From 52135e34d0d99326a661b902923175e16b35278b Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Tue, 3 Nov 2026 17:47:52 +0100 Subject: [PATCH] Emphasize pending column mappings --- crates/rundown-converter/src/gui/review.rs | 74 +++++++++++++++++++++- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/crates/rundown-converter/src/gui/review.rs b/crates/rundown-converter/src/gui/review.rs index b263f4c..a5a1a89 100644 --- a/crates/rundown-converter/src/gui/review.rs +++ b/crates/rundown-converter/src/gui/review.rs @@ -84,6 +84,7 @@ fn timing_hint(value: &str, example: &str) -> String { const PREVIEW_SUCCESS: Color32 = Color32::from_rgb(115, 205, 150); const PREVIEW_AMBER: Color32 = Color32::from_rgb(235, 190, 95); const PREVIEW_GAP: Color32 = Color32::from_rgb(110, 200, 215); +const PREVIEW_PENDING: Color32 = Color32::from_rgb(176, 155, 245); const PREVIEW_RED: Color32 = Color32::from_rgb(245, 125, 120); const PREVIEW_INFERRED: Color32 = Color32::from_rgb(165, 172, 184); const COLUMN_FOCUS_PULSE_SECONDS: f64 = 1.8; @@ -508,6 +509,23 @@ fn modified_row(row: &PreviewRow, profile: &Profile) -> bool { .is_some_and(|key| profile.gap_resolutions.contains_key(key)) } +fn column_choice(profile: &Profile, column: usize) -> Option<&str> { + profile + .columns + .iter() + .find(|(_, letter)| crate::model::column_index(letter) == Some(column)) + .map(|(role, _)| role.as_str()) + .or_else(|| profile.usage(column)) +} + +fn column_settings_changed(current: &Profile, analyzed: &Profile) -> bool { + current.header_row != analyzed.header_row + || current.columns != analyzed.columns + || current.column_usage != analyzed.column_usage + || current.expected_headers != analyzed.expected_headers + || current.duration_unit != analyzed.duration_unit +} + fn show_row( row: &PreviewRow, filter: RowFilter, @@ -1199,10 +1217,22 @@ impl App { serde_json::from_str::(&self.profile), ) { let before = serde_json::to_string(&profile).unwrap(); + let analyzed_profile = self + .analyzed_profile + .clone() + .unwrap_or_else(|| profile.clone()); + let mapping_pending = column_settings_changed(&profile, &analyzed_profile); let (mapping, evidence) = detect::inspect(table, &profile); match &mapping { Ok(m) => { - ui.colored_label(PREVIEW_SUCCESS, "OK Column mapping verified"); + if mapping_pending { + ui.colored_label( + PREVIEW_PENDING, + "Column mapping changed · Apply & recheck", + ); + } else { + ui.colored_label(PREVIEW_SUCCESS, "OK Column mapping verified"); + } ui.horizontal_wrapped(|ui| { for (role, column) in [ ("Start", Some(m.start)), @@ -1327,6 +1357,7 @@ impl App { let width = table.rows.iter().map(Vec::len).max().unwrap_or(0); for c in 0..width { ui.separator(); + let pending = column_choice(&profile, c) != column_choice(&analyzed_profile, c); let highlighted_role = ambiguities .iter() .filter(|(_, candidates)| candidates.contains(&c)) @@ -1338,7 +1369,27 @@ impl App { .as_ref() .is_some_and(|(_, candidates)| candidates.contains(&c)); let mut frame = egui::Frame::new().inner_margin(6.0); - if !highlighted_role.is_empty() { + if pending { + let pulse = if focused { + let until = mapping_focus_until.unwrap_or(now); + let progress = ((now - (until - COLUMN_FOCUS_PULSE_SECONDS)) + / COLUMN_FOCUS_PULSE_SECONDS) + .clamp(0.0, 1.0); + (std::f64::consts::PI * progress).sin() as f32 + } else { + 0.0 + }; + let fill = Color32::from_rgb(43, 36, 70) + .lerp_to_gamma(Color32::from_rgb(72, 58, 116), pulse * 0.7); + frame = frame + .fill(fill) + .stroke(egui::Stroke::new(1.0_f32, PREVIEW_PENDING)) + .corner_radius(4.0); + if focused { + ui.ctx() + .request_repaint_after(std::time::Duration::from_millis(40)); + } + } else if !highlighted_role.is_empty() { let pulse = if focused { let until = mapping_focus_until.unwrap_or(now); let progress = ((now - (until - COLUMN_FOCUS_PULSE_SECONDS)) @@ -1372,6 +1423,9 @@ impl App { format!("{highlighted_role} candidate"), ); } + if pending { + ui.colored_label(PREVIEW_PENDING, "Pending apply"); + } let col = column_name(c); let mut chosen = profile .columns @@ -1445,7 +1499,7 @@ impl App { profile.columns.insert(chosen, col); } } - if mapping.is_ok() { + if mapping.is_ok() && !pending { let role = detected_role.unwrap_or("Ignore"); ui.colored_label(PREVIEW_SUCCESS, format!("OK: {role}")); } @@ -2969,6 +3023,14 @@ mod tests { let ctx = egui::Context::default(); configure_style(&ctx); let size = [860.0, 900.0]; + render(&mut app, &ctx, size, vec![]); + let labels = render(&mut app, &ctx, size, vec![]); + assert!( + labels + .iter() + .any(|(text, _)| text == "Column mapping changed · Apply & recheck") + ); + assert!(labels.iter().any(|(text, _)| text == "Pending apply")); for (current, choice, expected) in [ ("Start", "Notes", Some("notes")), ("Notes", "Metadata", Some("metadata")), @@ -3001,6 +3063,12 @@ mod tests { ); assert_eq!(profile.usage(0), expected); assert!(app.dirty); + let labels = render(&mut app, &ctx, size, vec![]); + assert_eq!( + labels.iter().any(|(text, _)| text == "Pending apply"), + expected.is_some(), + "{current} -> {choice} should show pending state only when it differs from the analyzed mapping" + ); } } #[test]