agent: Add tooltip to diff stats (#51448)

Cameron Mcloughlin created

Change summary

crates/ui/src/components/ai/thread_item.rs | 14 ++++++++------
crates/ui/src/components/diff_stat.rs      | 12 ++++++++++++
2 files changed, 20 insertions(+), 6 deletions(-)

Detailed changes

crates/ui/src/components/ai/thread_item.rs 🔗

@@ -311,11 +311,10 @@ impl RenderOnce for ThreadItem {
                             this.child(dot_separator())
                         })
                         .when(has_diff_stats, |this| {
-                            this.child(DiffStat::new(
-                                diff_stat_id.clone(),
-                                added_count,
-                                removed_count,
-                            ))
+                            this.child(
+                                DiffStat::new(diff_stat_id.clone(), added_count, removed_count)
+                                    .tooltip("Unreviewed changes"),
+                            )
                         })
                         .when(has_diff_stats && has_timestamp, |this| {
                             this.child(dot_separator())
@@ -336,7 +335,10 @@ impl RenderOnce for ThreadItem {
                         .gap_1p5()
                         .child(icon_container()) // Icon Spacing
                         .when(has_diff_stats, |this| {
-                            this.child(DiffStat::new(diff_stat_id, added_count, removed_count))
+                            this.child(
+                                DiffStat::new(diff_stat_id, added_count, removed_count)
+                                    .tooltip("Unreviewed changes"),
+                            )
                         })
                         .when(has_diff_stats && has_timestamp, |this| {
                             this.child(dot_separator())

crates/ui/src/components/diff_stat.rs 🔗

@@ -1,3 +1,4 @@
+use crate::Tooltip;
 use crate::prelude::*;
 
 #[derive(IntoElement, RegisterComponent)]
@@ -6,6 +7,7 @@ pub struct DiffStat {
     added: usize,
     removed: usize,
     label_size: LabelSize,
+    tooltip: Option<SharedString>,
 }
 
 impl DiffStat {
@@ -15,6 +17,7 @@ impl DiffStat {
             added,
             removed,
             label_size: LabelSize::Small,
+            tooltip: None,
         }
     }
 
@@ -22,10 +25,16 @@ impl DiffStat {
         self.label_size = label_size;
         self
     }
+
+    pub fn tooltip(mut self, tooltip: impl Into<SharedString>) -> Self {
+        self.tooltip = Some(tooltip.into());
+        self
+    }
 }
 
 impl RenderOnce for DiffStat {
     fn render(self, _: &mut Window, _cx: &mut App) -> impl IntoElement {
+        let tooltip = self.tooltip;
         h_flex()
             .id(self.id)
             .gap_1()
@@ -39,6 +48,9 @@ impl RenderOnce for DiffStat {
                     .color(Color::Error)
                     .size(self.label_size),
             )
+            .when_some(tooltip, |this, tooltip| {
+                this.tooltip(Tooltip::text(tooltip))
+            })
     }
 }