tablenames added properly well

This commit is contained in:
filipriec
2025-05-26 19:51:48 +02:00
parent f3cd921c76
commit bf2726c151
3 changed files with 75 additions and 55 deletions

View File

@@ -10,6 +10,63 @@ use anyhow::{Context, Result};
pub struct UiService;
impl UiService {
pub async fn initialize_add_logic_table_data(
grpc_client: &mut GrpcClient,
add_logic_state: &mut AddLogicState,
profile_tree: &common::proto::multieko2::table_definition::ProfileTreeResponse,
) -> Result<String> {
let profile_name_clone_opt = Some(add_logic_state.profile_name.clone());
let table_name_opt_clone = add_logic_state.selected_table_name.clone();
// Collect all table names from all profiles
let all_table_names: Vec<String> = profile_tree.profiles
.iter()
.flat_map(|profile| profile.tables.iter())
.map(|table| table.name.clone())
.collect();
// Set all table names for autocomplete
add_logic_state.set_all_table_names(all_table_names.clone());
if let (Some(profile_name_clone), Some(table_name_clone)) = (profile_name_clone_opt, table_name_opt_clone) {
match grpc_client.get_table_structure(profile_name_clone.clone(), table_name_clone.clone()).await {
Ok(response) => {
let column_names: Vec<String> = response.columns
.into_iter()
.map(|col| col.name)
.collect();
add_logic_state.set_table_columns(column_names.clone());
Ok(format!(
"Loaded {} columns for table '{}' and {} total tables for autocomplete",
column_names.len(),
table_name_clone,
all_table_names.len()
))
}
Err(e) => {
tracing::warn!(
"Failed to fetch table structure for {}.{}: {}",
profile_name_clone,
table_name_clone,
e
);
Ok(format!(
"Warning: Could not load table structure for '{}'. Autocomplete will use basic suggestions with {} tables.",
table_name_clone,
all_table_names.len()
))
}
}
} else {
Ok(format!(
"No table selected for Add Logic. Loaded {} tables for autocomplete.",
all_table_names.len()
))
}
}
pub async fn initialize_app_state(
grpc_client: &mut GrpcClient,
app_state: &mut AppState,
@@ -38,49 +95,6 @@ impl UiService {
Ok(column_names)
}
pub async fn initialize_add_logic_table_data(
grpc_client: &mut GrpcClient,
add_logic_state: &mut AddLogicState,
) -> Result<String> {
let profile_name_clone_opt = Some(add_logic_state.profile_name.clone());
let table_name_opt_clone = add_logic_state.selected_table_name.clone();
if let (Some(profile_name_clone), Some(table_name_clone)) = (profile_name_clone_opt, table_name_opt_clone) {
match grpc_client.get_table_structure(profile_name_clone.clone(), table_name_clone.clone()).await {
Ok(response) => {
let column_names: Vec<String> = response.columns
.into_iter()
.map(|col| col.name)
.collect();
// This mutable borrow is now fine
add_logic_state.set_table_columns(column_names.clone());
Ok(format!(
"Loaded {} columns for table '{}' in profile '{}'",
column_names.len(),
table_name_clone, // Use cloned value
profile_name_clone // Use cloned value
))
}
Err(e) => {
tracing::warn!(
"Failed to fetch table structure for {}.{}: {}",
profile_name_clone, // Use cloned value
table_name_clone, // Use cloned value
e
);
Ok(format!(
"Warning: Could not load table structure for '{}'. Autocomplete will use basic suggestions.",
table_name_clone // Use cloned value
))
}
}
} else {
Ok("No table selected or profile name missing for Add Logic".to_string())
}
}
pub async fn initialize_adresar_count(
grpc_client: &mut GrpcClient,
app_state: &mut AppState,