compiled, still not working for canvas
This commit is contained in:
@@ -1,28 +1,37 @@
|
||||
// src/components/admin/add_table.rs
|
||||
use crate::config::colors::themes::Theme;
|
||||
use crate::state::app::highlight::HighlightState;
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::state::pages::add_table::{AddTableFocus, AddTableState};
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
use ratatui::{
|
||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||
style::{Style, Stylize},
|
||||
style::{Modifier, Style, Stylize},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, BorderType, Borders, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::state::app::highlight::HighlightState;
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
// Assuming render_canvas exists and works like in register.rs
|
||||
use crate::components::handlers::canvas::render_canvas;
|
||||
use crate::state::pages::add_table::AddTableState;
|
||||
|
||||
/// Renders a placeholder page for adding tables.
|
||||
/// Renders the Add New Table page layout.
|
||||
pub fn render_add_table(
|
||||
f: &mut Frame,
|
||||
area: Rect,
|
||||
theme: &Theme,
|
||||
_app_state: &AppState,
|
||||
app_state: &AppState, // Changed back from _app_state as it's needed for focus_outside_canvas check potentially
|
||||
add_table_state: &mut AddTableState,
|
||||
is_edit_mode: bool,
|
||||
is_edit_mode: bool, // This comes from the main event loop based on AppMode
|
||||
highlight_state: &HighlightState,
|
||||
) {
|
||||
// Determine if focus is on canvas inputs vs other elements based on AddTableState
|
||||
let focus_on_canvas_inputs = matches!(
|
||||
add_table_state.current_focus,
|
||||
AddTableFocus::InputTableName
|
||||
| AddTableFocus::InputColumnName
|
||||
| AddTableFocus::InputColumnType
|
||||
);
|
||||
|
||||
// Main block for the whole page
|
||||
let main_block = Block::default()
|
||||
.title(" Add New Table ")
|
||||
@@ -51,17 +60,24 @@ pub fn render_add_table(
|
||||
.constraints([
|
||||
Constraint::Length(3), // Profile & Table Name header
|
||||
Constraint::Min(5), // Columns section (expandable)
|
||||
Constraint::Length(1), // Separator
|
||||
Constraint::Length(1), // Separator (placeholder for now)
|
||||
Constraint::Min(3), // Indexes section (expandable)
|
||||
Constraint::Length(1), // Separator
|
||||
Constraint::Length(1), // Separator (placeholder for now)
|
||||
Constraint::Min(3), // Links section (expandable)
|
||||
].as_ref())
|
||||
.split(left_pane);
|
||||
|
||||
// Profile & Table Name section
|
||||
// --- Left Pane Rendering ---
|
||||
// Profile & Table Name section (Displays current state)
|
||||
let profile_text = Paragraph::new(vec![
|
||||
Line::from(Span::styled("profile: default", theme.fg)), // Placeholder
|
||||
Line::from(Span::styled("table name: [tablename]", theme.fg)), // Placeholder
|
||||
Line::from(Span::styled(
|
||||
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,
|
||||
)),
|
||||
])
|
||||
.block(
|
||||
Block::default()
|
||||
@@ -70,36 +86,67 @@ pub fn render_add_table(
|
||||
);
|
||||
f.render_widget(profile_text, left_vertical_chunks[0]);
|
||||
|
||||
// Columns section
|
||||
let columns_text = Paragraph::new(vec![
|
||||
// --- Columns Table ---
|
||||
let columns_focused =
|
||||
add_table_state.current_focus == AddTableFocus::ColumnsTable;
|
||||
let columns_border_style = if columns_focused {
|
||||
Style::default().fg(theme.highlight)
|
||||
} 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(Block::default().title(Span::styled(" Columns ", theme.fg)));
|
||||
f.render_widget(columns_text, left_vertical_chunks[1]);
|
||||
.block(
|
||||
Block::default()
|
||||
.title(Span::styled(" Columns ", theme.fg))
|
||||
.borders(Borders::TOP) // Separator from Profile/Name
|
||||
.border_style(columns_border_style), // Indicate focus
|
||||
);
|
||||
f.render_widget(columns_content, left_vertical_chunks[1]);
|
||||
|
||||
// Indexes section
|
||||
let indexes_text = Paragraph::new(vec![
|
||||
// --- Indexes Table ---
|
||||
let indexes_focused =
|
||||
add_table_state.current_focus == AddTableFocus::IndexesTable;
|
||||
let indexes_border_style = if indexes_focused {
|
||||
Style::default().fg(theme.highlight)
|
||||
} else {
|
||||
Style::default().fg(theme.secondary)
|
||||
};
|
||||
// TODO: Replace this Paragraph with a Table/List widget for add_table_state.indexes
|
||||
let indexes_content = Paragraph::new(vec![
|
||||
Line::from(Span::styled("Column name", theme.accent)), // Header
|
||||
Line::from("... Index list placeholder ..."),
|
||||
])
|
||||
.block(
|
||||
Block::default()
|
||||
.title(Span::styled(" Indexes ", theme.fg))
|
||||
.borders(Borders::TOP) // Separator from Columns
|
||||
.border_style(Style::default().fg(theme.secondary)),
|
||||
.border_style(indexes_border_style), // Indicate focus
|
||||
);
|
||||
f.render_widget(indexes_text, left_vertical_chunks[3]);
|
||||
f.render_widget(indexes_content, left_vertical_chunks[3]);
|
||||
|
||||
// Links section
|
||||
let links_text = Paragraph::new(vec![
|
||||
// --- Links Table ---
|
||||
let links_focused = add_table_state.current_focus == AddTableFocus::LinksTable;
|
||||
let links_border_style = if links_focused {
|
||||
Style::default().fg(theme.highlight)
|
||||
} else {
|
||||
Style::default().fg(theme.secondary)
|
||||
};
|
||||
// TODO: Replace this Paragraph with a Table widget for add_table_state.links
|
||||
let links_content = Paragraph::new(vec![
|
||||
Line::from(Span::styled("Linked table Required", theme.accent)), // Header
|
||||
Line::from("... Link list placeholder ..."),
|
||||
])
|
||||
.block(
|
||||
Block::default()
|
||||
.title(Span::styled(" Links ", theme.fg))
|
||||
.borders(Borders::TOP) // Separator from Indexes
|
||||
.border_style(Style::default().fg(theme.secondary)),
|
||||
.border_style(links_border_style), // Indicate focus
|
||||
);
|
||||
f.render_widget(links_text, left_vertical_chunks[5]);
|
||||
f.render_widget(links_content, left_vertical_chunks[5]);
|
||||
|
||||
// --- Right Pane ---
|
||||
let right_vertical_chunks = Layout::default()
|
||||
@@ -117,31 +164,58 @@ pub fn render_add_table(
|
||||
let bottom_buttons_area = right_vertical_chunks[3];
|
||||
|
||||
// --- Use render_canvas for Inputs ---
|
||||
// Pass is_edit_mode determined by the main loop based on AppMode
|
||||
// Only show edit styling if AppMode is Edit AND focus is on one of the canvas inputs
|
||||
let _active_field_rect = render_canvas(
|
||||
f,
|
||||
canvas_area,
|
||||
add_table_state,
|
||||
&[
|
||||
"Table name",
|
||||
"Name",
|
||||
"Type",
|
||||
],
|
||||
add_table_state, // Implements CanvasState
|
||||
&add_table_state.fields(), // Get field names from state
|
||||
&add_table_state.current_field(),
|
||||
&add_table_state.inputs().iter().map(|s| *s).collect::<Vec<&String>>(),
|
||||
&add_table_state.inputs(), // Get inputs from state
|
||||
theme,
|
||||
is_edit_mode,
|
||||
is_edit_mode && focus_on_canvas_inputs, // Only truly edit mode if focus is on canvas
|
||||
highlight_state,
|
||||
);
|
||||
|
||||
// Add Button (Placeholder)
|
||||
// --- Buttons ---
|
||||
// Helper to get style based on focus
|
||||
let get_button_style = |button_focus: AddTableFocus| {
|
||||
let is_focused = add_table_state.current_focus == button_focus;
|
||||
// Base style: secondary color, unless focused then highlight color
|
||||
let mut style = Style::default().fg(if is_focused {
|
||||
theme.highlight
|
||||
} else {
|
||||
theme.secondary
|
||||
});
|
||||
// Apply bold and reverse if focused
|
||||
if is_focused {
|
||||
style = style
|
||||
.add_modifier(Modifier::BOLD)
|
||||
.add_modifier(Modifier::REVERSED);
|
||||
}
|
||||
style
|
||||
};
|
||||
// Helper to get border style based on focus
|
||||
let get_button_border_style = |button_focus: AddTableFocus| {
|
||||
if add_table_state.current_focus == button_focus {
|
||||
Style::default().fg(theme.highlight) // Highlight border when focused
|
||||
} else {
|
||||
Style::default().fg(theme.secondary) // Dim border otherwise
|
||||
}
|
||||
};
|
||||
|
||||
// Add Button
|
||||
let add_button = Paragraph::new(" Add ")
|
||||
.style(Style::default().fg(theme.secondary))
|
||||
.style(get_button_style(AddTableFocus::AddColumnButton))
|
||||
.alignment(Alignment::Center)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(Style::default().fg(theme.secondary)),
|
||||
.border_style(get_button_border_style(
|
||||
AddTableFocus::AddColumnButton,
|
||||
)),
|
||||
);
|
||||
f.render_widget(add_button, add_button_area);
|
||||
|
||||
@@ -154,27 +228,30 @@ pub fn render_add_table(
|
||||
].as_ref())
|
||||
.split(bottom_buttons_area);
|
||||
|
||||
// Save Button (Placeholder)
|
||||
// Save Button
|
||||
let save_button = Paragraph::new(" Save table ")
|
||||
.style(Style::default().fg(theme.secondary))
|
||||
.style(get_button_style(AddTableFocus::SaveButton))
|
||||
.alignment(Alignment::Center)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(Style::default().fg(theme.secondary)),
|
||||
.border_style(get_button_border_style(AddTableFocus::SaveButton)),
|
||||
);
|
||||
f.render_widget(save_button, bottom_button_chunks[0]);
|
||||
|
||||
// Cancel Button (Placeholder)
|
||||
// Cancel Button
|
||||
let cancel_button = Paragraph::new(" Cancel ")
|
||||
.style(Style::default().fg(theme.secondary))
|
||||
.style(get_button_style(AddTableFocus::CancelButton))
|
||||
.alignment(Alignment::Center)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(Style::default().fg(theme.secondary)),
|
||||
.border_style(get_button_border_style(
|
||||
AddTableFocus::CancelButton,
|
||||
)),
|
||||
);
|
||||
f.render_widget(cancel_button, bottom_button_chunks[1]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user