Show automatic role suggestions beside column choices
This commit is contained in:
parent
a4c4c7dc73
commit
23d805dedc
|
|
@ -187,6 +187,74 @@ pub fn infer(table: &Table, profile: &Profile) -> Result<Mapping, Vec<Diagnostic
|
|||
inspect(table, profile).0
|
||||
}
|
||||
|
||||
/// Automatic recommendations independent of manual column choices. When the
|
||||
/// whole mapping is blocked, header hints remain suggestions, not validation.
|
||||
#[cfg(feature = "desktop")]
|
||||
pub(crate) fn suggested_roles(
|
||||
table: &Table,
|
||||
profile: &Profile,
|
||||
) -> std::collections::BTreeMap<usize, &'static str> {
|
||||
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::<usize>().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,
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue