knotra 0.34.0

knotra: multi-project VCS dashboard and bulk-operation tool.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
//! A single dashboard project row: identity, status/progress summary, and
//! the tier-specific action.

use iced::widget::{Space, button, column, container, rich_text, row, span, text};
use iced::{Alignment, Element, Length, Padding};
use knotra_ui::widget::{
    BUTTON_HEIGHT, STRONG_FONT, Tokens, body_badge_diameter, centered_button_label,
    centered_button_row, checkbox, status_badge, style,
};
use knotra_vcs::model::project::Project;

use crate::{
    message::{ConflictOpsMessage, DetailPanelMessage, Message, SelectionMessage},
    state::{
        AppState,
        dashboard::{
            DashboardCause, DashboardEntry, DashboardTier, ProgressKind, badge_for_all_set,
            badge_for_cause, badge_for_progress, workspace_has_mixed_vcs_kinds,
        },
        focus::FocusTarget,
    },
};

use super::width_mode::WidthMode;

/// Bounded row-track widths (R9), sized for the 1000-1279px standard-width
/// breakpoint (`.git-exclude/reviewed/062-...md` "Standard, 1000-1279px:
/// bounded three-track project rows"): identity, then status/progress, then
/// the tier action, each a fixed width rather than `FillPortion` so the
/// three columns line up down the entire list. Originally measured against
/// a 1000px window (a now-removed 180px sidebar from an earlier shell
/// layout left ~820px of content, minus the dashboard body's 24px
/// horizontal padding, the row's own 16px padding, and 16px of
/// inter-column spacing, leaving ~764px before a scrollbar), with the
/// original sum (700px of tracks + 16px of gaps = 716px) keeping a margin
/// at that floor. The sidebar itself, and the `SIDEBAR_WIDTH` constant
/// that named it, are long gone from the shell (RFC-071 D8a removes the
/// leftover constant); this measurement stays historical rather than
/// rewritten to describe a shell that no longer exists. RFC-071 D8 then
/// grew `ACTION_TRACK_WIDTH` from 100px to 160px (see its own doc comment
/// below) — the sum is now 760px of tracks + 16px of gaps = 776px,
/// already past the old 764px sidebar-era floor; the floor itself no
/// longer applies (there is no sidebar to leave ~764px of content), and a
/// real build confirms today's three tracks still fit cleanly in a real
/// 1000px-wide window (the screenshots behind `ACTION_TRACK_WIDTH`'s own
/// measurement), so this is not a live regression — only the historical
/// arithmetic's own margin claim, which this note corrects rather than
/// leaves silently wrong. Stage 4 centres and may revisit these; they must
/// not grow indefinitely at wide widths (the audit's explicit warning), so
/// this stage keeps them fixed rather than picking something that only
/// works at one size.
const IDENTITY_TRACK_WIDTH: f32 = 280.0;
const MIDDLE_TRACK_WIDTH: f32 = 320.0;

/// RFC-071 D8: grown from 100px to fit `row_action_button`'s label at
/// `body` (16px) — Amendment A3 D14 moved that label off `body_small`
/// (14px) without revisiting this width, so the longest pair in either
/// language, "Choose resolution" / 「解決方法を選ぶ」 (`dashboard.resolve`,
/// the longer of the two possible action labels — confirmed by reading
/// `crates/knotra-ui/src/i18n.rs`), wrapped onto two lines at the old
/// value. Measured the same way Task 098 found its own button-padding
/// defect: a real build, a real NeedsHelp/conflict row at the Standard
/// band (~1040px window), screenshotted in both languages at each
/// candidate width. 100/140/150px wrapped "Choose resolution"; 160px was
/// the smallest round value (matching this file's own `IDENTITY_`/
/// `MIDDLE_TRACK_WIDTH` convention of clean round numbers) where both
/// languages rendered on one line with visible margin from the track's own
/// edge, at 160/180/200px alike — the button is content-sized, not
/// track-stretched, so 160px is the point past which a wider track buys
/// nothing.
const ACTION_TRACK_WIDTH: f32 = 160.0;

