add table page1

This commit is contained in:
filipriec
2025-04-16 22:23:30 +02:00
parent 69953401b1
commit f4db0e384c
6 changed files with 273 additions and 16 deletions

View File

@@ -0,0 +1,68 @@
// src/state/pages/add_table.rs
use ratatui::widgets::TableState;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ColumnDefinition {
pub name: String,
pub data_type: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LinkDefinition {
pub linked_table_name: String,
pub is_required: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum AddTableFocus {
#[default]
TableName,
Columns,
Indexes,
Links,
SaveButton,
CancelButton,
}
#[derive(Debug, Clone)]
pub struct AddTableState {
pub profile_name: String,
pub table_name: String,
pub columns: Vec<ColumnDefinition>,
pub indexes: Vec<String>,
pub links: Vec<LinkDefinition>,
pub current_focus: AddTableFocus,
pub column_table_state: TableState,
pub index_table_state: TableState,
pub link_table_state: TableState,
pub table_name_cursor_pos: usize,
}
impl Default for AddTableState {
fn default() -> Self {
// Initialize with some dummy data for demonstration
AddTableState {
profile_name: "default".to_string(), // Should be set dynamically
table_name: "new_table".to_string(),
columns: vec![
ColumnDefinition { name: "id".to_string(), data_type: "INTEGER".to_string() },
ColumnDefinition { name: "name".to_string(), data_type: "TEXT".to_string() },
],
indexes: vec!["id".to_string()],
links: vec![
LinkDefinition { linked_table_name: "related_table".to_string(), is_required: true },
LinkDefinition { linked_table_name: "another_table".to_string(), is_required: false },
],
current_focus: AddTableFocus::TableName,
column_table_state: TableState::default().with_selected(0),
index_table_state: TableState::default().with_selected(0),
link_table_state: TableState::default().with_selected(0),
table_name_cursor_pos: 0,
}
}
}
impl AddTableState {
}