add 'All Lines' to match view

This commit is contained in:
Robin Appelman 2024-12-17 19:00:15 +01:00
commit 4d9719345f
5 changed files with 35 additions and 21 deletions

View file

@ -38,6 +38,7 @@ pub struct LogMatch {
pub lines: Vec<usize>,
pub histogram: TimeGraph,
pub sparkline: String,
pub all: GroupedLines,
pub grouped: Vec<GroupedLines>,
}
@ -51,6 +52,11 @@ impl LogMatch {
}
let grouped = group_lines(all_lines, lines.iter().copied());
let sparkline = histogram.sparkline::<10>();
let all = GroupedLines {
sparkline: sparkline.clone(),
histogram: histogram.clone(),
lines: lines.clone(),
};
LogMatch {
result,
@ -58,6 +64,7 @@ impl LogMatch {
histogram,
sparkline,
grouped,
all,
}
}

View file

@ -2,6 +2,7 @@ use hdrhistogram::Histogram;
use std::cmp::max;
use time::OffsetDateTime;
#[derive(Clone)]
pub struct TimeGraph {
histogram: Histogram<u64>,
start: u64,

View file

@ -10,7 +10,6 @@ use ratatui::text::Text;
use ratatui::widgets::{Cell, Paragraph, Row, Wrap};
pub struct GroupedLogs<'a> {
line: &'a LogLine<'a>,
lines: &'a [usize],
app: &'a App<'a>,
filter: &'a Filter,
@ -21,13 +20,7 @@ pub fn grouped_logs<'a>(
lines: &'a [usize],
filter: &'a Filter,
) -> GroupedLogs<'a> {
let line = &app.lines[lines[0]];
GroupedLogs {
line,
lines,
app,
filter,
}
GroupedLogs { lines, app, filter }
}
impl StatefulWidget for GroupedLogs<'_> {
@ -37,24 +30,25 @@ impl StatefulWidget for GroupedLogs<'_> {
where
Self: Sized,
{
let line = &self.app.lines[self.lines[state.selected()]];
let lines = self.lines.iter().copied().map(|i| &self.app.lines[i]);
let par = Paragraph::new(format!(
"{}{}{}\n\n{} from {} - Nextcloud {}",
self.line
line
.exception
.as_ref()
.map(|e| e.exception.as_ref())
.unwrap_or_default(),
if self.line.exception.is_some() {
if line.exception.is_some() {
":\n"
} else {
""
},
self.line.message,
self.line.level.as_str(),
self.line.app,
self.line.version,
line.message,
line.level.as_str(),
line.app,
line.version,
))
.wrap(Wrap::default());

View file

@ -4,6 +4,7 @@ use crate::ui::table::ScrollbarTable;
use ratatui::layout::Constraint;
use ratatui::text::Text;
use ratatui::widgets::{Cell, Row};
use std::iter::once;
pub fn grouped_lines<'a>(
app: &'a App<'a>,
@ -32,10 +33,19 @@ pub fn grouped_lines<'a>(
Constraint::Min(10),
];
ScrollbarTable::new(
once(Row::new([
Text::from("All lines"),
Text::from(""),
Text::from(""),
Text::from(log_match.sparkline.as_str()),
Text::from(log_match.lines.len().to_string()),
]))
.chain(
grouped
.iter()
.filter(|group| group.matches(app, filter))
.map(|group| group_row(app, group)),
),
widths,
)
.header(header)

View file

@ -88,14 +88,16 @@ impl<'a> MatchState<'a> {
let mut table_state = TableState::default();
table_state.select(Some(0));
let selected_line = if self.filter.is_empty() {
&self.result.grouped[selected]
let selected_line = if selected == 0 {
&self.result.all
} else if self.filter.is_empty() {
&self.result.grouped[selected - 1]
} else {
self.result
.grouped
.iter()
.filter(|grouped| grouped.matches(app, &self.filter))
.nth(selected)
.nth(selected - 1)
.expect("filtered select out of bounds")
};
let lines = selected_line.lines.as_slice();