displaying data properly, fixing hardcoded backend to firma part one

This commit is contained in:
filipriec
2025-06-07 14:05:35 +02:00
parent 08e01d41f2
commit 387e1a0fe0
10 changed files with 101 additions and 119 deletions

View File

@@ -1,19 +1,16 @@
// src/tui/functions/form.rs
use crate::state::pages::canvas_state::CanvasState; // Import the trait
use crate::state::pages::form::FormState;
use crate::services::grpc_client::GrpcClient;
use crate::state::pages::canvas_state::CanvasState;
use crate::services::ui_service::UiService;
use anyhow::{anyhow, Result};
pub async fn handle_action(
action: &str,
form_state: &mut FormState,
grpc_client: &mut GrpcClient,
current_position: &mut u64,
total_count: u64,
_grpc_client: &mut GrpcClient,
ideal_cursor_column: &mut usize,
) -> Result<String> {
// Check for unsaved changes in both cases
// FIX: Call has_unsaved_changes() via the CanvasState trait.
if form_state.has_unsaved_changes() {
return Ok(
"Unsaved changes. Save (Ctrl+S) or Revert (Ctrl+R) before navigating."
@@ -21,56 +18,31 @@ pub async fn handle_action(
);
}
let total_count = form_state.total_count;
match action {
"previous_entry" => {
let new_position = form_state.current_position.saturating_sub(1);
if new_position >= 1 {
form_state.current_position = new_position;
*current_position = new_position;
if new_position <= form_state.total_count {
let load_message = UiService::load_table_data_by_position(grpc_client, form_state).await?;
let current_input = form_state.get_current_input();
let max_cursor_pos = if !current_input.is_empty() {
current_input.len() - 1
} else { 0 };
form_state.current_cursor_pos = (*ideal_cursor_column).min(max_cursor_pos);
Ok(load_message)
if total_count > 0 {
if form_state.current_position > 1 {
form_state.current_position -= 1;
} else {
Ok(format!("Moved to position {}", new_position))
form_state.current_position = total_count;
}
} else {
Ok("Already at first position".into())
*ideal_cursor_column = 0;
}
}
"next_entry" => {
if form_state.current_position <= form_state.total_count {
form_state.current_position += 1;
*current_position = form_state.current_position;
if form_state.current_position <= form_state.total_count {
let load_message = UiService::load_table_data_by_position(grpc_client, form_state).await?;
let current_input = form_state.get_current_input();
let max_cursor_pos = if !current_input.is_empty() {
current_input.len() - 1
} else { 0 };
form_state.current_cursor_pos = (*ideal_cursor_column).min(max_cursor_pos);
Ok(load_message)
if total_count > 0 {
if form_state.current_position < total_count {
form_state.current_position += 1;
} else {
form_state.reset_to_empty();
form_state.current_field = 0;
form_state.current_cursor_pos = 0;
*ideal_cursor_column = 0;
Ok("New form entry mode".into())
form_state.current_position = 1;
}
} else {
Ok("Already at last entry".into())
*ideal_cursor_column = 0;
}
}
_ => Err(anyhow!("Unknown form action: {}", action))
_ => return Err(anyhow!("Unknown form action: {}", action)),
}
Ok(String::new())
}