diff --git a/client/src/components/admin/add_table.rs b/client/src/components/admin/add_table.rs index 5c0fe28..2dfd1be 100644 --- a/client/src/components/admin/add_table.rs +++ b/client/src/components/admin/add_table.rs @@ -8,7 +8,7 @@ use ratatui::{ layout::{Alignment, Constraint, Direction, Layout, Rect}, style::{Modifier, Style, Stylize}, text::{Line, Span}, - widgets::{Block, BorderType, Borders, Paragraph}, + widgets::{Block, BorderType, Borders, Paragraph, Cell, Row, Table}, Frame, }; // Assuming render_canvas exists and works like in register.rs @@ -19,9 +19,9 @@ pub fn render_add_table( f: &mut Frame, area: Rect, theme: &Theme, - app_state: &AppState, // Changed back from _app_state as it's needed for focus_outside_canvas check potentially + app_state: &AppState, add_table_state: &mut AddTableState, - is_edit_mode: bool, // This comes from the main event loop based on AppMode + is_edit_mode: bool, highlight_state: &HighlightState, ) { // Determine if focus is on canvas inputs vs other elements based on AddTableState @@ -71,19 +71,19 @@ pub fn render_add_table( // Profile & Table Name section (Displays current state) let profile_text = Paragraph::new(vec![ Line::from(Span::styled( - format!("profile: {}", add_table_state.profile_name), // Use actual profile - theme.fg, + format!("profile: {}", add_table_state.profile_name), // Use actual profile + theme.fg, )), Line::from(Span::styled( - format!("table name: {}", add_table_state.table_name), // Use actual table name (from input) - theme.fg, - )), + format!("table name: {}", add_table_state.table_name), // Use actual table name (from input) + theme.fg, + )) ]) - .block( - Block::default() + .block( + Block::default() .borders(Borders::BOTTOM) .border_style(Style::default().fg(theme.secondary)), - ); + ); f.render_widget(profile_text, left_vertical_chunks[0]); // --- Columns Table --- @@ -94,18 +94,43 @@ pub fn render_add_table( } else { Style::default().fg(theme.secondary) }; - // TODO: Replace this Paragraph with a Table widget rendering add_table_state.columns - let columns_content = Paragraph::new(vec![ - Line::from(Span::styled("Name Type", theme.accent)), // Header - Line::from("... Column list placeholder ..."), // Placeholder content - ]) - .block( + // --- Create Table Rows from State --- + let column_rows: Vec = add_table_state + .columns + .iter() + .map(|col_def| { + Row::new(vec![ + Cell::from(col_def.name.clone()), + Cell::from(col_def.data_type.clone()), + ]) + .style(Style::default().fg(theme.fg)) + }) + .collect(); + + // --- Define Table Header --- + let header_cells = ["Name", "Type"] + .iter() + .map(|h| Cell::from(*h).style(Style::default().fg(theme.accent))); + let header = Row::new(header_cells).height(1).bottom_margin(1); + + // --- Create the Table Widget --- + let columns_table = Table::new(column_rows, [Constraint::Percentage(50), Constraint::Percentage(50)]) + .header(header) + .block( Block::default() .title(Span::styled(" Columns ", theme.fg)) .borders(Borders::TOP) // Separator from Profile/Name - .border_style(columns_border_style), // Indicate focus + .border_style(columns_border_style), + ) + .highlight_style(Style::default().add_modifier(Modifier::REVERSED).fg(theme.highlight)) // Style for selected row + .highlight_symbol(" > "); // Symbol for selected row + + // --- Render the Table --- + f.render_stateful_widget( + columns_table, + left_vertical_chunks[1], + &mut add_table_state.column_table_state, ); - f.render_widget(columns_content, left_vertical_chunks[1]); // --- Indexes Table --- let indexes_focused =