canvas properly updating table name
This commit is contained in:
@@ -12,25 +12,34 @@ pub fn handle_add_column_action(
|
||||
add_table_state: &mut AddTableState,
|
||||
command_message: &mut String,
|
||||
) -> Option<AddTableFocus> {
|
||||
// Trim and create owned Strings immediately to avoid borrow issues later
|
||||
let name = add_table_state.column_name_input.trim().to_string();
|
||||
let data_type = add_table_state.column_type_input.trim().to_string();
|
||||
|
||||
if name.is_empty() || data_type.is_empty() {
|
||||
// Trim and create owned Strings from inputs
|
||||
let table_name_val = add_table_state.table_name_input.trim().to_string();
|
||||
let column_name_val = add_table_state.column_name_input.trim().to_string();
|
||||
let column_type_val = add_table_state.column_type_input.trim().to_string();
|
||||
|
||||
// Validate all inputs needed for this combined action
|
||||
if table_name_val.is_empty() {
|
||||
*command_message = "Table Name cannot be empty.".to_string();
|
||||
None
|
||||
} else if column_name_val.is_empty() || column_type_val.is_empty() {
|
||||
*command_message = "Column Name and Type cannot be empty.".to_string();
|
||||
None // Indicate failure, no focus change desired from here
|
||||
} else {
|
||||
add_table_state.table_name = table_name_val.clone();
|
||||
let new_column = ColumnDefinition {
|
||||
name: name.clone(), // Clone the owned string for the message
|
||||
data_type, // Move the owned string
|
||||
name: column_name_val.clone(),
|
||||
data_type: column_type_val,
|
||||
};
|
||||
add_table_state.columns.push(new_column);
|
||||
add_table_state.table_name_input.clear();
|
||||
add_table_state.column_name_input.clear();
|
||||
add_table_state.column_type_input.clear();
|
||||
add_table_state.table_name_cursor_pos = 0;
|
||||
add_table_state.column_name_cursor_pos = 0;
|
||||
add_table_state.column_type_cursor_pos = 0;
|
||||
add_table_state.has_unsaved_changes = true;
|
||||
*command_message = format!("Column '{}' added.", name);
|
||||
*command_message = format!("Table name set to '{}'. Column '{}' added.", table_name_val, column_name_val);
|
||||
// Indicate success and suggest moving focus back to the name input
|
||||
Some(AddTableFocus::InputColumnName)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user