working selection in the admin panel for the admin perfectly well
This commit is contained in:
@@ -116,11 +116,11 @@ pub fn render_admin_panel_admin(
|
|||||||
.tables
|
.tables
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, table)| {
|
.map(|(idx, table)| {
|
||||||
let is_selected = admin_state.table_list_state.selected() == Some(i);
|
let is_navigated = admin_state.table_list_state.selected() == Some(idx);
|
||||||
let prefix = if is_selected { "[*] " } else { "[ ] " }; // Use [*] for selected
|
let prefix = if admin_state.is_table_selected(idx) { "[*] " } else { "[ ] " };
|
||||||
// Don't show dependencies inline anymore
|
// 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)
|
Style::default().fg(theme.highlight).add_modifier(ratatui::style::Modifier::BOLD)
|
||||||
} else {
|
} else {
|
||||||
Style::default().fg(theme.fg)
|
Style::default().fg(theme.fg)
|
||||||
|
|||||||
@@ -99,10 +99,9 @@ pub fn handle_admin_navigation(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
AdminFocus::Tables => {
|
AdminFocus::Tables => {
|
||||||
// Currently, selecting a table just confirms the highlight.
|
if let Some(idx) = admin_state.get_selected_table_index() {
|
||||||
// Future: Could be used for multi-select toggle or other actions.
|
admin_state.toggle_table_selection(idx);
|
||||||
if let Some(idx) = admin_state.table_list_state.selected() {
|
*command_message = format!("Toggled selection for table index {}", idx);
|
||||||
*command_message = format!("Table {} highlighted", idx);
|
|
||||||
} else {
|
} else {
|
||||||
*command_message = "No table highlighted".to_string();
|
*command_message = "No table highlighted".to_string();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// src/state/pages/admin.rs
|
// src/state/pages/admin.rs
|
||||||
|
|
||||||
use ratatui::widgets::ListState;
|
use ratatui::widgets::ListState;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
// Define the focus states for the admin panel panes
|
// Define the focus states for the admin panel panes
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||||
@@ -14,7 +15,8 @@ pub enum AdminFocus {
|
|||||||
pub struct AdminState {
|
pub struct AdminState {
|
||||||
pub profiles: Vec<String>,
|
pub profiles: Vec<String>,
|
||||||
pub profile_list_state: ListState, // State for the profiles list
|
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
|
pub current_focus: AdminFocus, // Tracks which pane is focused
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,6 +87,7 @@ impl AdminState {
|
|||||||
pub fn select_profile(&mut self, index: Option<usize>) {
|
pub fn select_profile(&mut self, index: Option<usize>) {
|
||||||
self.profile_list_state.select(index);
|
self.profile_list_state.select(index);
|
||||||
self.table_list_state.select(None); // Reset table selection
|
self.table_list_state.select(None); // Reset table selection
|
||||||
|
self.selected_table_indices.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Selects a table by index.
|
/// Selects a table by index.
|
||||||
@@ -175,5 +178,17 @@ impl AdminState {
|
|||||||
AdminFocus::Tables => AdminFocus::Profiles,
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user