From 75af0c3be11b5c89482bc0651197c8bc90a49170 Mon Sep 17 00:00:00 2001 From: filipriec Date: Thu, 17 Apr 2025 21:59:19 +0200 Subject: [PATCH] the profile name is now passed from admin panel to the add table page --- client/src/components/admin/add_table.rs | 8 ++--- .../functions/modes/navigation/admin_nav.rs | 35 +++++++++++++++++-- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/client/src/components/admin/add_table.rs b/client/src/components/admin/add_table.rs index 94d00a4..b0997fc 100644 --- a/client/src/components/admin/add_table.rs +++ b/client/src/components/admin/add_table.rs @@ -113,11 +113,11 @@ pub fn render_add_table( // --- Top Info Rendering (Wide - 2 lines) --- let profile_text = Paragraph::new(vec![ Line::from(Span::styled( - format!("profile: {}", add_table_state.profile_name), + format!("Profile: {}", add_table_state.profile_name), theme.fg, )), Line::from(Span::styled( - format!("table name: {}", add_table_state.table_name), + format!("Table name: {}", add_table_state.table_name), theme.fg, )), ]) @@ -169,14 +169,14 @@ pub fn render_add_table( .split(top_info_area); let profile_text = Paragraph::new(Span::styled( - format!("profile: {}", add_table_state.profile_name), + format!("Profile: {}", add_table_state.profile_name), theme.fg, )) .alignment(Alignment::Left); f.render_widget(profile_text, top_info_chunks[0]); let table_name_text = Paragraph::new(Span::styled( - format!("table: {}", add_table_state.table_name), + format!("Table: {}", add_table_state.table_name), theme.fg, )) .alignment(Alignment::Left); diff --git a/client/src/functions/modes/navigation/admin_nav.rs b/client/src/functions/modes/navigation/admin_nav.rs index 0c5e104..dbfd4e3 100644 --- a/client/src/functions/modes/navigation/admin_nav.rs +++ b/client/src/functions/modes/navigation/admin_nav.rs @@ -8,6 +8,7 @@ use crate::state::{ use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; use crate::state::app::buffer::AppView; use crate::state::app::buffer::BufferState; +use crate::state::pages::add_table::AddTableState; /// Handles navigation events specifically for the Admin Panel view. /// Returns true if the event was handled, false otherwise. @@ -160,9 +161,37 @@ pub fn handle_admin_navigation( // TODO: Trigger action for Button 1 } AdminFocus::Button2 => { - buffer_state.update_history(AppView::AddTable); - app_state.ui.focus_outside_canvas = false; - *command_message = "Navigating to Add Table page...".to_string(); + // --- Prepare AddTableState based on persistent selections --- + if let Some(p_idx) = admin_state.selected_profile_index { + if let Some(profile) = app_state.profile_tree.profiles.get(p_idx) { + let selected_profile_name = profile.name.clone(); + + + // Create and populate the new AddTableState + let new_add_table_state = AddTableState { + profile_name: selected_profile_name, + // Reset other fields to defaults for a fresh start + ..AddTableState::default() + }; + + // Assign the prepared state + admin_state.add_table_state = new_add_table_state; + + // Switch view + buffer_state.update_history(AppView::AddTable); + app_state.ui.focus_outside_canvas = false; + *command_message = format!( + "Navigating to Add Table for profile '{}'...", + admin_state.add_table_state.profile_name + ); + + } else { + *command_message = "Error: Selected profile index out of bounds.".to_string(); + } + } else { + *command_message = "Please select a profile ([*]) first.".to_string(); + } + // --- End preparation --- } AdminFocus::Button3 => { *command_message = "Action: Change Table (Not Implemented)".to_string();