deletion of the selected works

This commit is contained in:
filipriec
2025-04-18 11:15:15 +02:00
parent 92a9011f27
commit 305bcfcf62
4 changed files with 44 additions and 9 deletions

View File

@@ -36,6 +36,7 @@ pub fn handle_add_column_action(
let new_column = ColumnDefinition {
name: column_name_in.to_string(),
data_type: column_type_in.to_string(),
selected: false,
};
add_table_state.columns.push(new_column.clone()); // Clone for msg
msg.push_str(&format!("Column '{}' added.", new_column.name));
@@ -73,3 +74,28 @@ pub fn handle_add_column_action(
}
}
}
/// Handles deleting columns marked as selected in the AddTableState.
pub fn handle_delete_selected_columns(
add_table_state: &mut AddTableState,
command_message: &mut String,
) {
let initial_count = add_table_state.columns.len();
// Keep only the columns that are NOT selected
add_table_state.columns.retain(|col| !col.selected);
let deleted_count = initial_count - add_table_state.columns.len();
if deleted_count > 0 {
*command_message = format!("Deleted {} selected column(s).", deleted_count);
add_table_state.has_unsaved_changes = true;
// Reset selection highlight as indices have changed
add_table_state.column_table_state.select(None);
// Optionally, select the first item if the list is not empty
// if !add_table_state.columns.is_empty() {
// add_table_state.column_table_state.select(Some(0));
// }
} else {
*command_message = "No columns marked for deletion.".to_string();
}
}