diff --git a/client/src/components/admin/add_table.rs b/client/src/components/admin/add_table.rs index fca4add..8753e40 100644 --- a/client/src/components/admin/add_table.rs +++ b/client/src/components/admin/add_table.rs @@ -13,6 +13,7 @@ use ratatui::{ Frame, }; use crate::components::handlers::canvas::render_canvas; +use crate::components::common::dialog; /// Renders the Add New Table page layout, structuring the display of table information, /// input fields, and action buttons. Adapts layout based on terminal width. @@ -482,4 +483,18 @@ pub fn render_add_table( )), ); f.render_widget(cancel_button, bottom_button_chunks[2]); + + // --- DIALOG --- + // Render the dialog overlay if it's active + if _app_state.ui.dialog.dialog_show { // Use the passed-in app_state + dialog::render_dialog( + f, + f.area(), // Render over the whole frame area + theme, + &_app_state.ui.dialog.dialog_title, + &_app_state.ui.dialog.dialog_message, + &_app_state.ui.dialog.dialog_buttons, + _app_state.ui.dialog.dialog_active_button_index, + ); + } } diff --git a/client/src/functions/modes/navigation/add_table_nav.rs b/client/src/functions/modes/navigation/add_table_nav.rs index e966d26..752f968 100644 --- a/client/src/functions/modes/navigation/add_table_nav.rs +++ b/client/src/functions/modes/navigation/add_table_nav.rs @@ -7,7 +7,7 @@ use crate::state::{ use crossterm::event::{KeyEvent}; use ratatui::widgets::TableState; use crate::tui::functions::common::add_table::handle_add_column_action; -use crate::tui::functions::common::add_table::handle_delete_selected_columns; +use crate::ui::handlers::context::DialogPurpose; /// Handles navigation events specifically for the Add Table view. /// Returns true if the event was handled, false otherwise. @@ -255,7 +255,21 @@ pub fn handle_add_table_navigation( // TODO: Implement logic } AddTableFocus::DeleteSelectedButton => { - handle_delete_selected_columns(add_table_state, command_message); + // --- Show Confirmation Dialog --- + let columns_to_delete: Vec = add_table_state + .columns + .iter() + .filter(|col| col.selected) + .map(|col| col.name.clone()) + .collect(); + + if columns_to_delete.is_empty() { + *command_message = "No columns selected for deletion.".to_string(); + } else { + let message = format!("Delete the following columns?\n\n{}", columns_to_delete.join("\n")); + let buttons = vec!["Confirm".to_string(), "Cancel".to_string()]; + app_state.show_dialog("Confirm Deletion", &message, buttons, DialogPurpose::ConfirmDeleteColumns); + } } AddTableFocus::CancelButton => { *command_message = "Action: Cancel Add Table".to_string(); diff --git a/client/src/modes/general/dialog.rs b/client/src/modes/general/dialog.rs index b286bbd..1cd47a6 100644 --- a/client/src/modes/general/dialog.rs +++ b/client/src/modes/general/dialog.rs @@ -6,10 +6,11 @@ use crate::ui::handlers::context::DialogPurpose; use crate::state::app::state::AppState; use crate::state::app::buffer::BufferState; use crate::state::pages::auth::AuthState; -use crate::state::pages::auth::LoginState; -use crate::state::pages::auth::RegisterState; +use crate::state::pages::auth::{LoginState, RegisterState}; +use crate::state::pages::admin::AdminState; use crate::modes::handlers::event::EventOutcome; use crate::tui::functions::common::{login, register}; +use crate::tui::functions::common::add_table::handle_delete_selected_columns; /// Handles key events specifically when a dialog is active. /// Returns Some(Result) if the event was handled (consumed), @@ -22,6 +23,7 @@ pub async fn handle_dialog_event( login_state: &mut LoginState, register_state: &mut RegisterState, buffer_state: &mut BufferState, + admin_state: &mut AdminState, ) -> Option>> { if let Event::Key(key) = event { // Always allow Esc to dismiss @@ -114,6 +116,20 @@ pub async fn handle_dialog_event( } } } + DialogPurpose::ConfirmDeleteColumns => { + match selected_index { + 0 => { // "Confirm" button selected + let outcome_message = handle_delete_selected_columns(&mut admin_state.add_table_state); + app_state.hide_dialog(); + return Some(Ok(EventOutcome::Ok(outcome_message))); + } + 1 => { // "Cancel" button selected + app_state.hide_dialog(); + return Some(Ok(EventOutcome::Ok("Deletion cancelled.".to_string()))); + } + _ => { /* Handle unexpected index */ } + } + } } } _ => {} // Ignore other general actions when dialog is shown diff --git a/client/src/modes/handlers/event.rs b/client/src/modes/handlers/event.rs index 88d0fe8..ec368e1 100644 --- a/client/src/modes/handlers/event.rs +++ b/client/src/modes/handlers/event.rs @@ -116,7 +116,14 @@ impl EventHandler { if app_state.ui.dialog.dialog_show { if let Some(dialog_result) = dialog::handle_dialog_event( - &event, config, app_state, auth_state, login_state, register_state, buffer_state + &event, + config, + app_state, + auth_state, + login_state, + register_state, + buffer_state, + admin_state, ).await { return dialog_result; } diff --git a/client/src/tui/functions/common/add_table.rs b/client/src/tui/functions/common/add_table.rs index 0b38e05..9e6bbfa 100644 --- a/client/src/tui/functions/common/add_table.rs +++ b/client/src/tui/functions/common/add_table.rs @@ -78,15 +78,13 @@ 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, -) { +) -> 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); @@ -94,8 +92,9 @@ pub fn handle_delete_selected_columns( // if !add_table_state.columns.is_empty() { // add_table_state.column_table_state.select(Some(0)); // } + format!("Deleted {} selected column(s).", deleted_count) } else { - *command_message = "No columns marked for deletion.".to_string(); + "No columns marked for deletion.".to_string() } } diff --git a/client/src/ui/handlers/context.rs b/client/src/ui/handlers/context.rs index 3328d61..02ee602 100644 --- a/client/src/ui/handlers/context.rs +++ b/client/src/ui/handlers/context.rs @@ -15,6 +15,7 @@ pub enum DialogPurpose { LoginFailed, RegisterSuccess, RegisterFailed, + ConfirmDeleteColumns, // add_table delete selected Columns // TODO in the future: // ConfirmQuit, }