mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-05 00:03:08 +00:00
fix: transform_inputs now only support single line expressions
This commit is contained in:
@@ -143,7 +143,6 @@ fn add_closing_bracket(s: &str) -> String {
|
||||
s
|
||||
}
|
||||
|
||||
const SPLIT_PAT: &str = ";";
|
||||
async fn eval(
|
||||
context: &mut JsRuntime,
|
||||
expr: &str,
|
||||
@@ -151,21 +150,6 @@ async fn eval(
|
||||
by_id: Option<IdContext>,
|
||||
has_client: bool,
|
||||
) -> anyhow::Result<serde_json::Value> {
|
||||
let exprs = expr
|
||||
.trim()
|
||||
.split(SPLIT_PAT)
|
||||
.map(|x| x.trim())
|
||||
.filter(|x| !x.is_empty())
|
||||
.collect::<Vec<&str>>();
|
||||
let expr = if exprs.is_empty() {
|
||||
"return undefined;".to_string()
|
||||
} else {
|
||||
format!(
|
||||
"{};\n return {};",
|
||||
exprs.iter().take(exprs.len() - 1).join(";\n"),
|
||||
exprs.last().unwrap()
|
||||
)
|
||||
};
|
||||
let (api_code, by_id_code) = if has_client {
|
||||
let by_id_code = if let Some(by_id) = by_id {
|
||||
format!(
|
||||
@@ -238,7 +222,7 @@ async function resource(path) {{
|
||||
{}
|
||||
{by_id_code}
|
||||
(async () => {{
|
||||
{expr}
|
||||
return {expr};
|
||||
}})()
|
||||
"#,
|
||||
env.into_iter()
|
||||
@@ -251,7 +235,6 @@ async function resource(path) {{
|
||||
})
|
||||
.join(""),
|
||||
);
|
||||
tracing::debug!("{}", code);
|
||||
let global = context.execute_script("<anon>", code.into())?;
|
||||
let global = context.resolve_value(global).await?;
|
||||
|
||||
|
||||
@@ -196,7 +196,7 @@
|
||||
>
|
||||
{#if isStaticTemplate(inputCat)}
|
||||
<ToggleButton
|
||||
title={`Write text or surround javascript with \`\$\{\` and \`\}\`. Use \`result\` to connect to another node\'s output.`}
|
||||
title={`Write text or surround javascript with \`\$\{\` and \`\}\`. Use \`results\` to connect to another node\'s output.`}
|
||||
light
|
||||
position="left"
|
||||
value="static"
|
||||
@@ -210,7 +210,7 @@
|
||||
|
||||
<ToggleButton
|
||||
light
|
||||
title="Write javascript expressions directly, using 'flow_input' or 'result'. You can use multiline javascript."
|
||||
title="Javascript expression ('flow_input' or 'results')."
|
||||
position="right"
|
||||
value="javascript"
|
||||
startIcon={{ icon: faCode }}
|
||||
|
||||
@@ -26,12 +26,7 @@
|
||||
role="alert"
|
||||
id="dynamic-input-help-box"
|
||||
>
|
||||
the last line must always be the final expression.
|
||||
<p>
|
||||
If it is multiline, the statement before the final expression <b
|
||||
>MUST END WITH ; and a newline</b
|
||||
>
|
||||
</p>
|
||||
Single javascript expression. The following functions and objects are available:
|
||||
<ul class="ml-4">
|
||||
<li><b>{'results.<id>'}</b>: the result of step at id 'id'</li>
|
||||
<li><b>flow_input</b>: the object containing the flow input arguments</li>
|
||||
|
||||
Reference in New Issue
Block a user