/// Stable per-row `FocusTarget` keys, shared between `dashboard/mod.rs`'s
/// `focus_order` and this module's [`is_focused`] — one expression per
/// target rather than the `format!` string duplicated in each place
/// (Handoff 025 §7.5, same discipline as `toolbar.rs`/`section.rs`).
pub(super) fn checkbox_key(id: &knotra_vcs::ProjectId) -> String {
    format!("dashboard.row.{id}.checkbox")
}

pub(super) fn name_key(id: &knotra_vcs::ProjectId) -> String {
    format!("dashboard.row.{id}.name")
}

pub(super) fn action_key(id: &knotra_vcs::ProjectId) -> String {
    format!("dashboard.row.{id}.action")
}

fn is_focused(state: &AppState, key: &str) -> bool {
    state.dashboard_focus.as_ref() == Some(&FocusTarget::control_dynamic(key.to_owned()))
}

/// RFC-071 D4: the project-name button's own text colour — `accent` on
/// hover, press, or keyboard focus; `text_primary` at rest. Kept in step
/// with `name_button`'s span, which applies the same rule statically for
/// `focused` (see that function's own doc comment for why hover alone
/// cannot drive the span's underline the same way).
fn project_name_style(
    tokens: &Tokens,
    status: iced::widget::button::Status,
    focused: bool,
) -> iced::widget::button::Style {
    use iced::widget::button::Status;

    let text_primary = snora::design::style::color::to_iced_color(tokens.palette.text_primary);
    let accent = snora::design::style::color::to_iced_color(tokens.palette.accent);
    let text_color = if focused || matches!(status, Status::Hovered | Status::Pressed) {
        accent
    } else {
        text_primary
    };
    iced::widget::button::Style {
        background: None,
        text_color,
        ..iced::widget::button::Style::default()
    }
}

pub(super) fn view_project_row<'a>(
    state: &'a AppState,
    entry: DashboardEntry<'a>,
    mode: WidthMode,
) -> Element<'a, Message> {
    let tokens = &state.theme.tokens;
    let project = entry.project;

    let checkbox_element = selection_checkbox(state, tokens, project);
    let name = name_button(state, tokens, project);
    let action = row_action(state, tokens, &entry, project);
    // RFC-073 Amendment A6 §2: an unborn HEAD's own `context.label` is just
    // the branch name — on its own indistinguishable from an ordinary
    // branch with commits — so this composes "<branch> · No commits yet"
    // here, the one place both layouts read `work_area` from.
    let work_area = entry
        .status
        .and_then(|status| status.context.as_ref())
        .map(|context| {
            if context.unborn {
                format!(
                    "{} · {}",
                    context.label,
                    state.t("dashboard.no_commits_yet")
                )
            } else {
                context.label.clone()
            }
        })
        .unwrap_or_else(|| state.t("dashboard.work_area_unknown").to_owned());

    match mode {
        WidthMode::Compact => {
            view_compact_row(state, &entry, checkbox_element, name, action, work_area)
        }
        WidthMode::Standard | WidthMode::Wide => {
            view_standard_row(state, &entry, checkbox_element, name, action, work_area)
        }
    }
}

/// The selection checkbox, when selection mode is on — shared between the
/// standard and compact layouts, which place it differently but never
/// change its behaviour or focus target.
fn selection_checkbox<'a>(
    state: &'a AppState,
    tokens: &Tokens,
    project: &'a Project,
) -> Option<Element<'a, Message>> {
    if !state.selection_mode {
        return None;
    }
    let id = project.id.clone();
    let is_checked = state.selection.contains(&project.id);
    Some(checkbox(
        tokens,
        format!(
            "{} — {}",
            state.t("plain.selection.select_project"),
            project.name
        ),
        is_checked,
        move |_checked| Message::Selection(SelectionMessage::Toggled(id.clone())),
        is_focused(state, &checkbox_key(&project.id)),
    ))
}

