autocomplete is now powerful
This commit is contained in:
@@ -18,15 +18,15 @@ impl UiService {
|
||||
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
|
||||
// Collect table names from SAME profile only
|
||||
let same_profile_table_names: Vec<String> = profile_tree.profiles
|
||||
.iter()
|
||||
.flat_map(|profile| profile.tables.iter())
|
||||
.map(|table| table.name.clone())
|
||||
.collect();
|
||||
.find(|profile| profile.name == add_logic_state.profile_name)
|
||||
.map(|profile| profile.tables.iter().map(|table| table.name.clone()).collect())
|
||||
.unwrap_or_default();
|
||||
|
||||
// Set all table names for autocomplete
|
||||
add_logic_state.set_all_table_names(all_table_names.clone());
|
||||
// Set same profile table names for autocomplete
|
||||
add_logic_state.set_same_profile_table_names(same_profile_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 {
|
||||
@@ -39,10 +39,11 @@ impl UiService {
|
||||
add_logic_state.set_table_columns(column_names.clone());
|
||||
|
||||
Ok(format!(
|
||||
"Loaded {} columns for table '{}' and {} total tables for autocomplete",
|
||||
"Loaded {} columns for table '{}' and {} tables from profile '{}'",
|
||||
column_names.len(),
|
||||
table_name_clone,
|
||||
all_table_names.len()
|
||||
same_profile_table_names.len(),
|
||||
add_logic_state.profile_name
|
||||
))
|
||||
}
|
||||
Err(e) => {
|
||||
@@ -53,20 +54,43 @@ impl UiService {
|
||||
e
|
||||
);
|
||||
Ok(format!(
|
||||
"Warning: Could not load table structure for '{}'. Autocomplete will use basic suggestions with {} tables.",
|
||||
"Warning: Could not load table structure for '{}'. Autocomplete will use {} tables from profile '{}'.",
|
||||
table_name_clone,
|
||||
all_table_names.len()
|
||||
same_profile_table_names.len(),
|
||||
add_logic_state.profile_name
|
||||
))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Ok(format!(
|
||||
"No table selected for Add Logic. Loaded {} tables for autocomplete.",
|
||||
all_table_names.len()
|
||||
"No table selected for Add Logic. Loaded {} tables from profile '{}' for autocomplete.",
|
||||
same_profile_table_names.len(),
|
||||
add_logic_state.profile_name
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetches columns for a specific table (used for table.column autocomplete)
|
||||
pub async fn fetch_columns_for_table(
|
||||
grpc_client: &mut GrpcClient,
|
||||
profile_name: &str,
|
||||
table_name: &str,
|
||||
) -> Result<Vec<String>> {
|
||||
match grpc_client.get_table_structure(profile_name.to_string(), table_name.to_string()).await {
|
||||
Ok(response) => {
|
||||
let column_names: Vec<String> = response.columns
|
||||
.into_iter()
|
||||
.map(|col| col.name)
|
||||
.collect();
|
||||
Ok(column_names)
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!("Failed to fetch columns for {}.{}: {}", profile_name, table_name, e);
|
||||
Err(e.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn initialize_app_state(
|
||||
grpc_client: &mut GrpcClient,
|
||||
app_state: &mut AppState,
|
||||
|
||||
Reference in New Issue
Block a user