admin panel bombarded like never before

This commit is contained in:
filipriec
2025-04-16 12:47:33 +02:00
parent 26b899df16
commit 055b6a0a43
6 changed files with 264 additions and 17 deletions

View File

@@ -98,8 +98,8 @@ fn render_admin_panel_non_admin(
.block(Block::default().title("Profiles"))
.highlight_style(Style::default().bg(theme.highlight).fg(theme.bg));
let mut list_state_clone = admin_state.list_state.clone();
f.render_stateful_widget(list, content_chunks[0], &mut list_state_clone);
let mut profile_list_state_clone = admin_state.profile_list_state.clone();
f.render_stateful_widget(list, content_chunks[0], &mut profile_list_state_clone);
// Profile details - Use selection info from admin_state
if let Some(profile) = admin_state

View File

@@ -0,0 +1,127 @@
// src/components/admin/admin_panel_admin.rs
// Add necessary imports that were previously in admin_panel.rs
// and are used by this function
use crate::config::colors::themes::Theme;
use crate::state::pages::admin::{AdminFocus, AdminState};
use crate::state::app::state::AppState;
use ratatui::{
layout::{Alignment, Rect},
style::{Style, Stylize},
text::{Line, Span},
widgets::{Block, BorderType, Borders, List, ListItem, Paragraph},
Frame,
};
/// Renders the view specific to admin users.
/// Implements the two-pane layout for profile and table browsing.
// Make it public (`pub`) if called from outside this module,
// or keep it private (no `pub`) if only called from admin_panel.rs
// For now, let's assume it's only called from admin_panel.rs
pub(super) fn render_admin_panel_admin( // Use pub(super) or pub based on need
f: &mut Frame,
admin_state: &mut AdminState,
app_state: &AppState,
content_chunks: &[Rect],
theme: &Theme,
) {
let profile_tree = &app_state.profile_tree;
let selected_profile_index = admin_state.get_selected_profile_index();
// --- Profile List (Left Pane) ---
let profile_items: Vec<ListItem> = profile_tree
.profiles
.iter()
.enumerate()
.map(|(i, p)| {
let is_selected = selected_profile_index == Some(i);
let style = if is_selected && admin_state.current_focus == AdminFocus::Profiles {
Style::default().fg(theme.bg).bg(theme.highlight)
} else if is_selected {
Style::default().fg(theme.fg).bg(theme.inactive_highlight_bg)
} else {
Style::default().fg(theme.fg)
};
ListItem::new(Line::from(Span::styled(&p.name, style)))
})
.collect();
let profile_list_block = Block::default()
.title(" Profiles ")
.borders(Borders::ALL)
.border_type(BorderType::Plain)
.border_style(if admin_state.current_focus == AdminFocus::Profiles {
Style::default().fg(theme.accent)
} else {
Style::default().fg(theme.border)
});
let profile_list = List::new(profile_items).block(profile_list_block);
f.render_stateful_widget(
profile_list,
content_chunks[0],
&mut admin_state.profile_list_state,
);
// --- Table List & Details (Right Pane) ---
let table_list_block = Block::default()
.title(" Tables & Dependencies ")
.borders(Borders::ALL)
.border_type(BorderType::Plain)
.border_style(if admin_state.current_focus == AdminFocus::Tables {
Style::default().fg(theme.accent)
} else {
Style::default().fg(theme.border)
});
if let Some(profile_idx) = selected_profile_index {
if let Some(profile) = profile_tree.profiles.get(profile_idx) {
let selected_table_index = admin_state.get_selected_table_index();
let table_items: Vec<ListItem> = profile
.tables
.iter()
.enumerate()
.map(|(i, table)| {
let is_selected = selected_table_index == Some(i);
let base_style = if is_selected && admin_state.current_focus == AdminFocus::Tables {
Style::default().fg(theme.bg).bg(theme.highlight)
} else if is_selected {
Style::default().fg(theme.fg).bg(theme.inactive_highlight_bg)
} else {
Style::default().fg(theme.fg)
};
let mut line_spans = vec![Span::styled(&table.name, base_style)];
if !table.depends_on.is_empty() {
line_spans.push(Span::styled(" -> ", base_style.fg(theme.secondary)));
line_spans.push(Span::styled(
format!("[{}]", table.depends_on.join(", ")),
base_style.fg(theme.secondary),
));
}
ListItem::new(Line::from(line_spans))
})
.collect();
let table_list = List::new(table_items);
f.render_stateful_widget(
table_list.block(table_list_block),
content_chunks[1],
&mut admin_state.table_list_state,
);
return;
}
}
let placeholder = Paragraph::new("Select a profile to see tables.")
.style(Style::default().fg(theme.secondary))
.alignment(Alignment::Center);
f.render_widget(
placeholder.block(table_list_block),
content_chunks[1],
);
}