Guide users through ambiguous column selection
This commit is contained in:
parent
5256936bf4
commit
2b355ff755
|
|
@ -50,6 +50,8 @@ struct App {
|
|||
completed: Option<PathBuf>,
|
||||
settings: bool,
|
||||
advanced_settings: bool,
|
||||
mapping_focus: Option<(String, Vec<usize>)>,
|
||||
mapping_focus_scroll: Option<usize>,
|
||||
review_view: ReviewView,
|
||||
dirty: bool,
|
||||
issue_index: usize,
|
||||
|
|
@ -106,6 +108,8 @@ impl Default for App {
|
|||
completed: None,
|
||||
settings: false,
|
||||
advanced_settings: false,
|
||||
mapping_focus: None,
|
||||
mapping_focus_scroll: None,
|
||||
review_view: ReviewView::Rows,
|
||||
dirty: false,
|
||||
issue_index: 0,
|
||||
|
|
@ -126,6 +130,8 @@ impl Default for App {
|
|||
impl App {
|
||||
fn invalidate(&mut self) {
|
||||
self.analysis = None;
|
||||
self.mapping_focus = None;
|
||||
self.mapping_focus_scroll = None;
|
||||
self.dirty = false;
|
||||
self.issue_index = 0;
|
||||
self.selected_row = None;
|
||||
|
|
@ -255,6 +261,8 @@ impl App {
|
|||
.into();
|
||||
self.dirty = false;
|
||||
self.issue_index = 0;
|
||||
self.mapping_focus = None;
|
||||
self.mapping_focus_scroll = None;
|
||||
self.selected_row = a.diagnostics.first().and_then(review::diagnostic_row);
|
||||
self.selected_gap = None;
|
||||
self.jump_row = self.selected_row;
|
||||
|
|
|
|||
|
|
@ -69,6 +69,16 @@ fn needs_information(d: &Diagnostic) -> bool {
|
|||
)
|
||||
}
|
||||
|
||||
fn ambiguous_columns(message: &str) -> Option<(String, Vec<usize>)> {
|
||||
let (role, rest) = message.strip_prefix("Several ")?.split_once(" columns: ")?;
|
||||
let letters = rest.split_once('.').map_or(rest, |(letters, _)| letters);
|
||||
let columns: Vec<_> = letters
|
||||
.split(',')
|
||||
.filter_map(|letter| crate::model::column_index(letter.trim()))
|
||||
.collect();
|
||||
(!columns.is_empty()).then(|| (role.to_owned(), columns))
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct PreviewRow {
|
||||
row: usize,
|
||||
|
|
@ -823,6 +833,8 @@ impl App {
|
|||
self.settings = true;
|
||||
self.tab = Tab::Setup;
|
||||
}
|
||||
let mut mapping_focus = self.mapping_focus.clone();
|
||||
let mut mapping_focus_scroll = self.mapping_focus_scroll;
|
||||
if let (Some(table), Ok(mut profile)) = (
|
||||
self.tables.iter().find(|t| t.name == self.sheet),
|
||||
serde_json::from_str::<Profile>(&self.profile),
|
||||
|
|
@ -852,10 +864,37 @@ impl App {
|
|||
format!("! Column mapping needs attention · {} issues", errors.len()),
|
||||
);
|
||||
for error in errors {
|
||||
ui.add(
|
||||
egui::Label::new(RichText::new(&error.message).color(PREVIEW_AMBER))
|
||||
if let Some((role, candidates)) = ambiguous_columns(&error.message) {
|
||||
let letters = candidates
|
||||
.iter()
|
||||
.map(|column| column_name(*column))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
ui.colored_label(
|
||||
PREVIEW_AMBER,
|
||||
format!("Several {role} columns detected: {letters}."),
|
||||
);
|
||||
if ui
|
||||
.button(format!("Choose {role} column…"))
|
||||
.on_hover_text(format!(
|
||||
"Show and highlight the possible {role} columns: {letters}"
|
||||
))
|
||||
.clicked()
|
||||
{
|
||||
mapping_focus_scroll = candidates.first().copied();
|
||||
mapping_focus = Some((role, candidates));
|
||||
}
|
||||
ui.collapsing("Technical details", |ui| {
|
||||
ui.add(egui::Label::new(&error.message).wrap());
|
||||
});
|
||||
} else {
|
||||
ui.add(
|
||||
egui::Label::new(
|
||||
RichText::new(&error.message).color(PREVIEW_AMBER),
|
||||
)
|
||||
.wrap(),
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -877,77 +916,100 @@ impl App {
|
|||
let width = table.rows.iter().map(Vec::len).max().unwrap_or(0);
|
||||
for c in 0..width {
|
||||
ui.separator();
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.strong(format!(
|
||||
"{} · {}",
|
||||
column_name(c),
|
||||
table.cell(header - 1, c).text
|
||||
));
|
||||
let col = column_name(c);
|
||||
let mut chosen = profile
|
||||
.columns
|
||||
.iter()
|
||||
.find(|(_, v)| crate::model::column_index(v) == Some(c))
|
||||
.map(|(k, _)| k.clone())
|
||||
.or_else(|| profile.usage(c).map(str::to_string))
|
||||
.unwrap_or_default();
|
||||
let old = chosen.clone();
|
||||
egui::ComboBox::from_id_salt(("column", c))
|
||||
.selected_text(if chosen.is_empty() { "Auto" } else { &chosen })
|
||||
.show_ui(ui, |ui| {
|
||||
ui.selectable_value(&mut chosen, String::new(), "Auto");
|
||||
for role in ["start", "end", "duration", "title", "metadata", "ignore"]
|
||||
{
|
||||
ui.selectable_value(&mut chosen, role.into(), role);
|
||||
}
|
||||
});
|
||||
if chosen != old {
|
||||
profile
|
||||
.columns
|
||||
.retain(|_, v| crate::model::column_index(v) != Some(c));
|
||||
profile
|
||||
.column_usage
|
||||
.retain(|letter, _| crate::model::column_index(letter) != Some(c));
|
||||
if matches!(chosen.as_str(), "metadata" | "ignore") {
|
||||
profile.column_usage.insert(col, chosen);
|
||||
} else if !chosen.is_empty() {
|
||||
profile.columns.insert(chosen, col);
|
||||
let highlighted_role = mapping_focus
|
||||
.as_ref()
|
||||
.filter(|(_, candidates)| candidates.contains(&c))
|
||||
.map(|(role, _)| role.clone());
|
||||
let mut frame = egui::Frame::new().inner_margin(6.0);
|
||||
if highlighted_role.is_some() {
|
||||
frame = frame
|
||||
.fill(Color32::from_rgb(54, 44, 26))
|
||||
.stroke(egui::Stroke::new(1.0_f32, PREVIEW_AMBER))
|
||||
.corner_radius(4.0);
|
||||
}
|
||||
let response = frame.show(ui, |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.strong(format!(
|
||||
"{} · {}",
|
||||
column_name(c),
|
||||
table.cell(header - 1, c).text
|
||||
));
|
||||
if let Some(role) = &highlighted_role {
|
||||
ui.colored_label(PREVIEW_AMBER, format!("{role} candidate"));
|
||||
}
|
||||
}
|
||||
if let Ok(m) = &mapping {
|
||||
let role = if profile.usage(c) == Some("ignore") {
|
||||
"ignore"
|
||||
} else if m.start == c {
|
||||
"start"
|
||||
} else if m.title == c {
|
||||
"title"
|
||||
} else if m.end == Some(c) {
|
||||
"end"
|
||||
} else if m.duration == Some(c) {
|
||||
"duration"
|
||||
} else {
|
||||
"metadata"
|
||||
};
|
||||
ui.colored_label(PREVIEW_SUCCESS, format!("OK: {role}"));
|
||||
}
|
||||
let col = column_name(c);
|
||||
let mut chosen = profile
|
||||
.columns
|
||||
.iter()
|
||||
.find(|(_, v)| crate::model::column_index(v) == Some(c))
|
||||
.map(|(k, _)| k.clone())
|
||||
.or_else(|| profile.usage(c).map(str::to_string))
|
||||
.unwrap_or_default();
|
||||
let old = chosen.clone();
|
||||
egui::ComboBox::from_id_salt(("column", c))
|
||||
.selected_text(if chosen.is_empty() { "Auto" } else { &chosen })
|
||||
.show_ui(ui, |ui| {
|
||||
ui.selectable_value(&mut chosen, String::new(), "Auto");
|
||||
for role in
|
||||
["start", "end", "duration", "title", "metadata", "ignore"]
|
||||
{
|
||||
ui.selectable_value(&mut chosen, role.into(), role);
|
||||
}
|
||||
});
|
||||
if chosen != old {
|
||||
profile
|
||||
.columns
|
||||
.retain(|_, v| crate::model::column_index(v) != Some(c));
|
||||
profile
|
||||
.column_usage
|
||||
.retain(|letter, _| crate::model::column_index(letter) != Some(c));
|
||||
if matches!(chosen.as_str(), "metadata" | "ignore") {
|
||||
profile.column_usage.insert(col, chosen);
|
||||
} else if !chosen.is_empty() {
|
||||
profile.columns.insert(chosen, col);
|
||||
}
|
||||
}
|
||||
if let Ok(m) = &mapping {
|
||||
let role = if profile.usage(c) == Some("ignore") {
|
||||
"ignore"
|
||||
} else if m.start == c {
|
||||
"start"
|
||||
} else if m.title == c {
|
||||
"title"
|
||||
} else if m.end == Some(c) {
|
||||
"end"
|
||||
} else if m.duration == Some(c) {
|
||||
"duration"
|
||||
} else {
|
||||
"metadata"
|
||||
};
|
||||
ui.colored_label(PREVIEW_SUCCESS, format!("OK: {role}"));
|
||||
}
|
||||
});
|
||||
let samples = table
|
||||
.rows
|
||||
.iter()
|
||||
.skip(header)
|
||||
.filter_map(|r| r.get(c))
|
||||
.filter(|v| !v.text.trim().is_empty())
|
||||
.take(3)
|
||||
.map(|v| short(&cell_text(v), 65))
|
||||
.collect::<Vec<_>>()
|
||||
.join(" / ");
|
||||
ui.label(samples);
|
||||
});
|
||||
let samples = table
|
||||
.rows
|
||||
.iter()
|
||||
.skip(header)
|
||||
.filter_map(|r| r.get(c))
|
||||
.filter(|v| !v.text.trim().is_empty())
|
||||
.take(3)
|
||||
.map(|v| short(&cell_text(v), 65))
|
||||
.collect::<Vec<_>>()
|
||||
.join(" / ");
|
||||
ui.label(samples);
|
||||
if mapping_focus_scroll == Some(c) {
|
||||
ui.scroll_to_rect(response.response.rect, Some(egui::Align::Center));
|
||||
mapping_focus_scroll = None;
|
||||
}
|
||||
}
|
||||
if before != serde_json::to_string(&profile).unwrap() {
|
||||
self.profile = serde_json::to_string_pretty(&profile).unwrap();
|
||||
self.decisions_changed();
|
||||
}
|
||||
}
|
||||
self.mapping_focus = mapping_focus;
|
||||
self.mapping_focus_scroll = mapping_focus_scroll;
|
||||
}
|
||||
|
||||
fn schedule_preview(&mut self, ui: &mut egui::Ui) {
|
||||
|
|
@ -1734,11 +1796,32 @@ mod tests {
|
|||
render(&mut app, &ctx, [860.0, 900.0], vec![]);
|
||||
let labels = render(&mut app, &ctx, [860.0, 900.0], vec![]);
|
||||
assert!(labels.iter().any(|(s, _)| s.contains("00:10:00")));
|
||||
assert!(!labels.iter().any(|(s, _)| s.contains("6.944444")));
|
||||
assert!(
|
||||
labels
|
||||
.iter()
|
||||
.any(|(s, _)| s.contains("Several duration columns"))
|
||||
.any(|(s, _)| s == "Several duration columns detected: B, C.")
|
||||
);
|
||||
assert!(!labels.iter().any(|(s, _)| s.contains("6.944444")));
|
||||
assert!(
|
||||
!labels
|
||||
.iter()
|
||||
.any(|(s, _)| s.contains("parent and child timers"))
|
||||
);
|
||||
let choose = labels
|
||||
.iter()
|
||||
.find(|(s, _)| s == "Choose duration column…")
|
||||
.unwrap()
|
||||
.1
|
||||
.center();
|
||||
click_size(&mut app, &ctx, choose, [860.0, 900.0]);
|
||||
assert_eq!(app.mapping_focus, Some(("duration".into(), vec![1, 2])));
|
||||
let labels = render(&mut app, &ctx, [860.0, 900.0], vec![]);
|
||||
assert_eq!(
|
||||
labels
|
||||
.iter()
|
||||
.filter(|(s, _)| s == "duration candidate")
|
||||
.count(),
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,10 @@ Blocking column errors open **Columns** automatically. Row corrections become
|
|||
available after the timing mapping is unambiguous and rechecked. Spreadsheet
|
||||
cells marked as times display as `HH:MM:SS` in samples and the inspector; the
|
||||
original stored value remains available in the inspector.
|
||||
When several columns could have the same timing role, the error gives a short
|
||||
instruction and a **Choose … column…** button. It scrolls to the candidate
|
||||
columns and highlights them in amber; the original inference explanation remains
|
||||
available under **Technical details**.
|
||||
Review has two views:
|
||||
|
||||
The main navigation and Review view tabs use a subtle purple tint so they remain
|
||||
|
|
|
|||
Loading…
Reference in New Issue