* claim: #8592 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * History: error and warning marks in the browser and on folded folders (#8592) In the History "In browser" layout, a feature whose build failed gets the error icon at the end of its row, one that built with a warning the warning icon, with the message in the tooltip: the marks and text of the History on the left. A folded History or Features folder carries the worst mark of what it holds, and so does a folded folder in the History on the left. Suppressed and rolled-back features are not built and get none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -74,7 +74,21 @@ pub(super) fn rows(app: &mut SolveApp, ui: &mut egui::Ui, component: u64, path:
|
||||
let (key, label) =
|
||||
if compact { (format!("{scope}/history"), crate::i18n::tr("ui.history_title")) } else { (format!("{scope}/features"), "Features") };
|
||||
let open = is_open(app, &key, compact);
|
||||
let r = draw_row(ui, ui.id().with(&key), &Row { depth, fold: Some(open), icon: "folder", label, ..Default::default() });
|
||||
// Folded, it carries the worst mark of what it holds.
|
||||
let ids: Vec<u64> = if open {
|
||||
Vec::new()
|
||||
} else {
|
||||
app.session
|
||||
.doc
|
||||
.features
|
||||
.iter()
|
||||
.filter(|f| f.component == component && (compact || !matches!(f.kind, FeatureKind::Sketch { .. })))
|
||||
.map(|f| f.id)
|
||||
.collect()
|
||||
};
|
||||
let (status, tip) = crate::timeline::worst_status(app, &ids);
|
||||
let r =
|
||||
draw_row(ui, ui.id().with(&key), &Row { depth, fold: Some(open), icon: "folder", label, status, tip: tip.as_deref(), ..Default::default() });
|
||||
if r.fold || r.clicked {
|
||||
toggle(app, &key, compact);
|
||||
}
|
||||
@@ -209,10 +223,25 @@ fn feature_row(
|
||||
let visible =
|
||||
if is_sketch { crate::browser::sketch_visible(app, id) } else { bodies.iter().any(|b| !app.session.visibility.hidden_bodies.contains(b)) };
|
||||
let eye = (is_sketch || !bodies.is_empty()).then_some(visible);
|
||||
let status = crate::timeline::feature_status(app, id);
|
||||
let tip = status.and_then(|_| crate::timeline::feature_message(app, id));
|
||||
let r = draw_row(
|
||||
ui,
|
||||
ui.id().with(("browser_feature", id)),
|
||||
&Row { depth, fold, eye, icon, label: &label, selected, dim: dim || (!is_sketch && eye == Some(false)), action, mark, ..Default::default() },
|
||||
&Row {
|
||||
depth,
|
||||
fold,
|
||||
eye,
|
||||
icon,
|
||||
label: &label,
|
||||
selected,
|
||||
dim: dim || (!is_sketch && eye == Some(false)),
|
||||
action,
|
||||
mark,
|
||||
status,
|
||||
tip: tip.as_deref(),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
if r.eye && is_sketch {
|
||||
crate::browser::set_sketch_visible(app, id, !visible);
|
||||
@@ -793,4 +822,50 @@ mod tests {
|
||||
h.frames(2);
|
||||
assert!(!shown(&h), "and hides it again");
|
||||
}
|
||||
|
||||
/// #8592: a feature that failed has an error mark in the browser's history, one that built
|
||||
/// with a warning a warning mark, and the others none; the folded History carries the worst
|
||||
/// of its features, and a suppressed feature none.
|
||||
#[test]
|
||||
fn browser_history_marks_errors_and_warnings_and_the_folded_history_takes_the_worst() {
|
||||
let mut h = Harness::new();
|
||||
let mut boxes = Vec::new();
|
||||
for (i, name) in ["Clean", "Broken", "Warned"].into_iter().enumerate() {
|
||||
let size = 5 + i as u64;
|
||||
let r = h.app.run("solid.box", json!({"length":size,"width":size,"height":size,"name":name,"body_name":name})).unwrap();
|
||||
boxes.push(r["feature"].as_u64().unwrap());
|
||||
}
|
||||
h.app.run("view.history_layout", json!({"dock":"browser"})).unwrap();
|
||||
settle_heavy(&mut h);
|
||||
let set = |h: &mut Harness| {
|
||||
for (id, error, warning) in [
|
||||
(boxes[1], Some("the blend is larger than the neighbouring faces"), None),
|
||||
(boxes[2], None, Some("edge 3 no longer exists; using the edge at the picked point")),
|
||||
] {
|
||||
let result = h.app.session.model.results.iter_mut().find(|r| r.id == id).unwrap();
|
||||
result.error = error.map(str::to_string);
|
||||
result.warning = warning.map(str::to_string);
|
||||
}
|
||||
};
|
||||
set(&mut h);
|
||||
h.frames(2);
|
||||
let marks = || {
|
||||
let mut marks: Vec<String> = crate::scenario::handles("status:").into_iter().map(|(name, _)| name).collect();
|
||||
marks.sort();
|
||||
marks.dedup();
|
||||
marks
|
||||
};
|
||||
assert_eq!(marks(), ["status:error:Broken", "status:warning:Warned"]);
|
||||
|
||||
h.app.tree.collapsed.insert("c0/history".into());
|
||||
h.frames(2);
|
||||
assert_eq!(marks(), ["status:error:History"], "the folded History shows its worst feature's mark");
|
||||
|
||||
h.app.tree.collapsed.remove("c0/history");
|
||||
h.app.run("timeline.suppress", json!({"feature":boxes[1],"suppressed":true})).unwrap();
|
||||
settle_heavy(&mut h);
|
||||
set(&mut h);
|
||||
h.frames(2);
|
||||
assert_eq!(marks(), ["status:warning:Warned"], "a suppressed feature isn't built and has no mark");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! The timeline (bottom): features in order, the rollback marker, errors and warnings.
|
||||
|
||||
use crate::ui_kit::{Container, Edge, Surface};
|
||||
use crate::ui_kit::{Container, Edge, Status, Surface};
|
||||
use egui::{Rect, Sense, UiBuilder, pos2, vec2};
|
||||
use serde_json::{Value, json};
|
||||
use solidcraft_engine::doc::{
|
||||
@@ -390,6 +390,27 @@ pub(crate) fn status_text(name: &str, ty: &str, error: Option<&str>, warning: Op
|
||||
text
|
||||
}
|
||||
|
||||
/// A feature's mark: an error, else a warning; none while it is suppressed or rolled back, as
|
||||
/// it isn't built then.
|
||||
pub(crate) fn feature_status(app: &SolveApp, id: u64) -> Option<Status> {
|
||||
let index = app.session.doc.feature_index(id)?;
|
||||
let feature = app.session.doc.features.get(index)?;
|
||||
if feature.suppressed || app.session.doc.marker.is_some_and(|marker| index >= marker) {
|
||||
return None;
|
||||
}
|
||||
let result = app.session.model.result(id)?;
|
||||
if result.error.is_some() { Some(Status::Error) } else { result.warning.as_ref().map(|_| Status::Warning) }
|
||||
}
|
||||
|
||||
/// The worst mark among `ids`, with the message of the first feature that has it.
|
||||
pub(crate) fn worst_status(app: &SolveApp, ids: &[u64]) -> (Option<Status>, Option<String>) {
|
||||
let worst = ids.iter().filter_map(|id| feature_status(app, *id).map(|status| (status, *id))).reduce(|a, b| if b.0 > a.0 { b } else { a });
|
||||
match worst {
|
||||
Some((status, id)) => (Some(status), feature_message(app, id)),
|
||||
None => (None, None),
|
||||
}
|
||||
}
|
||||
|
||||
/// What a feature's error or warning mark says, as its tooltip shows it (name and type, then
|
||||
/// the error and the warning), for the clipboard. `None` when it has neither.
|
||||
pub(crate) fn feature_message(app: &SolveApp, id: u64) -> Option<String> {
|
||||
|
||||
@@ -1028,6 +1028,20 @@ fn vertical_group_row(
|
||||
if suppressed {
|
||||
painter.line_segment([icon.left_bottom(), icon.right_top()], Stroke::new(1.5, t.text_dim));
|
||||
}
|
||||
// Folded, it carries the worst mark of its features, as a feature chip marks its own (#8592).
|
||||
let (status, tip) = if open { (None, None) } else { crate::timeline::worst_status(app, &contents) };
|
||||
if let Some(status) = status {
|
||||
let side = if names { t.space_12 } else { t.space_10 };
|
||||
let at =
|
||||
if names { pos2(rect.right() - t.space_3 - side, rect.center().y - side / 2.0) } else { icon.right_top() - vec2(side / 2.0, side / 2.0) };
|
||||
let mark = Rect::from_min_size(at, vec2(side, side));
|
||||
icons::paint_icon(ui.painter(), mark, status.icon(), 1.0);
|
||||
crate::scenario::publish_handle(&format!("timeline-folder-status:{}:{}", status.icon(), group.name), mark.center());
|
||||
}
|
||||
let response = match tip {
|
||||
Some(tip) => response.on_hover_text(tip),
|
||||
None => response,
|
||||
};
|
||||
let renaming = timeline_group_name(app, ui, group, rect, offset, names, suppressed, &t);
|
||||
crate::scenario::publish_handle(&format!("timeline-folder:{}", group.name), rect.center());
|
||||
let fold_rect = Rect::from_min_max(pos2(rect.left() + offset, rect.top()), pos2(rect.left() + offset + 18.0, rect.bottom()));
|
||||
@@ -2444,6 +2458,41 @@ mod tests {
|
||||
assert!(handle_at("timeline:Inside").is_none(), "collapsed folder still showed its contents");
|
||||
}
|
||||
|
||||
/// #8592: a folded folder carries the worst mark of its features, nested folders included,
|
||||
/// and an open one none.
|
||||
#[test]
|
||||
fn a_folded_folder_carries_the_worst_mark_of_its_features() {
|
||||
let mut harness = Harness::new();
|
||||
harness.app.preferences.timeline_left = true;
|
||||
for name in ["Warned", "Broken"] {
|
||||
harness.app.run("solid.box", json!({"length": 10, "width": 10, "height": 10, "name": name})).unwrap();
|
||||
}
|
||||
harness.app.run("timeline.group", json!({"name": "Inner", "features": ["Broken"]})).unwrap();
|
||||
harness.app.run("timeline.group", json!({"name": "Outer", "features": ["Warned"]})).unwrap();
|
||||
let groups = harness.app.session.doc.timeline_groups.clone();
|
||||
let id = |name: &str| groups.iter().find(|group| group.name == name).map(|group| group.id).unwrap();
|
||||
harness.app.run("timeline.move_to_group", json!({"groups": [id("Inner")], "group": id("Outer")})).unwrap();
|
||||
harness.frames(4);
|
||||
let mark = |harness: &mut Harness, name: &str, error: Option<&str>, warning: Option<&str>| {
|
||||
let feature = harness.app.session.doc.features.iter().find(|f| f.name == name).map(|f| f.id).unwrap();
|
||||
let result = harness.app.session.model.results.iter_mut().find(|r| r.id == feature).unwrap();
|
||||
result.error = error.map(str::to_string);
|
||||
result.warning = warning.map(str::to_string);
|
||||
};
|
||||
mark(&mut harness, "Warned", None, Some("edge 3 no longer exists; using the edge at the picked point"));
|
||||
harness.frames(2);
|
||||
let marks = || crate::scenario::handles("timeline-folder-status:").into_iter().map(|(name, _)| name).collect::<Vec<_>>();
|
||||
assert!(marks().is_empty(), "open folders show their features' own marks");
|
||||
|
||||
harness.app.tree.collapsed.insert(format!("timeline_group:{}", id("Outer")));
|
||||
harness.frames(2);
|
||||
assert_eq!(marks(), ["timeline-folder-status:warning:Outer"]);
|
||||
|
||||
mark(&mut harness, "Broken", Some("the blend is larger than the neighbouring faces"), None);
|
||||
harness.frames(2);
|
||||
assert_eq!(marks(), ["timeline-folder-status:error:Outer"], "an error in a nested folder outweighs the warning");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drop_below_a_collapsed_folder_appends_to_that_folder() {
|
||||
let mut harness = Harness::new();
|
||||
|
||||
@@ -46,6 +46,9 @@ pub(crate) struct Row<'a> {
|
||||
pub(crate) kind_tip: Option<&'a str>,
|
||||
/// Lit by the selection or the 3D view's pointer: the item's own row, or a row leading to it.
|
||||
pub(crate) mark: Mark,
|
||||
/// A feature that failed or built with a warning, or a folded row holding one: its mark at
|
||||
/// the row's end, the message in [`Row::tip`].
|
||||
pub(crate) status: Option<Status>,
|
||||
/// Optional document appearance and shared trailing text slots.
|
||||
pub(crate) swatch: Option<Color32>,
|
||||
pub(crate) secondary: &'a str,
|
||||
@@ -67,6 +70,23 @@ pub(crate) enum Mark {
|
||||
Here,
|
||||
}
|
||||
|
||||
/// A feature's build state as its row marks it; the worse one sorts last.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub(crate) enum Status {
|
||||
Warning,
|
||||
Error,
|
||||
}
|
||||
|
||||
impl Status {
|
||||
/// The icon and the scenario handle's word.
|
||||
pub(crate) fn icon(self) -> &'static str {
|
||||
match self {
|
||||
Status::Warning => "warning",
|
||||
Status::Error => "error",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// What happened on a row.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct RowResp {
|
||||
@@ -247,6 +267,13 @@ pub(crate) fn tree_row(ui: &mut egui::Ui, id: egui::Id, row: &Row) -> RowResp {
|
||||
// and its full text is in the tooltip.
|
||||
let badges_width = row.badges.len() as f32 * 15.0;
|
||||
let mut right = if row.compact && row.eye.is_some() { eye_r.left() - t.space_4 } else { action_left } - badges_width;
|
||||
if let Some(status) = row.status {
|
||||
right -= t.space_16;
|
||||
let sr = Rect::from_center_size(pos2(right + t.space_8, cy), vec2(t.space_14, t.space_14));
|
||||
icons::paint_icon(ui.painter(), sr, status.icon(), 1.0);
|
||||
crate::scenario::publish_handle(&format!("status:{}:{}", status.icon(), row.label), sr.center());
|
||||
right -= t.space_4;
|
||||
}
|
||||
for text in [row.count, row.secondary, if row.compact { row.subtitle } else { "" }] {
|
||||
if text.is_empty() {
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user