Skip to main content

datui_lib/widgets/
quality_export.rs

1//! The dialog that writes the Data Quality report on screen to a file: a path and
2//! a form, and a line saying what the form holds or why Enter did not write.
3
4use crate::quality_export::ExportForm;
5use crate::widgets::data_quality::{DataQualityWidgetConfig, centered_rect, dotted, fit};
6use crate::widgets::ui::{FormRow, FormValue, Surface};
7use ratatui::buffer::Buffer;
8use ratatui::layout::Rect;
9use ratatui::style::Style;
10use ratatui::text::Line;
11use ratatui::widgets::{Paragraph, Widget};
12
13const LABEL_WIDTH: u16 = 9;
14
15pub fn render(
16    form: &ExportForm,
17    config: &DataQualityWidgetConfig<'_>,
18    area: Rect,
19    buf: &mut Buffer,
20) {
21    let ctx = config.ctx;
22    let width = 64.min(area.width.saturating_sub(2));
23    // Path, format, a blank and the status line, inside the frame.
24    let popup = centered_rect(width, 6, area);
25    let content = Surface::new("Export Report").render(popup, buf, ctx);
26    if content.height < 2 || content.width < 8 {
27        return;
28    }
29    let line = |index: u16| Rect {
30        y: content.y + index,
31        height: 1,
32        ..content
33    };
34    FormRow {
35        label: "Path:",
36        value: FormValue::Input(&form.path),
37        focused: !form.on_format,
38        label_width: LABEL_WIDTH,
39    }
40    .render(line(0), buf, ctx);
41    FormRow {
42        label: "Format:",
43        value: FormValue::Choice(form.format.label()),
44        focused: form.on_format,
45        label_width: LABEL_WIDTH,
46    }
47    .render(line(1), buf, ctx);
48    let (status, warn) = match &form.error {
49        Some(error) => (error.clone(), true),
50        None => (format!("{} ยท no read", form.format.holds()), false),
51    };
52    Paragraph::new(Line::styled(
53        fit(&dotted(&status), content.width as usize),
54        Style::default().fg(if warn { ctx.warning } else { ctx.dimmed }),
55    ))
56    .render(line(content.height - 1), buf);
57}