Lines
98.41 %
Functions
50 %
Branches
100 %
//! Filtering the Transactions tab from the palette and from the Accounts tab.
use cli_core::forms::Fetched;
use forms::{FormValues, Source, TRANSACTION_QUERY};
use super::App;
use super::lookup::Goal;
use super::pending::rejection;
use crate::form::Form;
use crate::tabs::list::ListTab;
use crate::tabs::paging::filter_summary;
use crate::view::Tab;
use crate::window::WindowId;
impl App {
/// Filter the Transactions tab by `filter`, whose `account` may be a label.
pub fn filter_transactions(&mut self, filter: FormValues) {
let window = self.window_or_open(Tab::Transactions).window;
self.start_lookup(Goal::Filter(window), &TRANSACTION_QUERY, filter);
}
/// Drop the Transactions filter and show the window.
pub fn show_all_transactions(&mut self) {
self.clear_transaction_filter(window);
self.activate_window(window);
/// Filter the Transactions tab by the account selected on the Accounts tab.
pub fn filter_transactions_of_selected_account(&mut self) {
let Some(id) = self.selected_id(Tab::Accounts) else {
self.set_status("no account selected");
return;
};
let mut filter = FormValues::default();
filter.set("account", &id);
self.filter_transactions(filter);
pub(super) fn next_filter_seq(&mut self, window: WindowId) -> Option<u64> {
self.win_mut::<ListTab>(window)
.map(|list| list.filter_seq.advance())
pub(super) fn apply_resolved_filter(
&mut self,
window: WindowId,
filter: &FormValues,
fetched: &Fetched,
) {
let label = filter
.text("account")
.and_then(|id| {
let (_, options) = fetched.iter().find(|(s, _)| *s == Source::Accounts)?;
options.iter().find(|option| option.id == id)
})
.map_or("", |option| option.label.as_str());
let summary = filter_summary(label, filter);
self.submit_transaction_filter(window, filter, summary);
/// Adopt the filter of an answered query, or report the server's refusal
/// and keep the old one; a reply of a superseded request is dropped.
pub(super) fn deliver_filter_reply(
seq: u64,
summary: String,
wire: &str,
let awaited = self
.win::<ListTab>(window)
.is_some_and(|list| list.filter_seq.awaits(seq));
if !awaited {
if let Err(e) = cli_core::render::parse_wire(wire) {
let mut form = Form::transaction_filter(filter);
form.show_errors(&rejection(&e));
self.set_status(format!("filter failed: {}", form.errors.join("; ")));
if let Some(list) = self.win_mut::<ListTab>(window) {
list.set_filter(filter, summary);
self.deliver_transactions_reply(window, wire);
self.show_window_if_free(window);