chore: Upgrade Webpack to v5 (#16701)

* Upgrade Webpack to v5

* Remove mapbox hack

* Replace url-loaders and file-loaders with asset modules

* Remove 1 rule

* Change --colors to --color

* Remove invalid option (--no-progress)

* Remove url-loader, bump plugin

* Fix AnnotationLayer formula check

* Remove redundant tests

* Bump cypress packages

* Remove old comment

* Fix tests

* Remove checks for number of scripts in markdown test

* Cosmetic changes

* Add tests

* Fix test

* Fix test

* Fixes test warnings

* disable flaky test

Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com>
Co-authored-by: Michael S. Molina <michael.s.molina@gmail.com>
This commit is contained in:
Kamil Gabryjelski
2021-09-22 13:24:54 +02:00
committed by GitHub
parent 9b17e86b44
commit 486e0d412c
16 changed files with 9046 additions and 29792 deletions

View File

@@ -20,7 +20,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { CompactPicker } from 'react-color';
import Button from 'src/components/Button';
import { parse as mathjsParse } from 'mathjs';
import mexp from 'math-expression-evaluator';
import {
t,
SupersetClient,
@@ -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(/^\s*[a-zA-Z]\w*\s*$/))
) {
return false;
}
mexp.eval(subexpressions[1] ?? subexpressions[0], [token], { x: 0 });
} catch (err) {
return true;
return false;
}
}
return false;
return true;
}
isValidForm() {
@@ -238,7 +253,7 @@ export default class AnnotationLayer extends React.PureComponent {
errors.push(validateNonEmpty(intervalEndColumn));
}
}
errors.push(this.isValidFormula(value, annotationType));
errors.push(!this.isValidFormula(value, annotationType));
return !errors.filter(x => x).length;
}
@@ -442,7 +457,7 @@ export default class AnnotationLayer extends React.PureComponent {
value={value}
onChange={this.handleValue}
validationErrors={
this.isValidFormula(value, annotationType) ? ['Bad formula.'] : []
!this.isValidFormula(value, annotationType) ? ['Bad formula.'] : []
}
/>
);