pinakes-ui: fix action param precedence and non-JSON 2xx handling

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Iac5d1f3d2ed5c85c3e1f3d0f259235056a6a6964
This commit is contained in:
raf 2026-03-10 00:02:09 +03:00
commit 188f9a7b8d
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF

View file

@ -82,10 +82,11 @@ async fn execute_inline_action(
.iter()
.map(|(k, v)| (k.clone(), v.clone()))
.collect();
// action.params take precedence; form_data only fills in missing keys
if let Some(fd) = form_data {
if let Some(obj) = fd.as_object() {
for (k, v) in obj {
merged.insert(k.clone(), v.clone());
merged.entry(k.clone()).or_insert_with(|| v.clone());
}
}
}
@ -115,7 +116,7 @@ async fn execute_inline_action(
}
let value: serde_json::Value =
response.json().await.map_err(|e| e.to_string())?;
response.json().await.unwrap_or(serde_json::Value::Null);
if let Some(route) = &action.navigate_to {
return Ok(ActionResult::Navigate(route.clone()));
@ -126,6 +127,8 @@ async fn execute_inline_action(
#[cfg(test)]
mod tests {
use pinakes_plugin_api::ActionRef;
use super::*;
#[test]
@ -135,4 +138,50 @@ mod tests {
let _ = ActionResult::Error("error".to_string());
let _ = ActionResult::Navigate("/page".to_string());
}
#[test]
fn test_action_result_clone() {
let original = ActionResult::Success(serde_json::json!({"key": "value"}));
let cloned = original.clone();
if let (ActionResult::Success(a), ActionResult::Success(b)) =
(original, cloned)
{
assert_eq!(a, b);
} else {
panic!("clone produced wrong variant");
}
}
#[test]
fn test_action_result_error_clone() {
let original = ActionResult::Error("something went wrong".to_string());
let cloned = original.clone();
if let (ActionResult::Error(a), ActionResult::Error(b)) = (original, cloned)
{
assert_eq!(a, b);
} else {
panic!("clone produced wrong variant");
}
}
#[test]
fn test_action_result_navigate_clone() {
let original = ActionResult::Navigate("/dashboard".to_string());
let cloned = original.clone();
if let (ActionResult::Navigate(a), ActionResult::Navigate(b)) =
(original, cloned)
{
assert_eq!(a, b);
} else {
panic!("clone produced wrong variant");
}
}
#[tokio::test]
async fn test_named_action_ref_returns_none() {
let client = crate::client::ApiClient::default();
let action_ref = ActionRef::Name("my-action".to_string());
let result = execute_action(&client, &action_ref, None).await.unwrap();
assert!(matches!(result, ActionResult::None));
}
}