/// RFC-071 D4: a project name is `text_primary` at rest — blue is for
/// what acts, and a name's own click target/message are unchanged, but it
/// no longer looks like a link by default. On hover or keyboard focus it
/// becomes `accent`, with an underline, so what is clickable is visible
/// when it matters (never only on hover — A1 D13 item 2).
///
/// **Hover and focus are not symmetric here, and that is reported, not
/// silently accepted**: a plain `iced::widget::Text`'s colour has no
/// per-`button::Status` hook of its own, so hover's colour change is driven
/// entirely by the button's own `.style(...)` closure (which iced already
/// re-evaluates every frame from real pointer state) — the name's `Span`
/// leaves its colour unset there, inheriting the button's. The underline
/// has no such ambient hook: `iced::widget::text::Style` carries only a
/// colour, and `Span::underline` is static content built once per `view()`
/// call, with no per-`Status` variant at all. Keyboard focus already is
/// app state the view rebuilds on, so the span can set its own colour and
/// underline statically whenever `focused` is true; mouse hover is not
/// tracked as app state anywhere, and adding live pointer-position
/// tracking to get a reactive underline on hover alone was judged
/// disproportionate to this one cosmetic detail.
fn name_button<'a>(
    state: &'a AppState,
    tokens: &Tokens,
    project: &'a Project,
) -> Element<'a, Message> {
    let focused = is_focused(state, &name_key(&project.id));
    let t = tokens.clone();

    let mut name_span: iced::advanced::text::Span<'_, ()> =
        span(project.name.as_str()).font(STRONG_FONT);
    if focused {
        name_span = name_span
            .color(snora::design::style::color::to_iced_color(
                tokens.palette.accent,
            ))
            .underline(true);
    }
    let label = rich_text![name_span]
        .size(snora::design::style::text::body_size(tokens))
        .line_height(snora::design::style::text::body_line_height(tokens));

    // RFC-071 A1 D13 item 2: a small "›" follows the name, in
    // `text_secondary`, always visible — so what a name does is
    // recognisable without hovering, not only on hover or focus.
    let cue = knotra_ui::widget::icon::colored_icon_element(
        &knotra_ui::widget::icon::chevron_right(),
        snora::design::style::text::body_small_size(tokens).0,
        snora::design::style::color::to_iced_color(tokens.palette.text_secondary),
    );

    // RFC-071 D8: `left: 0.0` — a plain `button` otherwise opens with
    // `button::DEFAULT_PADDING`'s 10px left inset, which the VCS kind text
    // pushed directly beneath it (`identity_details`, no padding of its
    // own) does not share; without this the name's own glyphs start 10px
    // right of where "Git"/"jj" starts, even though both are meant to line
    // up at the identity column's left edge.
    // RFC-073 D8: at least `SMALL_BUTTON_HEIGHT`, here `BUTTON_HEIGHT` — a
    // project name is the dashboard's single most-clicked target.
    button(centered_button_row(row![label, cue].spacing(2)))
        .height(Length::Fixed(BUTTON_HEIGHT))
        .padding(Padding {
            left: 0.0,
            ..button::DEFAULT_PADDING
        })
        .on_press(Message::DetailPanel(DetailPanelMessage::Opened(
            project.id.clone(),
        )))
        .style(move |_theme, status| {
            style::with_focus_ring(&t, focused, project_name_style(&t, status, focused))
        })
        .into()
}

