villebro commented on a change in pull request #16701:
URL: https://github.com/apache/superset/pull/16701#discussion_r712973724



##########
File path: 
superset-frontend/src/explore/components/controls/AnnotationLayerControl/AnnotationLayer.jsx
##########
@@ -204,15 +204,30 @@ export default class AnnotationLayer extends 
React.PureComponent {
     return sources;
   }
 
-  isValidFormula(value, annotationType) {
+  isValidFormula(expression, annotationType) {
     if (annotationType === ANNOTATION_TYPES.FORMULA) {
       try {
-        mathjsParse(value).compile().evaluate({ x: 0 });
+        const token = {
+          type: 3,
+          token: 'x',
+          show: 'x',
+          value: 'x',
+        };
+
+        // handle input like "y = x+1" instead of just "x+1"
+        const subexpressions = expression.split('=');
+        if (
+          subexpressions.length > 2 ||
+          (subexpressions[1] && !subexpressions[0].match(/^[a-zA-Z]\w*$/))
+        ) {
+          return false;
+        }
+        mexp.eval(subexpressions[1] ?? subexpressions[0], [token], { x: 0 });

Review comment:
       Thanks for providing these @etr2460 ! It turns out we needed some 
additional functionality from `mathjs` to provide adequate backward 
compatibility for these more complex cases. I opened this PR on `superset-ui` 
to centralize this logic in one place and add proper unit tests: 
https://github.com/apache-superset/superset-ui/pull/1371 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to