Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I20f205d9e06a93a89e8f4433ed6f80576a6a6964
65 lines
1.7 KiB
Rust
65 lines
1.7 KiB
Rust
use ratatui::{
|
|
Frame,
|
|
layout::Rect,
|
|
style::{Color, Modifier, Style},
|
|
widgets::{Block, Borders, Row, Table},
|
|
};
|
|
|
|
use super::format_date;
|
|
use crate::app::AppState;
|
|
|
|
pub fn render(f: &mut Frame, state: &AppState, area: Rect) {
|
|
let header =
|
|
Row::new(vec!["Name", "Kind", "Description", "Members", "Created"]).style(
|
|
Style::default()
|
|
.fg(Color::Yellow)
|
|
.add_modifier(Modifier::BOLD),
|
|
);
|
|
|
|
let rows: Vec<Row> = state
|
|
.collections
|
|
.iter()
|
|
.enumerate()
|
|
.map(|(i, col)| {
|
|
let style = if Some(i) == state.collection_selected {
|
|
Style::default().fg(Color::Black).bg(Color::Cyan)
|
|
} else {
|
|
Style::default()
|
|
};
|
|
|
|
// We show the filter_query as a proxy for member info when kind is
|
|
// "smart"
|
|
let members_display = if col.kind == "smart" {
|
|
col
|
|
.filter_query
|
|
.as_deref()
|
|
.map_or_else(|| "-".to_string(), |q| format!("filter: {q}"))
|
|
} else {
|
|
"-".to_string()
|
|
};
|
|
|
|
Row::new(vec![
|
|
col.name.clone(),
|
|
col.kind.clone(),
|
|
col.description.clone().unwrap_or_else(|| "-".into()),
|
|
members_display,
|
|
format_date(&col.created_at).to_string(),
|
|
])
|
|
.style(style)
|
|
})
|
|
.collect();
|
|
|
|
let title = format!(" Collections ({}) ", state.collections.len());
|
|
|
|
let table = Table::new(rows, [
|
|
ratatui::layout::Constraint::Percentage(25),
|
|
ratatui::layout::Constraint::Percentage(12),
|
|
ratatui::layout::Constraint::Percentage(28),
|
|
ratatui::layout::Constraint::Percentage(15),
|
|
ratatui::layout::Constraint::Percentage(20),
|
|
])
|
|
.header(header)
|
|
.block(Block::default().borders(Borders::ALL).title(title));
|
|
|
|
f.render_widget(table, area);
|
|
}
|