add_table ready to be used as a post request, only small changes are needed

This commit is contained in:
filipriec
2025-04-22 17:36:00 +02:00
parent ec596b2ada
commit 2c03ee6af0
2 changed files with 49 additions and 3 deletions

View File

@@ -124,6 +124,40 @@ pub fn render_add_table(
return; // IMPORTANT: Stop rendering here for fullscreen mode return; // IMPORTANT: Stop rendering here for fullscreen mode
} }
// --- Fullscreen Links Table Check (Narrow Screens Only) ---
if area.width < NARROW_LAYOUT_THRESHOLD && add_table_state.current_focus == AddTableFocus::InsideLinksTable {
// Render ONLY the links table taking the full inner area
let links_border_style = Style::default().fg(theme.highlight); // Always highlighted when fullscreen
let link_rows: Vec<Row<'_>> = add_table_state
.links
.iter()
.map(|link_def| {
Row::new(vec![
Cell::from(link_def.linked_table_name.clone()),
Cell::from(if link_def.selected { "[*]" } else { "[ ]" }),
])
.style(Style::default().fg(theme.fg))
})
.collect();
let link_header_cells = ["Available Table", "Selected"]
.iter()
.map(|h| Cell::from(*h).style(Style::default().fg(theme.accent)));
let link_header = Row::new(link_header_cells).height(1).bottom_margin(1);
let links_table = Table::new(link_rows, [Constraint::Percentage(95), Constraint::Length(5)])
.header(link_header)
.block(
Block::default()
.title(Span::styled(" Links (Fullscreen) ", theme.fg)) // Indicate fullscreen
.title_alignment(Alignment::Center)
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(links_border_style),
)
.row_highlight_style(Style::default().add_modifier(Modifier::REVERSED).fg(theme.highlight))
.highlight_symbol(" > "); // Use the inside symbol
f.render_stateful_widget(links_table, inner_area, &mut add_table_state.link_table_state);
return; // IMPORTANT: Stop rendering here for fullscreen mode
}
// --- Area Variable Declarations --- // --- Area Variable Declarations ---
let top_info_area: Rect; let top_info_area: Rect;
@@ -427,7 +461,7 @@ pub fn render_add_table(
.map(|link_def| { .map(|link_def| {
Row::new(vec![ Row::new(vec![
Cell::from(link_def.linked_table_name.clone()), Cell::from(link_def.linked_table_name.clone()),
Cell::from(if link_def.is_required { "[X]" } else { "[ ]" }), Cell::from(if link_def.selected { "[*]" } else { "[ ]" }),
]) ])
.style(Style::default().fg(theme.fg)) .style(Style::default().fg(theme.fg))
}) })
@@ -437,7 +471,7 @@ pub fn render_add_table(
.map(|h| Cell::from(*h).style(Style::default().fg(theme.accent))); .map(|h| Cell::from(*h).style(Style::default().fg(theme.accent)));
let link_header = Row::new(link_header_cells).height(1).bottom_margin(1); let link_header = Row::new(link_header_cells).height(1).bottom_margin(1);
let links_table = let links_table =
Table::new(link_rows, [Constraint::Percentage(80), Constraint::Min(5)]) Table::new(link_rows, [Constraint::Percentage(95), Constraint::Length(5)])
.header(link_header) .header(link_header)
.block( .block(
Block::default() Block::default()

View File

@@ -8,7 +8,7 @@ use crate::state::{
use crossterm::event::KeyEvent; use crossterm::event::KeyEvent;
use crate::state::app::buffer::AppView; use crate::state::app::buffer::AppView;
use crate::state::app::buffer::BufferState; use crate::state::app::buffer::BufferState;
use crate::state::pages::add_table::AddTableState; use crate::state::pages::add_table::{AddTableState, LinkDefinition};
/// Handles navigation events specifically for the Admin Panel view. /// Handles navigation events specifically for the Admin Panel view.
/// Returns true if the event was handled, false otherwise. /// Returns true if the event was handled, false otherwise.
@@ -165,11 +165,23 @@ pub fn handle_admin_navigation(
if let Some(p_idx) = admin_state.selected_profile_index { if let Some(p_idx) = admin_state.selected_profile_index {
if let Some(profile) = app_state.profile_tree.profiles.get(p_idx) { if let Some(profile) = app_state.profile_tree.profiles.get(p_idx) {
let selected_profile_name = profile.name.clone(); let selected_profile_name = profile.name.clone();
// --- Populate Links from Profile Tables ---
let available_links: Vec<LinkDefinition> = profile
.tables
.iter()
.map(|table| LinkDefinition {
linked_table_name: table.name.clone(),
is_required: false,
selected: false,
})
.collect();
// --- End Populate Links ---
// Create and populate the new AddTableState // Create and populate the new AddTableState
let new_add_table_state = AddTableState { let new_add_table_state = AddTableState {
profile_name: selected_profile_name, profile_name: selected_profile_name,
links: available_links,
// Reset other fields to defaults for a fresh start // Reset other fields to defaults for a fresh start
..AddTableState::default() ..AddTableState::default()
}; };