add table and add logic removal from ui.rs and event.rs

This commit is contained in:
filipriec
2025-08-30 19:47:26 +02:00
parent 9ed558562b
commit c7d524c76a
6 changed files with 179 additions and 76 deletions

View File

@@ -12,6 +12,7 @@ use crate::state::pages::auth::AuthState;
use crate::state::pages::auth::UserRole;
use crate::pages::login::LoginFormState;
use crate::pages::register::RegisterFormState;
use crate::pages::admin_panel::add_logic;
use crate::pages::admin::AdminState;
use crate::pages::admin::AdminFocus;
use crate::pages::admin::admin;
@@ -485,67 +486,25 @@ pub async fn run_ui() -> Result<()> {
}
}
// Continue with the rest of the positioning logic...
// Now we can use CanvasState methods like get_current_input(), current_field(), etc.
let needs_redraw_from_fetch = add_logic::loader::process_pending_table_structure_fetch(
&mut app_state,
&mut router,
&mut grpc_client,
&mut event_handler.command_message,
).await.unwrap_or(false);
if let Some((profile_name, table_name)) = app_state.pending_table_structure_fetch.take() {
if let Page::AddLogic(state) = &mut router.current {
if state.profile_name == profile_name
&& state.selected_table_name.as_deref() == Some(table_name.as_str())
{
info!("Fetching table structure for {}.{}", profile_name, table_name);
let fetch_message = UiService::initialize_add_logic_table_data(
&mut grpc_client,
state,
&app_state.profile_tree,
)
.await
.unwrap_or_else(|e| {
error!("Error initializing add_logic_table_data: {}", e);
format!("Error fetching table structure: {}", e)
});
if !fetch_message.contains("Error") && !fetch_message.contains("Warning") {
info!("{}", fetch_message);
} else {
event_handler.command_message = fetch_message;
}
needs_redraw = true;
} else {
error!(
"Mismatch in pending_table_structure_fetch: app_state wants {}.{}, but AddLogic state is for {}.{:?}",
profile_name,
table_name,
state.profile_name,
state.selected_table_name
);
}
} else {
warn!(
"Pending table structure fetch for {}.{} but AddLogic view is not active. Fetch ignored.",
profile_name, table_name
);
}
if needs_redraw_from_fetch {
needs_redraw = true;
}
if let Page::AddLogic(state) = &mut router.current {
if let Some(table_name) = state.script_editor_awaiting_column_autocomplete.clone() {
let profile_name = state.profile_name.clone();
let needs_redraw_from_columns = add_logic::loader::maybe_fetch_columns_for_awaiting_table(
&mut grpc_client,
state,
&mut event_handler.command_message,
).await.unwrap_or(false);
info!("Fetching columns for table selection: {}.{}", profile_name, table_name);
match UiService::fetch_columns_for_table(&mut grpc_client, &profile_name, &table_name).await {
Ok(columns) => {
state.set_columns_for_table_autocomplete(columns.clone());
info!("Loaded {} columns for table '{}'", columns.len(), table_name);
event_handler.command_message = format!("Columns for '{}' loaded. Select a column.", table_name);
}
Err(e) => {
error!("Failed to fetch columns for {}.{}: {}", profile_name, table_name, e);
state.script_editor_awaiting_column_autocomplete = None;
state.deactivate_script_editor_autocomplete();
event_handler.command_message = format!("Error loading columns for '{}': {}", table_name, e);
}
}
if needs_redraw_from_columns {
needs_redraw = true;
}
}