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:
parent
e55fd5cc98
commit
188f9a7b8d
1 changed files with 51 additions and 2 deletions
|
|
@ -82,10 +82,11 @@ async fn execute_inline_action(
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(k, v)| (k.clone(), v.clone()))
|
.map(|(k, v)| (k.clone(), v.clone()))
|
||||||
.collect();
|
.collect();
|
||||||
|
// action.params take precedence; form_data only fills in missing keys
|
||||||
if let Some(fd) = form_data {
|
if let Some(fd) = form_data {
|
||||||
if let Some(obj) = fd.as_object() {
|
if let Some(obj) = fd.as_object() {
|
||||||
for (k, v) in obj {
|
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 =
|
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 {
|
if let Some(route) = &action.navigate_to {
|
||||||
return Ok(ActionResult::Navigate(route.clone()));
|
return Ok(ActionResult::Navigate(route.clone()));
|
||||||
|
|
@ -126,6 +127,8 @@ async fn execute_inline_action(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use pinakes_plugin_api::ActionRef;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -135,4 +138,50 @@ mod tests {
|
||||||
let _ = ActionResult::Error("error".to_string());
|
let _ = ActionResult::Error("error".to_string());
|
||||||
let _ = ActionResult::Navigate("/page".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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue