BugFix: variables not accessible from custom js queries (#2448)

This commit is contained in:
Muhsin Shah C P 2022-03-08 09:47:36 +05:30 committed by GitHub
parent 5a8e7f72f1
commit b2491a05d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 4 deletions

View file

@ -72,13 +72,24 @@ export function getDataFromLocalStorage(key) {
export function runTransformation(_ref, rawData, transformation, query) {
const data = rawData;
const evalFunction = Function(['data', 'moment', '_', 'components', 'queries', 'globals'], transformation);
const evalFunction = Function(
['data', 'moment', '_', 'components', 'queries', 'globals', 'variables'],
transformation
);
let result = [];
const currentState = _ref.state.currentState || {};
try {
result = evalFunction(data, moment, _, currentState.components, currentState.queries, currentState.globals);
result = evalFunction(
data,
moment,
_,
currentState.components,
currentState.queries,
currentState.globals,
currentState.variables
);
} catch (err) {
console.log('Transformation failed for query: ', query.name, err);
result = { message: err.stack.split('\n')[0], status: 'failed', data: data };

View file

@ -274,10 +274,18 @@ export async function executeMultilineJS(currentState, code) {
try {
const AsyncFunction = new Function(`return Object.getPrototypeOf(async function(){}).constructor`)();
var evalFn = new AsyncFunction('moment', '_', 'components', 'queries', 'globals', 'axios', code);
var evalFn = new AsyncFunction('moment', '_', 'components', 'queries', 'globals', 'axios', 'variables', code);
result = {
status: 'ok',
data: await evalFn(moment, _, currentState.components, currentState.queries, currentState.globals, axios),
data: await evalFn(
moment,
_,
currentState.components,
currentState.queries,
currentState.globals,
axios,
currentState.variables
),
};
} catch (err) {
console.log('JS execution failed: ', err);