mirror of
https://github.com/apache/superset.git
synced 2026-04-21 09:04:38 +00:00
Introduce Javascript controls (#4076)
* Introduce Javascript controls This allows power-users to perform intricate transformations on data and objects using javascript code. The operations allowed are "sanboxed" or limited using node's vm `runInNewContext` https://nodejs.org/api/vm.html#vm_vm_runinnewcontext_code_sandbox_options For now I'm only enabling in the line chart visualization, but the plan would be to go towards offering more power to people who can write some JS moving forward. * Not applied
This commit is contained in:
committed by
GitHub
parent
b4909f2d03
commit
69195f8d2d
@@ -8,6 +8,7 @@ import ChartBody from './ChartBody';
|
||||
import Loading from '../components/Loading';
|
||||
import StackTraceMessage from '../components/StackTraceMessage';
|
||||
import visMap from '../../visualizations/main';
|
||||
import sandboxedEval from '../modules/sandbox';
|
||||
|
||||
const propTypes = {
|
||||
annotationData: PropTypes.object,
|
||||
@@ -141,8 +142,15 @@ class Chart extends React.PureComponent {
|
||||
|
||||
renderViz() {
|
||||
const viz = visMap[this.props.vizType];
|
||||
const fd = this.props.formData;
|
||||
const qr = this.props.queryResponse;
|
||||
try {
|
||||
viz(this, this.props.queryResponse, this.props.setControlValue);
|
||||
// Executing user-defined data mutator function
|
||||
if (fd.js_data) {
|
||||
qr.data = sandboxedEval(fd.js_data)(qr.data);
|
||||
}
|
||||
// [re]rendering the visualization
|
||||
viz(this, qr, this.props.setControlValue);
|
||||
} catch (e) {
|
||||
this.props.actions.chartRenderingFailed(e, this.props.chartKey);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user