mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-28 04:11:16 +01:00
Add an option to allow jsonpath/xpath to return as array (#297)
Co-authored-by: Gregory Schier <gschier1990@gmail.com>
This commit is contained in:
@@ -658,6 +658,18 @@ pub enum JsonPrimitive {
|
||||
Null,
|
||||
}
|
||||
|
||||
impl From<serde_json::Value> for JsonPrimitive {
|
||||
fn from(value: serde_json::Value) -> Self {
|
||||
match value {
|
||||
serde_json::Value::Null => JsonPrimitive::Null,
|
||||
serde_json::Value::Bool(b) => JsonPrimitive::Boolean(b),
|
||||
serde_json::Value::Number(n) => JsonPrimitive::Number(n.as_f64().unwrap()),
|
||||
serde_json::Value::String(s) => JsonPrimitive::String(s),
|
||||
v => panic!("Unsupported JSON primitive type {:?}", v),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
#[ts(export, export_to = "gen_events.ts")]
|
||||
@@ -733,6 +745,7 @@ pub enum FormInput {
|
||||
File(FormInputFile),
|
||||
HttpRequest(FormInputHttpRequest),
|
||||
Accordion(FormInputAccordion),
|
||||
HStack(FormInputHStack),
|
||||
Banner(FormInputBanner),
|
||||
Markdown(FormInputMarkdown),
|
||||
}
|
||||
@@ -895,7 +908,7 @@ pub struct FormInputFile {
|
||||
#[ts(optional)]
|
||||
pub directory: Option<bool>,
|
||||
|
||||
// Default file path for selection dialog
|
||||
// Default file path for the selection dialog
|
||||
#[ts(optional)]
|
||||
pub default_path: Option<String>,
|
||||
|
||||
@@ -953,6 +966,14 @@ pub struct FormInputAccordion {
|
||||
pub hidden: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
#[ts(export, export_to = "gen_events.ts")]
|
||||
pub struct FormInputHStack {
|
||||
#[ts(optional)]
|
||||
pub inputs: Option<Vec<FormInput>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, TS)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
#[ts(export, export_to = "gen_events.ts")]
|
||||
@@ -1015,7 +1036,7 @@ pub struct CallTemplateFunctionResponse {
|
||||
#[ts(export, export_to = "gen_events.ts")]
|
||||
pub struct CallTemplateFunctionArgs {
|
||||
pub purpose: RenderPurpose,
|
||||
pub values: HashMap<String, serde_json::Value>,
|
||||
pub values: HashMap<String, JsonPrimitive>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
|
||||
|
||||
@@ -786,7 +786,7 @@ impl PluginManager {
|
||||
&self,
|
||||
plugin_context: &PluginContext,
|
||||
fn_name: &str,
|
||||
values: HashMap<String, serde_json::Value>,
|
||||
values: HashMap<String, JsonPrimitive>,
|
||||
purpose: RenderPurpose,
|
||||
) -> TemplateResult<String> {
|
||||
let req = CallTemplateFunctionRequest {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::events::{PluginContext, RenderPurpose};
|
||||
use crate::events::{JsonPrimitive, PluginContext, RenderPurpose};
|
||||
use crate::manager::PluginManager;
|
||||
use crate::native_template_functions::{
|
||||
template_function_keychain_run, template_function_secure_run,
|
||||
@@ -42,12 +42,17 @@ impl<R: Runtime> TemplateCallback for PluginTemplateCallback<R> {
|
||||
return template_function_keychain_run(args);
|
||||
}
|
||||
|
||||
let mut primitive_args = HashMap::new();
|
||||
for (key, value) in args {
|
||||
primitive_args.insert(key, JsonPrimitive::from(value));
|
||||
}
|
||||
|
||||
let plugin_manager = &*self.app_handle.state::<PluginManager>();
|
||||
let resp = plugin_manager
|
||||
.call_template_function(
|
||||
&self.plugin_context,
|
||||
fn_name,
|
||||
args,
|
||||
primitive_args,
|
||||
self.render_purpose.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Reference in New Issue
Block a user