displaying data properly, fixing hardcoded backend to firma part one
This commit is contained in:
@@ -51,7 +51,6 @@ impl FormState {
|
||||
theme: &Theme,
|
||||
is_edit_mode: bool,
|
||||
highlight_state: &HighlightState,
|
||||
// total_count and current_position are now part of self
|
||||
) {
|
||||
let fields_str_slice: Vec<&str> =
|
||||
self.fields.iter().map(|s| s.as_str()).collect();
|
||||
@@ -64,6 +63,7 @@ impl FormState {
|
||||
&fields_str_slice,
|
||||
&self.current_field,
|
||||
&values_str_slice,
|
||||
&self.table_name,
|
||||
theme,
|
||||
is_edit_mode,
|
||||
highlight_state,
|
||||
@@ -107,33 +107,35 @@ impl FormState {
|
||||
&mut self,
|
||||
response_data: &HashMap<String, String>,
|
||||
) {
|
||||
self.values = self.fields.iter()
|
||||
.map(|field| response_data.get(field).cloned().unwrap_or_default())
|
||||
.collect();
|
||||
// Create a new vector for the values, ensuring they are in the correct order.
|
||||
self.values = self.fields.iter().map(|field_from_schema| {
|
||||
// For each field from our schema, find the corresponding key in the
|
||||
// response data by doing a case-insensitive comparison.
|
||||
response_data
|
||||
.iter()
|
||||
.find(|(key_from_data, _)| key_from_data.eq_ignore_ascii_case(field_from_schema))
|
||||
.map(|(_, value)| value.clone()) // If found, clone its value.
|
||||
.unwrap_or_default() // If not found, use an empty string.
|
||||
}).collect();
|
||||
|
||||
if let Some(id_str) = response_data.get("id") {
|
||||
match id_str.parse::<i64>() {
|
||||
Ok(parsed_id) => self.id = parsed_id,
|
||||
Err(e) => {
|
||||
tracing::error!(
|
||||
"Failed to parse 'id' field '{}' for table {}.{}: {}",
|
||||
id_str,
|
||||
self.profile_name,
|
||||
self.table_name,
|
||||
e
|
||||
);
|
||||
self.id = 0; // Default to 0 if parsing fails
|
||||
}
|
||||
// Now, do the same case-insensitive lookup for the 'id' field.
|
||||
let id_str_opt = response_data
|
||||
.iter()
|
||||
.find(|(k, _)| k.eq_ignore_ascii_case("id"))
|
||||
.map(|(_, v)| v);
|
||||
|
||||
if let Some(id_str) = id_str_opt {
|
||||
if let Ok(parsed_id) = id_str.parse::<i64>() {
|
||||
self.id = parsed_id;
|
||||
} else {
|
||||
tracing::error!( "Failed to parse 'id' field '{}' for table {}.{}", id_str, self.profile_name, self.table_name);
|
||||
self.id = 0;
|
||||
}
|
||||
} else {
|
||||
// If no ID is present, it might be a new record structure or an error
|
||||
// For now, assume it means the record doesn't have an ID from the server yet
|
||||
self.id = 0;
|
||||
}
|
||||
|
||||
self.has_unsaved_changes = false;
|
||||
// current_field and current_cursor_pos might need resetting or adjusting
|
||||
// depending on the desired behavior after loading data.
|
||||
// For now, let's reset current_field to 0.
|
||||
self.current_field = 0;
|
||||
self.current_cursor_pos = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user