working selection in the admin panel for the admin perfectly well

This commit is contained in:
filipriec
2025-04-16 19:15:05 +02:00
parent 8ea9965ee3
commit 05d9e6e46b
3 changed files with 23 additions and 9 deletions

View File

@@ -116,11 +116,11 @@ pub fn render_admin_panel_admin(
.tables
.iter()
.enumerate()
.map(|(i, table)| {
let is_selected = admin_state.table_list_state.selected() == Some(i);
let prefix = if is_selected { "[*] " } else { "[ ] " }; // Use [*] for selected
.map(|(idx, table)| {
let is_navigated = admin_state.table_list_state.selected() == Some(idx);
let prefix = if admin_state.is_table_selected(idx) { "[*] " } else { "[ ] " };
// Don't show dependencies inline anymore
let style = if is_selected {
let style = if is_navigated {
Style::default().fg(theme.highlight).add_modifier(ratatui::style::Modifier::BOLD)
} else {
Style::default().fg(theme.fg)

View File

@@ -99,10 +99,9 @@ pub fn handle_admin_navigation(
}
}
AdminFocus::Tables => {
// Currently, selecting a table just confirms the highlight.
// Future: Could be used for multi-select toggle or other actions.
if let Some(idx) = admin_state.table_list_state.selected() {
*command_message = format!("Table {} highlighted", idx);
if let Some(idx) = admin_state.get_selected_table_index() {
admin_state.toggle_table_selection(idx);
*command_message = format!("Toggled selection for table index {}", idx);
} else {
*command_message = "No table highlighted".to_string();
}

View File

@@ -1,6 +1,7 @@
// src/state/pages/admin.rs
use ratatui::widgets::ListState;
use std::collections::HashSet;
// Define the focus states for the admin panel panes
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
@@ -14,7 +15,8 @@ pub enum AdminFocus {
pub struct AdminState {
pub profiles: Vec<String>,
pub profile_list_state: ListState, // State for the profiles list
pub table_list_state: ListState, // State for the tables list
pub table_list_state: ListState, // State for the tables list navigation/highlight
pub selected_table_indices: HashSet<usize>, // Indices of tables marked with [*]
pub current_focus: AdminFocus, // Tracks which pane is focused
}
@@ -85,6 +87,7 @@ impl AdminState {
pub fn select_profile(&mut self, index: Option<usize>) {
self.profile_list_state.select(index);
self.table_list_state.select(None); // Reset table selection
self.selected_table_indices.clear();
}
/// Selects a table by index.
@@ -175,5 +178,17 @@ impl AdminState {
AdminFocus::Tables => AdminFocus::Profiles,
};
}
/// Toggles the selection state of the table at the given index.
pub fn toggle_table_selection(&mut self, index: usize) {
if !self.selected_table_indices.remove(&index) {
// If remove returned false, it wasn't present, so insert it.
self.selected_table_indices.insert(index);
}
}
pub fn is_table_selected(&self, index: usize) -> bool {
self.selected_table_indices.contains(&index)
}
}