/// The tier-specific row action — shared between layouts. `Space::new()` for
/// InProgress/AllSet (no action slot, per RFC-032 R10's tier density).
fn row_action<'a>(
    state: &'a AppState,
    tokens: &Tokens,
    entry: &DashboardEntry<'a>,
    project: &'a Project,
) -> Element<'a, Message> {
    if entry.tier != DashboardTier::NeedsHelp {
        return Space::new().into();
    }
    let focused = is_focused(state, &action_key(&project.id));
    if entry.cause == Some(DashboardCause::Conflict) {
        // The row's one mutating action (RFC-032 R10): opens the
        // conflict-resolution overlay, so it carries `secondary`'s
        // stronger weight.
        //
        // RFC-035 R13/Handoff 030 §6.2: no busy-reason text here anymore.
        // With multiple needs-help/conflict rows on screen, each printing
        // "Busy" while the interlock is held is the same duplication R13
        // targets in the selection bar, just repeated per row instead of
        // per action. The button still disables correctly (`on_press_maybe`
        // stays gated on `!is_busy()`); it just stops re-explaining why,
        // the same way row.rs's other actions never explained "busy" either.
        row_action_button(
            tokens,
            state.t("dashboard.resolve"),
            style::secondary,
            (!state.operation_interlock.is_busy()).then_some(Message::ConflictOps(
                ConflictOpsMessage::OpenRequested(Some(project.id.clone())),
            )),
            None,
            focused,
        )
    } else {
        // Dispatches the same `DetailPanel::Opened` message the project
        // name does — a link-weight affordance to the same destination,
        // not a distinct mutating action, so `ghost` matches the name's
        // own treatment rather than `secondary`.
        row_action_button(
            tokens,
            state.t("plain.show_details"),
            style::ghost,
            Some(Message::DetailPanel(DetailPanelMessage::Opened(
                project.id.clone(),
            ))),
            None,
            focused,
        )
    }
}

/// RFC-071 D3: the badge for a row's own status line — picks the one
/// `badge_for_*` function that matches what the row's status text already
/// shows (`cause_label` for `NeedsHelp`, the count line for `InProgress`,
/// `work_area` for `AllSet`), so the badge is never out of step with the
/// words beside it. The `None`/fallback cases mirror the status line's own
/// fallback text exactly: `cause_label` reads a missing cause the same way
/// `Some(StatusUnknown)` does, and the count line falls back to
/// `plain.status.unsaved_work` when `relevant_count` is `None`.
fn entry_badge(entry: &DashboardEntry<'_>) -> (knotra_ui::widget::Tone, snora::Icon) {
    match entry.tier {
        DashboardTier::NeedsHelp => {
            badge_for_cause(entry.cause.unwrap_or(DashboardCause::StatusUnknown))
        }
        DashboardTier::InProgress => badge_for_progress(
            entry
                .relevant_count
                .map(|c| c.kind)
                .unwrap_or(ProgressKind::Uncommitted),
        ),
        DashboardTier::AllSet => badge_for_all_set(),
    }
}

