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::analysis::quality_export::ExportForm;
5use crate::render::layout::dialog_in;
6use crate::widgets::data_quality::DataQualityWidgetConfig;
7use crate::widgets::ui::{FormLine, FormValue, FormView};
8use ratatui::buffer::Buffer;
9use ratatui::layout::Rect;
10use ratatui::style::Style;
11
12const LABEL_WIDTH: u16 = 9;
13
14pub fn render(
15    form: &ExportForm,
16    config: &DataQualityWidgetConfig<'_>,
17    area: Rect,
18    buf: &mut Buffer,
19) {
20    let ctx = config.ctx;
21    let width = 64.min(area.width.saturating_sub(2));
22    // Path, format, a blank and the status line, inside the frame.
23    let popup = dialog_in(area, width, 6);
24    // Not a `Form`: its keys are Data Quality's, and its rows take no clicks.
25    FormView {
26        title: "Export Report",
27        screen: datui_cli::keys::Context::DataQuality,
28        footer: None,
29        label_width: LABEL_WIDTH,
30        rows: vec![
31            FormLine::Field(false, "Path:", FormValue::Input(&form.path)),
32            FormLine::Field(true, "Format:", FormValue::Choice(form.format.label())),
33        ],
34        focused: Some(form.on_format),
35        picker: None,
36        status: Some(match &form.error {
37            Some(error) => (error.clone(), Style::default().fg(ctx.warning)),
38            None => (
39                crate::glyphs::dotted(&format!("{} ยท no read", form.format.holds())),
40                Style::default().fg(ctx.dimmed),
41            ),
42        }),
43        // The report under it is shielded by Data Quality's drawing.
44        shields: false,
45    }
46    .render_unrecorded(popup, buf, ctx);
47}