indexing now works amazingly well
This commit is contained in:
@@ -89,6 +89,42 @@ pub fn render_add_table(
|
||||
return; // IMPORTANT: Stop rendering here for fullscreen mode
|
||||
}
|
||||
|
||||
// --- Fullscreen Indexes Table Check (Narrow Screens Only) ---
|
||||
if area.width < NARROW_LAYOUT_THRESHOLD && add_table_state.current_focus == AddTableFocus::InsideIndexesTable {
|
||||
// Render ONLY the indexes table taking the full inner area
|
||||
let indexes_border_style = Style::default().fg(theme.highlight); // Always highlighted when fullscreen
|
||||
let index_rows: Vec<Row<'_>> = add_table_state
|
||||
.indexes
|
||||
.iter()
|
||||
.map(|index_def| {
|
||||
Row::new(vec![
|
||||
Cell::from(if index_def.selected { "[*]" } else { "[ ]" }),
|
||||
Cell::from(index_def.name.clone()),
|
||||
])
|
||||
.style(Style::default().fg(theme.fg))
|
||||
})
|
||||
.collect();
|
||||
let index_header_cells = ["Sel", "Column Name"]
|
||||
.iter()
|
||||
.map(|h| Cell::from(*h).style(Style::default().fg(theme.accent)));
|
||||
let index_header = Row::new(index_header_cells).height(1).bottom_margin(1);
|
||||
let indexes_table = Table::new(index_rows, [Constraint::Length(5), Constraint::Percentage(95)])
|
||||
.header(index_header)
|
||||
.block(
|
||||
Block::default()
|
||||
.title(Span::styled(" Indexes (Fullscreen) ", theme.fg)) // Indicate fullscreen
|
||||
.title_alignment(Alignment::Center)
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(indexes_border_style),
|
||||
)
|
||||
.row_highlight_style(Style::default().add_modifier(Modifier::REVERSED).fg(theme.highlight))
|
||||
.highlight_symbol(" > "); // Use the inside symbol
|
||||
f.render_stateful_widget(indexes_table, inner_area, &mut add_table_state.index_table_state);
|
||||
return; // IMPORTANT: Stop rendering here for fullscreen mode
|
||||
}
|
||||
|
||||
|
||||
// --- Area Variable Declarations ---
|
||||
let top_info_area: Rect;
|
||||
let columns_area: Rect;
|
||||
@@ -343,17 +379,20 @@ pub fn render_add_table(
|
||||
let index_rows: Vec<Row<'_>> = add_table_state
|
||||
.indexes
|
||||
.iter()
|
||||
.map(|index_name| {
|
||||
Row::new(vec![Cell::from(index_name.clone())])
|
||||
.map(|index_def| { // Use index_def now
|
||||
Row::new(vec![
|
||||
Cell::from(if index_def.selected { "[*]" } else { "[ ]" }), // Display selection
|
||||
Cell::from(index_def.name.clone()),
|
||||
])
|
||||
.style(Style::default().fg(theme.fg))
|
||||
})
|
||||
.collect();
|
||||
let index_header_cells = ["Column Name"]
|
||||
let index_header_cells = ["Sel", "Column Name"]
|
||||
.iter()
|
||||
.map(|h| Cell::from(*h).style(Style::default().fg(theme.accent)));
|
||||
let index_header = Row::new(index_header_cells).height(1).bottom_margin(1);
|
||||
let indexes_table =
|
||||
Table::new(index_rows, [Constraint::Percentage(100)])
|
||||
Table::new(index_rows, [Constraint::Length(5), Constraint::Percentage(95)])
|
||||
.header(index_header)
|
||||
.block(
|
||||
Block::default()
|
||||
|
||||
@@ -203,7 +203,16 @@ pub fn handle_add_table_navigation(
|
||||
AddTableFocus::InsideIndexesTable => {
|
||||
// Select does nothing here anymore, only Esc exits.
|
||||
if let Some(index) = add_table_state.index_table_state.selected() {
|
||||
*command_message = format!("Selected index index {} (Press Esc to exit scroll mode)", index);
|
||||
if let Some(idx_def) = add_table_state.indexes.get_mut(index) {
|
||||
idx_def.selected = !idx_def.selected;
|
||||
add_table_state.has_unsaved_changes = true;
|
||||
*command_message = format!(
|
||||
"Toggled selection for index: {} to {}",
|
||||
idx_def.name, idx_def.selected
|
||||
);
|
||||
} else {
|
||||
*command_message = "Error: Selected index out of bounds".to_string();
|
||||
}
|
||||
} else {
|
||||
*command_message = "No index selected (Press Esc to exit scroll mode)".to_string();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// src/state/pages/add_table.rs
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
use ratatui::widgets::TableState;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct ColumnDefinition {
|
||||
@@ -9,6 +10,12 @@ pub struct ColumnDefinition {
|
||||
pub selected: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct IndexDefinition {
|
||||
pub name: String,
|
||||
pub selected: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct LinkDefinition {
|
||||
pub linked_table_name: String,
|
||||
@@ -45,7 +52,7 @@ pub struct AddTableState {
|
||||
pub column_name_input: String,
|
||||
pub column_type_input: String,
|
||||
pub columns: Vec<ColumnDefinition>,
|
||||
pub indexes: Vec<String>,
|
||||
pub indexes: Vec<IndexDefinition>,
|
||||
pub links: Vec<LinkDefinition>,
|
||||
pub current_focus: AddTableFocus,
|
||||
pub column_table_state: TableState,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// src/tui/functions/common/add_table.rs
|
||||
use crate::state::pages::add_table::{
|
||||
AddTableFocus, AddTableState, ColumnDefinition,
|
||||
AddTableFocus, AddTableState, ColumnDefinition, IndexDefinition,
|
||||
};
|
||||
|
||||
/// Handles the logic for adding a column when the "Add" button is activated.
|
||||
@@ -40,6 +40,13 @@ pub fn handle_add_column_action(
|
||||
};
|
||||
add_table_state.columns.push(new_column.clone()); // Clone for msg
|
||||
msg.push_str(&format!("Column '{}' added.", new_column.name));
|
||||
|
||||
// Add corresponding index definition (initially unselected)
|
||||
let new_index = IndexDefinition {
|
||||
name: column_name_in.to_string(),
|
||||
selected: false,
|
||||
};
|
||||
add_table_state.indexes.push(new_index);
|
||||
*command_message = msg;
|
||||
|
||||
// Clear all inputs and reset cursors
|
||||
@@ -81,10 +88,17 @@ pub fn handle_delete_selected_columns(
|
||||
) -> String {
|
||||
let initial_count = add_table_state.columns.len();
|
||||
// Keep only the columns that are NOT selected
|
||||
let initial_selected_indices: std::collections::HashSet<String> = add_table_state
|
||||
.columns
|
||||
.iter()
|
||||
.filter(|col| col.selected)
|
||||
.map(|col| col.name.clone())
|
||||
.collect();
|
||||
add_table_state.columns.retain(|col| !col.selected);
|
||||
let deleted_count = initial_count - add_table_state.columns.len();
|
||||
|
||||
if deleted_count > 0 {
|
||||
add_table_state.indexes.retain(|index| !initial_selected_indices.contains(&index.name));
|
||||
add_table_state.has_unsaved_changes = true;
|
||||
// Reset selection highlight as indices have changed
|
||||
add_table_state.column_table_state.select(None);
|
||||
@@ -92,6 +106,7 @@ pub fn handle_delete_selected_columns(
|
||||
// if !add_table_state.columns.is_empty() {
|
||||
// add_table_state.column_table_state.select(Some(0));
|
||||
// }
|
||||
add_table_state.index_table_state.select(None);
|
||||
format!("Deleted {} selected column(s).", deleted_count)
|
||||
} else {
|
||||
"No columns marked for deletion.".to_string()
|
||||
|
||||
Reference in New Issue
Block a user