/// Standard/wide layout (R9): bounded three-track row, unchanged from Stage 3.
fn view_standard_row<'a>(
    state: &'a AppState,
    entry: &DashboardEntry<'a>,
    checkbox_element: Option<Element<'a, Message>>,
    name: Element<'a, Message>,
    action: Element<'a, Message>,
    work_area: String,
) -> Element<'a, Message> {
    let tokens = &state.theme.tokens;
    let mut identity = row![].spacing(4).align_y(Alignment::Center);
    if let Some(checkbox_element) = checkbox_element {
        identity = identity.push(checkbox_element);
    }
    let mut identity_details = column![name].spacing(2);
    // RFC-073 D3: the kind label tells something only when the workspace
    // holds both Git and Jujutsu projects.
    if entry.tier == DashboardTier::NeedsHelp
        && workspace_has_mixed_vcs_kinds(state.workspace_status.as_ref())
    {
        let vcs = entry
            .status
            .map(|status| status.identity.vcs_kind.to_string())
            .unwrap_or_else(|| state.t("status.unknown").to_owned());
        identity_details = identity_details.push(
            text(vcs)
                .size(snora::design::style::text::body_small_size(tokens))
                .line_height(snora::design::style::text::body_small_line_height(tokens)),
        );
    }
    identity = identity.push(identity_details);

    // RFC-071 D1: a project's status line is `body`, same as D9's density
    // adjustments expect — the VCS sub-line above it (metadata) keeps
    // `body_small`. RFC-071 D3: the status line carries a tone badge before
    // its words — never colour alone, the badge's symbol and the words both
    // carry the meaning.
    let (tone, glyph) = entry_badge(entry);
    let diameter = body_badge_diameter(tokens);
    let middle: Element<'_, Message> = match entry.tier {
        DashboardTier::NeedsHelp => row![
            status_badge(tokens, tone, &glyph, diameter),
            text(cause_label(state, entry.cause))
                .size(snora::design::style::text::body_size(tokens))
                .line_height(snora::design::style::text::body_line_height(tokens)),
        ]
        .spacing(6)
        .align_y(Alignment::Center)
        .into(),
        DashboardTier::InProgress => {
            let count = entry
                .relevant_count
                .map(|count| format!("{}: {}", progress_label(state, count.kind), count.value))
                .unwrap_or_else(|| state.t("plain.status.unsaved_work").to_owned());
            // RFC-071 Amendment A3 D9: one status line, joining the two
            // existing catalog texts with " · " — no new wording — the
            // same one-line shape NeedsHelp and AllSet already use below,
            // instead of `work_area` and `count` on two separate lines.
            row![
                status_badge(tokens, tone, &glyph, diameter),
                text(format!("{work_area} · {count}"))
                    .size(snora::design::style::text::body_size(tokens))
                    .line_height(snora::design::style::text::body_line_height(tokens)),
            ]
            .spacing(6)
            .align_y(Alignment::Center)
            .into()
        }
        DashboardTier::AllSet => row![
            status_badge(tokens, tone, &glyph, diameter),
            text(work_area)
                .size(snora::design::style::text::body_size(tokens))
                .line_height(snora::design::style::text::body_line_height(tokens)),
        ]
        .spacing(6)
        .align_y(Alignment::Center)
        .into(),
    };

    container(
        row![
            container(identity).width(Length::Fixed(IDENTITY_TRACK_WIDTH)),
            container(middle).width(Length::Fixed(MIDDLE_TRACK_WIDTH)),
            container(action).width(Length::Fixed(ACTION_TRACK_WIDTH)),
        ]
        .spacing(8)
        .align_y(Alignment::Center),
    )
    .width(Length::Fill)
    .padding([7, 8])
    .into()
}

/// Compact layout (R8, 800-999px): two lines. Line one is identity and the
/// row action (pushed to the far edge by a `Fill` spacer, same idiom the
/// toolbar/shell use for pinning a control to the opposite end of a row);
/// line two is a single combined status/reason line. Tier density is
/// unchanged from the standard layout (RFC-032 R10) — this only rearranges
/// the same content onto two lines instead of three tracks.
fn view_compact_row<'a>(
    state: &'a AppState,
    entry: &DashboardEntry<'a>,
    checkbox_element: Option<Element<'a, Message>>,
    name: Element<'a, Message>,
    action: Element<'a, Message>,
    work_area: String,
) -> Element<'a, Message> {
    let mut line_one = row![].spacing(4).align_y(Alignment::Center);
    if let Some(checkbox_element) = checkbox_element {
        line_one = line_one.push(checkbox_element);
    }
    line_one = line_one.push(name);
    line_one = line_one.push(Space::new().width(Length::Fill));
    line_one = line_one.push(action);

    let tokens = &state.theme.tokens;
    let line_two = compact_status_line(state, entry, &work_area);
    let (tone, glyph) = entry_badge(entry);

    container(
        column![
            line_one,
            row![
                status_badge(tokens, tone, &glyph, body_badge_diameter(tokens)),
                // RFC-071 Amendment A3 D9: `Length::Fill` so this line
                // wraps instead of rendering unbounded past the window's
                // edge — a `Row` with no `Fill` child sizes itself to its
                // children's natural width, and `text` only wraps when its
                // own layout width is bounded.
                text(line_two)
                    .size(snora::design::style::text::body_size(tokens))
                    .line_height(snora::design::style::text::body_line_height(tokens))
                    .width(Length::Fill),
            ]
            .spacing(6)
            .align_y(Alignment::Center),
        ]
        .spacing(2),
    )
    .width(Length::Fill)
    .padding([7, 8])
    .into()
}

