feat(readarr): add the history UI

Renders the history table, its sort, search and filter prompts, both
empty result popups and the item details view. Snapshots cover a
non-default selection so that reading a row from a fixed index rather
than the current selection cannot pass unnoticed.
This commit is contained in:
Dark-Alex-17 committed 2026-09-04 09:49:36 -06:00
1 parent 91c2613e65
commit ee07a0289f
16 files changed
+584 -3

No files matched your search

@@ -0,0 +1,154 @@
#[cfg(test)]
mod tests {
use strum::IntoEnumIterator;
use crate::app::App;
use crate::models::servarr_data::readarr::readarr_data::{ActiveReadarrBlock, HISTORY_BLOCKS};
use crate::ui::DrawUi;
use crate::ui::readarr_ui::history::HistoryUi;
use crate::ui::ui_test_utils::test_utils::render_to_string_with_app;
#[test]
fn test_history_ui_accepts() {
ActiveReadarrBlock::iter().for_each(|active_readarr_block| {
if HISTORY_BLOCKS.contains(&active_readarr_block) {
assert!(HistoryUi::accepts(active_readarr_block.into()));
} else {
assert!(!HistoryUi::accepts(active_readarr_block.into()));
}
});
}
mod snapshot_tests {
use chrono::DateTime;
use rstest::rstest;
use crate::models::readarr_models::{
ReadarrHistoryData, ReadarrHistoryEventType, ReadarrHistoryItem,
};
use crate::models::servarr_models::{Quality, QualityWrapper};
use crate::ui::ui_test_utils::test_utils::TerminalSize;
use super::*;
#[test]
fn test_history_ui_renders_loading() {
let mut app = App::test_default();
app.is_loading = true;
app.push_navigation_stack(ActiveReadarrBlock::History.into());
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
HistoryUi::draw(f, app, f.area());
});
insta::assert_snapshot!(output);
}
#[rstest]
fn test_history_ui_renders_empty(
#[values(ActiveReadarrBlock::History, ActiveReadarrBlock::HistoryItemDetails)]
active_readarr_block: ActiveReadarrBlock,
) {
let mut app = App::test_default();
app.push_navigation_stack(active_readarr_block.into());
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
HistoryUi::draw(f, app, f.area());
});
insta::assert_snapshot!(format!("empty_history_tab_{active_readarr_block}"), output);
}
#[rstest]
fn test_history_ui_renders(
#[values(
ActiveReadarrBlock::History,
ActiveReadarrBlock::HistoryItemDetails,
ActiveReadarrBlock::HistorySortPrompt,
ActiveReadarrBlock::FilterHistory,
ActiveReadarrBlock::FilterHistoryError,
ActiveReadarrBlock::SearchHistory,
ActiveReadarrBlock::SearchHistoryError
)]
active_readarr_block: ActiveReadarrBlock,
) {
let mut app = App::test_default_fully_populated();
app.push_navigation_stack(active_readarr_block.into());
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
HistoryUi::draw(f, app, f.area());
});
insta::assert_snapshot!(format!("history_tab_{active_readarr_block}"), output);
}
#[rstest]
fn test_history_ui_renders_second_item_selected(
#[values(ActiveReadarrBlock::History, ActiveReadarrBlock::HistoryItemDetails)]
active_readarr_block: ActiveReadarrBlock,
) {
let mut app = App::test_default();
app.data.readarr_data.history.set_items(history_vec());
app.data.readarr_data.history.select_index(Some(1));
app.push_navigation_stack(active_readarr_block.into());
let output = render_to_string_with_app(TerminalSize::Large, &mut app, |f, app| {
HistoryUi::draw(f, app, f.area());
});
insta::assert_snapshot!(
format!("history_second_item_selected_{active_readarr_block}"),
output
);
}
fn history_vec() -> Vec<ReadarrHistoryItem> {
vec![
ReadarrHistoryItem {
id: 1,
author_id: 1,
book_id: 1,
source_title: "First Source Title".into(),
quality: QualityWrapper {
quality: Quality {
name: "EPUB".to_owned(),
},
},
date: DateTime::from(DateTime::parse_from_rfc3339("2023-05-20T21:29:16Z").unwrap()),
event_type: ReadarrHistoryEventType::Grabbed,
data: ReadarrHistoryData {
indexer: Some("DrunkenSlug".to_owned()),
nzb_info_url: Some("https://drunkenslug.com/details/first".to_owned()),
release_group: Some("FirstReleaseGroup".to_owned()),
age: Some("3".to_owned()),
published_date: Some(DateTime::from(
DateTime::parse_from_rfc3339("2023-05-18T08:15:00Z").unwrap(),
)),
download_client_name: Some("nzbget".to_owned()),
..ReadarrHistoryData::default()
},
},
ReadarrHistoryItem {
id: 2,
author_id: 2,
book_id: 2,
source_title: "Second Source Title".into(),
quality: QualityWrapper {
quality: Quality {
name: "MOBI".to_owned(),
},
},
date: DateTime::from(DateTime::parse_from_rfc3339("2024-08-14T09:03:47Z").unwrap()),
event_type: ReadarrHistoryEventType::DownloadFailed,
data: ReadarrHistoryData {
download_client_name: Some("sabnzbd".to_owned()),
message: Some("The download client reported a failure".to_owned()),
release_group: Some("SecondReleaseGroup".to_owned()),
indexer: Some("Nyaa".to_owned()),
..ReadarrHistoryData::default()
},
},
]
}
}
}
+122
View File
@@ -0,0 +1,122 @@
use super::readarr_ui_utils::create_history_event_details;
use crate::app::App;
use crate::models::Route;
use crate::models::readarr_models::ReadarrHistoryItem;
use crate::models::servarr_data::readarr::readarr_data::{ActiveReadarrBlock, HISTORY_BLOCKS};
use crate::ui::DrawUi;
use crate::ui::styles::{ManagarrStyle, secondary_style};
use crate::ui::utils::{get_width_from_percentage, layout_block_top_border};
use crate::ui::widgets::managarr_table::ManagarrTable;
use crate::ui::widgets::message::Message;
use crate::ui::widgets::popup::{Popup, Size};
use ratatui::Frame;
use ratatui::layout::{Alignment, Rect};
use ratatui::prelude::Constraint;
use ratatui::text::Text;
use ratatui::widgets::{Cell, Row};
#[cfg(test)]
#[path = "history_ui_tests.rs"]
mod history_ui_tests;
pub(super) struct HistoryUi;
impl DrawUi for HistoryUi {
fn accepts(route: Route) -> bool {
if let Route::Readarr(active_readarr_block, _) = route {
return HISTORY_BLOCKS.contains(&active_readarr_block);
}
false
}
fn draw(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
if let Route::Readarr(active_readarr_block, _) = app.get_current_route() {
draw_history_table(f, app, area);
if active_readarr_block == ActiveReadarrBlock::HistoryItemDetails {
draw_history_item_details_popup(f, app);
}
}
}
}
fn draw_history_table(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
let current_selection = if app.data.readarr_data.history.items.is_empty() {
ReadarrHistoryItem::default()
} else {
app.data.readarr_data.history.current_selection().clone()
};
if let Route::Readarr(active_readarr_block, _) = app.get_current_route() {
let history_row_mapping = |history_item: &ReadarrHistoryItem| {
let ReadarrHistoryItem {
source_title,
quality,
event_type,
date,
..
} = history_item;
source_title.scroll_left_or_reset(
get_width_from_percentage(area, 50),
current_selection == *history_item,
app.should_text_scroll,
);
Row::new(vec![
Cell::from(source_title.to_string()),
Cell::from(event_type.to_string()),
Cell::from(quality.quality.name.to_owned()),
Cell::from(date.to_string()),
])
.primary()
};
let history_table = ManagarrTable::new(
Some(&mut app.data.readarr_data.history),
history_row_mapping,
)
.block(layout_block_top_border())
.loading(app.is_loading)
.sorting(active_readarr_block == ActiveReadarrBlock::HistorySortPrompt)
.searching(active_readarr_block == ActiveReadarrBlock::SearchHistory)
.search_produced_empty_results(active_readarr_block == ActiveReadarrBlock::SearchHistoryError)
.filtering(active_readarr_block == ActiveReadarrBlock::FilterHistory)
.filter_produced_empty_results(active_readarr_block == ActiveReadarrBlock::FilterHistoryError)
.headers(["Source Title", "Event Type", "Quality", "Date"])
.constraints([
Constraint::Percentage(50),
Constraint::Percentage(18),
Constraint::Percentage(12),
Constraint::Percentage(20),
]);
if [
ActiveReadarrBlock::SearchHistory,
ActiveReadarrBlock::FilterHistory,
]
.contains(&active_readarr_block)
{
history_table.show_cursor(f, area);
}
f.render_widget(history_table, area);
}
}
fn draw_history_item_details_popup(f: &mut Frame<'_>, app: &mut App<'_>) {
let current_selection = if app.data.readarr_data.history.items.is_empty() {
ReadarrHistoryItem::default()
} else {
app.data.readarr_data.history.current_selection().clone()
};
let line_vec = create_history_event_details(current_selection);
let text = Text::from(line_vec);
let message = Message::new(text)
.title("Details")
.style(secondary_style())
.alignment(Alignment::Left);
f.render_widget(Popup::new(message).size(Size::NarrowLongMessage), f.area());
}
@@ -0,0 +1,5 @@
---
source: src/ui/readarr_ui/history/history_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
@@ -0,0 +1,38 @@
---
source: src/ui/readarr_ui/history/history_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
╭─────────────────────────────────── Details ───────────────────────────────────╮
│Source Title: │
│Event Type: unknown │
│Quality: │
│Date: 1970-01-01 00:00:00 UTC │
│No additional details available. │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
╰─────────────────────────────────────────────────────────────────────────────────╯
@@ -0,0 +1,8 @@
---
source: src/ui/readarr_ui/history/history_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Source Title Event Type Quality Date
First Source Title grabbed EPUB 2023-05-20 21:29:16 UTC
=> Second Source Title downloadFailed MOBI 2024-08-14 09:03:47 UTC
@@ -0,0 +1,38 @@
---
source: src/ui/readarr_ui/history/history_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Source Title Event Type Quality Date
First Source Title grabbed EPUB 2023-05-20 21:29:16 UTC
=> Second Source Title downloadFailed MOBI 2024-08-14 09:03:47 UTC
╭─────────────────────────────────── Details ───────────────────────────────────╮
│Source Title: Second Source Title │
│Event Type: downloadFailed │
│Quality: MOBI │
│Date: 2024-08-14 09:03:47 UTC │
│Download Client: sabnzbd │
│Message: The download client reported a failure │
│Release Group: SecondReleaseGroup │
│Indexer: Nyaa │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
╰─────────────────────────────────────────────────────────────────────────────────╯
@@ -0,0 +1,28 @@
---
source: src/ui/readarr_ui/history/history_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Source Title ▼ Event Type Quality Date
=> Test Source Title grabbed EPUB 2023-05-20 21:29:16 UTC
╭───────────────── Filter ──────────────────╮
│test filter │
╰─────────────────────────────────────────────╯
@@ -0,0 +1,31 @@
---
source: src/ui/readarr_ui/history/history_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Source Title ▼ Event Type Quality Date
=> Test Source Title grabbed EPUB 2023-05-20 21:29:16 UTC
╭─────────────── Error ───────────────╮
│The given filter produced empty results│
│ │
╰───────────────────────────────────────╯
@@ -0,0 +1,7 @@
---
source: src/ui/readarr_ui/history/history_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Source Title ▼ Event Type Quality Date
=> Test Source Title grabbed EPUB 2023-05-20 21:29:16 UTC
@@ -0,0 +1,38 @@
---
source: src/ui/readarr_ui/history/history_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Source Title ▼ Event Type Quality Date
=> Test Source Title grabbed EPUB 2023-05-20 21:29:16 UTC
╭─────────────────────────────────── Details ───────────────────────────────────╮
│Source Title: Test Source Title │
│Event Type: grabbed │
│Quality: EPUB │
│Date: 2023-05-20 21:29:16 UTC │
│Indexer: │
│NZB Info URL: │
│Release Group: │
│Age: 0 days │
│Published Date: 1970-01-01 00:00:00 UTC │
│Download Client: │
│ │
│ │
│ │
│ │
│ │
│ │
╰─────────────────────────────────────────────────────────────────────────────────╯
@@ -0,0 +1,42 @@
---
source: src/ui/readarr_ui/history/history_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Source Title Event Type Quality Date
=> Test Source Title grabbed EPUB 2023-05-20 21:29:16 UTC
╭───────────────────────────────╮
│Date │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
╰───────────────────────────────╯
@@ -0,0 +1,28 @@
---
source: src/ui/readarr_ui/history/history_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Source Title ▼ Event Type Quality Date
=> Test Source Title grabbed EPUB 2023-05-20 21:29:16 UTC
╭───────────────── Search ──────────────────╮
│test search │
╰─────────────────────────────────────────────╯
@@ -0,0 +1,31 @@
---
source: src/ui/readarr_ui/history/history_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Source Title ▼ Event Type Quality Date
=> Test Source Title grabbed EPUB 2023-05-20 21:29:16 UTC
╭─────────────── Error ───────────────╮
│ No items found matching search │
│ │
╰───────────────────────────────────────╯
@@ -0,0 +1,8 @@
---
source: src/ui/readarr_ui/history/history_ui_tests.rs
expression: output
---
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Loading ...
+3
View File
@@ -3,6 +3,7 @@ use crate::ui::ui_test_utils::test_utils::Utc;
use chrono::Duration; use chrono::Duration;
#[cfg(not(test))] #[cfg(not(test))]
use chrono::Utc; use chrono::Utc;
use history::HistoryUi;
use library::LibraryUi; use library::LibraryUi;
use ratatui::{ use ratatui::{
Frame, Frame,
@@ -38,6 +39,7 @@ use crate::{
mod blocklist; mod blocklist;
mod downloads; mod downloads;
mod history;
mod library; mod library;
mod readarr_ui_utils; mod readarr_ui_utils;
@@ -60,6 +62,7 @@ impl DrawUi for ReadarrUi {
_ if LibraryUi::accepts(route) => LibraryUi::draw(f, app, content_area), _ if LibraryUi::accepts(route) => LibraryUi::draw(f, app, content_area),
_ if DownloadsUi::accepts(route) => DownloadsUi::draw(f, app, content_area), _ if DownloadsUi::accepts(route) => DownloadsUi::draw(f, app, content_area),
_ if BlocklistUi::accepts(route) => BlocklistUi::draw(f, app, content_area), _ if BlocklistUi::accepts(route) => BlocklistUi::draw(f, app, content_area),
_ if HistoryUi::accepts(route) => HistoryUi::draw(f, app, content_area),
_ => (), _ => (),
} }
} }
@@ -4,9 +4,9 @@ expression: output
--- ---
╭ Authors ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ ╭ Authors ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Library │ Downloads │ Blocklist │ History │ Root Folders │ Indexers │ System │ │ Library │ Downloads │ Blocklist │ History │ Root Folders │ Indexers │ System │
│ │ │───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
│ │ │ Source Title ▼ Event Type Quality Date │
│ │ │=> Test Source Title grabbed EPUB 2023-05-20 21:29:16 UTC │
│ │ │ │
│ │ │ │
│ │ │ │