From 23d805dedc1d47d6dce2a853437d0e26cadcf3f6 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Wed, 4 Nov 2026 16:42:38 +0100 Subject: [PATCH] Show automatic role suggestions beside column choices --- crates/rundown-converter/src/detect.rs | 68 ++++++++++++++++++++++ crates/rundown-converter/src/gui/review.rs | 29 +++++++++ docs/rundown-converter.md | 4 +- 3 files changed, 100 insertions(+), 1 deletion(-) diff --git a/crates/rundown-converter/src/detect.rs b/crates/rundown-converter/src/detect.rs index 4dd9dbf..f8f239c 100644 --- a/crates/rundown-converter/src/detect.rs +++ b/crates/rundown-converter/src/detect.rs @@ -187,6 +187,74 @@ pub fn infer(table: &Table, profile: &Profile) -> Result std::collections::BTreeMap { + let mut automatic = profile.clone(); + automatic.columns.clear(); + automatic.column_usage.clear(); + automatic.expected_headers.clear(); + let (mapping, evidence) = inspect(table, &automatic); + let mut suggestions = std::collections::BTreeMap::new(); + if let Ok(mapping) = mapping { + suggestions.insert( + mapping.start, + if mapping.start_end { + "Start–end" + } else { + "Start" + }, + ); + suggestions.insert(mapping.title, "Title"); + if let Some(column) = mapping.end { + suggestions.insert(column, "End"); + } + if let Some(column) = mapping.duration { + suggestions.insert(column, "Duration"); + } + for (column, usage) in mapping.column_usage { + if let Some(column) = column_index(&column) { + match usage.as_str() { + "notes" => { + suggestions.insert(column, "Notes"); + } + "metadata" => { + suggestions.insert(column, "Metadata"); + } + _ => {} + } + } + } + } else if let Some(header) = evidence + .first() + .and_then(|text| text.strip_prefix("Header row ")) + .and_then(|text| text.parse::().ok()) + { + for (column, cell) in table.rows[header - 1].iter().enumerate() { + let suggested = match role(&cell.text) { + Some("start") => Some("Start"), + Some("start_end") => Some("Start–end"), + Some("end") => Some("End"), + Some("duration") => Some("Duration"), + Some("title") => Some("Title"), + _ => match automatic_usage(&cell.text) { + "notes" => Some("Notes"), + "metadata" => Some("Metadata"), + _ => None, + }, + }; + if let Some(suggested) = suggested { + suggestions.insert(column, suggested); + } + } + } + suggestions +} + /// Retain inference evidence even when a later ambiguity blocks the mapping. pub fn inspect( table: &Table, diff --git a/crates/rundown-converter/src/gui/review.rs b/crates/rundown-converter/src/gui/review.rs index bbe1696..fde0883 100644 --- a/crates/rundown-converter/src/gui/review.rs +++ b/crates/rundown-converter/src/gui/review.rs @@ -1355,6 +1355,7 @@ impl App { .unwrap_or_else(|| profile.clone()); let mapping_pending = column_settings_changed(&profile, &analyzed_profile); let (mapping, evidence) = detect::inspect(table, &profile); + let suggestions = detect::suggested_roles(table, &profile); if mapping_pending { egui::Frame::new() .fill(Color32::from_rgb(53, 43, 88)) @@ -1567,6 +1568,10 @@ impl App { if pending { ui.colored_label(PREVIEW_PENDING, "Pending apply"); } + if let Some(role) = suggestions.get(&c) { + ui.colored_label(PREVIEW_SUCCESS, format!("Suggested: {role}")) + .on_hover_text("Automatic recommendation without manual column choices. If detection is blocked, this is a header hint; Apply & recheck still validates the mapping."); + } let col = column_name(c); let mut chosen = profile .columns @@ -3412,6 +3417,30 @@ mod tests { assert!(app.dirty); } + #[test] + fn column_suggestions_survive_manual_choices_and_blocked_detection() { + let mut app = sample(); + app.review_view = ReviewView::Columns; + let profile = Profile { + column_usage: BTreeMap::from([("A".into(), "ignore".into())]), + ..Default::default() + }; + app.profile = serde_json::to_string(&profile).unwrap(); + let ctx = egui::Context::default(); + configure_style(&ctx); + let size = [1100.0, 1000.0]; + render(&mut app, &ctx, size, vec![]); + let labels = render(&mut app, &ctx, size, vec![]); + assert!(labels.iter().any(|(text, _)| text == "Suggested: Start")); + assert!(labels.iter().any(|(text, _)| text == "Ignore")); + assert!(labels.iter().any(|(text, _)| text == "Suggested: Duration")); + // Broken duration data must not remove useful header hints. + app.tables[0].rows[1][1].text = "unknown".into(); + let labels = render(&mut app, &ctx, size, vec![]); + assert!(labels.iter().any(|(text, _)| text == "Suggested: Duration")); + assert!(!labels.iter().any(|(text, _)| text == "Suggested: Ignore")); + } + #[test] fn duration_column_exposes_handling_without_extra_column_roles() { let mut app = sample(); diff --git a/docs/rundown-converter.md b/docs/rundown-converter.md index 7fc6679..b569fac 100644 --- a/docs/rundown-converter.md +++ b/docs/rundown-converter.md @@ -115,7 +115,9 @@ visually distinct from labels and ordinary actions; the active tab uses the stro timing values stack so corrections remain accessible. Changes require recheck; the timing preview and diagnostics continue to show the previous analysis. - **Columns** shows a concise verified mapping summary, green detected roles, - per-column role dropdowns, and sample values. Expand **Detection evidence** for + per-column role dropdowns, and sample values. **Suggested: …** shows useful + automatic recommendations even after a manual choice. When detection is blocked, + recognised headers still provide hints; these do not replace validation. Expand **Detection evidence** for full inference and validation details; hover the **Columns** tab for a compact explanation of the role choices. **Start–end** maps one column containing full ranges such as `08h00 - 08h30`; every relevant timing cell must contain both