/// The compact layout's single status/reason line, folding what the
/// standard layout spreads across the identity column's VCS sub-line and
/// the middle track into one line per tier — same content, not more or
/// less (RFC-032 R10).
fn compact_status_line(state: &AppState, entry: &DashboardEntry<'_>, work_area: &str) -> String {
    match entry.tier {
        // RFC-073 D3: the kind label tells something only when the
        // workspace holds both Git and Jujutsu projects.
        DashboardTier::NeedsHelp
            if workspace_has_mixed_vcs_kinds(state.workspace_status.as_ref()) =>
        {
            let vcs = entry
                .status
                .map(|status| status.identity.vcs_kind.to_string())
                .unwrap_or_else(|| state.t("status.unknown").to_owned());
            format!("{vcs} · {}", cause_label(state, entry.cause))
        }
        DashboardTier::NeedsHelp => cause_label(state, entry.cause).to_owned(),
        DashboardTier::InProgress => {
            let count = entry
                .relevant_count
                .map(|count| format!("{}: {}", progress_label(state, count.kind), count.value))
                .unwrap_or_else(|| state.t("plain.status.unsaved_work").to_owned());
            format!("{work_area} · {count}")
        }
        DashboardTier::AllSet => work_area.to_owned(),
    }
}

/// The row's tier-specific action (R6): `secondary` for the row's one
/// mutating action, `ghost` for a link-weight affordance — the caller
/// chooses which via `style_fn`, one of `style::secondary`/`style::ghost`'s
/// plain-function signatures (same shape `select_mode_button` in
/// `toolbar.rs` closes over, but parametrized here since a row's action
/// varies by cause). Replaces `guided_button`'s disabled-reason-text
/// composition on top of a real semantic style plus a working focus ring,
/// keyed to the row's `dashboard.row.{id}.action` target.
fn row_action_button<'a>(
    tokens: &Tokens,
    label: &'a str,
    style_fn: fn(&Tokens, iced::widget::button::Status) -> iced::widget::button::Style,
    on_press: Option<Message>,
    reason: Option<&'a str>,
    is_focused: bool,
) -> Element<'a, Message> {
    let t = tokens.clone();
    let show_reason = on_press.is_none();

    // RFC-071 Amendment A3 D14: a button label, then its disabled-reason —
    // both `body`.
    let btn = button(centered_button_label(
        text(label)
            .size(snora::design::style::text::body_size(tokens))
            .line_height(snora::design::style::text::body_line_height(tokens)),
    ))
    .height(BUTTON_HEIGHT)
    .padding([0, 12])
    .on_press_maybe(on_press)
    .style(move |_theme, status| style::with_focus_ring(&t, is_focused, style_fn(&t, status)));

    match reason {
        Some(r) if show_reason => column![
            btn,
            text(r)
                .size(snora::design::style::text::body_size(tokens))
                .line_height(snora::design::style::text::body_line_height(tokens))
        ]
        .spacing(4)
        .into(),
        _ => btn.into(),
    }
}

fn cause_label(state: &AppState, cause: Option<DashboardCause>) -> &'static str {
    match cause {
        Some(DashboardCause::MissingPath) => state.t("dashboard.cause.missing_path"),
        Some(DashboardCause::Conflict) => state.t("dashboard.cause.conflict"),
        Some(DashboardCause::ConflictDetectionUnavailable) => {
            state.t("dashboard.cause.conflict_detection_unavailable")
        }
        Some(DashboardCause::ReadUnavailable) => state.t("dashboard.cause.read_unavailable"),
        Some(DashboardCause::DetachedContext) => state.t("dashboard.cause.detached_context"),
        Some(DashboardCause::StatusUnknown) | None => state.t("dashboard.cause.status_unknown"),
    }
}

fn progress_label(state: &AppState, kind: ProgressKind) -> &'static str {
    match kind {
        ProgressKind::Uncommitted => state.t("dashboard.progress.uncommitted"),
        ProgressKind::Untracked => state.t("dashboard.progress.untracked"),
        ProgressKind::Ahead => state.t("dashboard.progress.ahead"),
        ProgressKind::Behind => state.t("dashboard.progress.behind"),
    }
}