indexing now works amazingly well

This commit is contained in:
filipriec
2025-04-22 16:03:16 +02:00
parent b01ba0b2d9
commit ec596b2ada
4 changed files with 77 additions and 7 deletions

View File

@@ -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()