init startup fail fixed to detect working profile not just default profile

This commit is contained in:
Priec
2025-07-28 23:15:26 +02:00
parent 64fd7e4af2
commit d1b28b4fdd

View File

@@ -176,7 +176,7 @@ impl UiService {
} }
} }
// REFACTOR THIS FUNCTION // TODO REFACTOR (maybe)
pub async fn initialize_app_state_and_form( pub async fn initialize_app_state_and_form(
grpc_client: &mut GrpcClient, grpc_client: &mut GrpcClient,
app_state: &mut AppState, app_state: &mut AppState,
@@ -185,28 +185,27 @@ impl UiService {
.get_profile_tree() .get_profile_tree()
.await .await
.context("Failed to get profile tree")?; .context("Failed to get profile tree")?;
app_state.profile_tree = profile_tree; app_state.profile_tree = profile_tree;
let initial_profile_name = app_state // Find first profile that contains tables
let (initial_profile_name, initial_table_name) = app_state
.profile_tree .profile_tree
.profiles .profiles
.first() .iter()
.map(|p| p.name.clone()) .find(|profile| !profile.tables.is_empty())
.unwrap_or_else(|| "default".to_string()); .and_then(|profile| {
profile.tables.first().map(|table| {
let initial_table_name = app_state (profile.name.clone(), table.name.clone())
.profile_tree })
.profiles })
.first() .ok_or_else(|| anyhow!("No profiles with tables found. Create a table first."))?;
.and_then(|p| p.tables.first().map(|t| t.name.clone()))
.unwrap_or_else(|| "2025_company_data1".to_string());
app_state.set_current_view_table( app_state.set_current_view_table(
initial_profile_name.clone(), initial_profile_name.clone(),
initial_table_name.clone(), initial_table_name.clone(),
); );
// NOW, just call our new central function. This avoids code duplication.
let form_state = Self::load_table_view( let form_state = Self::load_table_view(
grpc_client, grpc_client,
app_state, app_state,
@@ -215,7 +214,6 @@ impl UiService {
) )
.await?; .await?;
// The field names for the UI are derived from the new form_state
let field_names = form_state.fields.iter().map(|f| f.display_name.clone()).collect(); let field_names = form_state.fields.iter().map(|f| f.display_name.clone()).collect();
Ok((initial_profile_name, initial_table_name, field_names)) Ok((initial_profile_name, initial_table_name, field_names))