Skip to content

A platform for community discussion. Free, open, simple.

DEV: Clean up workflow expression reference internals (#41545)

Renato Atilio010ce4d1363c
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/expression-context.js b/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/expression-context.js
index c45f95b45dd..d1b5f582f53 100644
--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/expression-context.js
+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/expression-context.js
@@ -26,7 +26,7 @@ export function resolveVariableId(variable, itemPrefix = "$json") {
}
// Matches paths like $('Node Name').rest or $("Node Name").rest
-const NODE_REF_RE = /^\$\((?:"((?:\\.|[^"\\])*)"|'((?:\\.|[^'\\])*)')\)/;
+export const NODE_REF_RE = /^\$\((?:"((?:\\.|[^"\\])*)"|'((?:\\.|[^'\\])*)')\)/;
const METHOD_CALL_RE = /^([A-Za-z_$][\w$]*)\((.*)\)$/;
const METHOD_WITH_SUFFIX_RE = /^([A-Za-z_$][\w$]*)\((.*?)\)(.*)$/;
// A property followed by one or more subscripts, e.g. `items[0]` or `map["k"]`.
@@ -73,7 +73,12 @@ export function walkScope(scope, path) {
return target;
}
-function parseNodeReferenceName(nodeRef) {
+// Reverses the escaping in a single-quoted literal (\\ and \' only).
+function unescapeSingleQuoted(str) {
+ return str.replace(/\\([\\'])/g, "$1");
+}
+
+export function parseNodeReferenceName(nodeRef) {
const doubleQuoted = nodeRef[1] !== undefined;
const raw = doubleQuoted ? nodeRef[1] : nodeRef[2];
@@ -85,7 +90,7 @@ function parseNodeReferenceName(nodeRef) {
}
}
- return raw.replace(/\\([\\'])/g, "$1");
+ return unescapeSingleQuoted(raw);
}
function resolvePathPart(target, part, scope) {
@@ -148,7 +153,7 @@ function resolveBracketKey(source, scope) {
}
if (key.startsWith("'")) {
- return key.slice(1, -1).replace(/\\([\\'])/g, "$1");
+ return unescapeSingleQuoted(key.slice(1, -1));
}
return walkScope(scope, key);
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/expression-extensions/reference-label.js b/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/expression-extensions/reference-label.js
index 81cb9732345..9dc1b2861fa 100644
--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/expression-extensions/reference-label.js
+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/expression-extensions/reference-label.js
@@ -1,11 +1,9 @@
import { i18n } from "discourse-i18n";
+import { NODE_REF_RE, parseNodeReferenceName } from "../expression-context";
// Parses a "simple reference" into source + path. Anything more involved
// (operators, arithmetic, multiple refs, method calls) returns null.
-// Matches a leading $('Node Name') / $("Node Name") node reference.
-const NODE_REF_RE = /^\$\((?:"((?:\\.|[^"\\])*)"|'((?:\\.|[^'\\])*)')\)/;
-
// An item selector after a node/$input ref: .first(), .item, .itemMatching('x')…
const SELECTOR_RE =
/^(?:\.(?:first|last|all|itemMatching|pairedItem)\([^()]*\)|\.item)/;
@@ -38,21 +36,6 @@ const SOURCE_ICONS = {
execution: "bolt",
};
-function parseNodeReferenceName(match) {
- const doubleQuoted = match[1] !== undefined;
- const raw = doubleQuoted ? match[1] : match[2];
-
- if (doubleQuoted) {
- try {
- return JSON.parse(`"${raw}"`);
- } catch {
- return raw;
- }
- }
-
- return raw.replace(/\\([\\'])/g, "$1");
-}
-
function stripLeadingDot(text) {
return text.startsWith(".") ? text.slice(1) : text;
}
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/expression-extensions/reference-properties.js b/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/expression-extensions/reference-properties.js
index 065822ecba1..8f9820d6da9 100644
--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/expression-extensions/reference-properties.js
+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/lib/workflows/expression-extensions/reference-properties.js
@@ -82,7 +82,6 @@ function splitLastAccessor(expression) {
return { parent, current: key };
}
-// Object → drill (append the pick); leaf → switch siblings (replace last).
export function referencePickerData(scope, expression) {
const inner = (expression || "").trim();
if (!inner) {
diff --git a/plugins/discourse-workflows/plugin.rb b/plugins/discourse-workflows/plugin.rb
index 871489559bf..55d10825a13 100644
--- a/plugins/discourse-workflows/plugin.rb
+++ b/plugins/discourse-workflows/plugin.rb
@@ -40,11 +40,7 @@ register_svg_icon "palette"
register_svg_icon "reply"
register_svg_icon "triangle-exclamation"
register_svg_icon "clock"
-register_svg_icon "diagram-project"
-register_svg_icon "right-to-bracket"
register_svg_icon "dollar-sign"
-register_svg_icon "user"
-register_svg_icon "gear"
register_svg_icon "comments"
register_svg_icon "pause"
register_svg_icon "window-maximize"