diff --git a/app/client/src/widgets/TableWidget/derived.js b/app/client/src/widgets/TableWidget/derived.js index 98940ed0e4..fb552096f7 100644 --- a/app/client/src/widgets/TableWidget/derived.js +++ b/app/client/src/widgets/TableWidget/derived.js @@ -97,7 +97,7 @@ export default { // getTableColumns: (props, moment, _) => { let columns = []; - let allColumns = props.primaryColumns || {}; + let allColumns = Object.assign({}, props.primaryColumns || {}); const data = props.sanitizedTableData || []; if (data.length > 0) { const columnIdsFromData = []; @@ -171,7 +171,7 @@ export default { } const allColumnProperties = Object.values(allColumns); for (let index = 0; index < allColumnProperties.length; index++) { - const columnProperties = allColumnProperties[index]; + const columnProperties = { ...allColumnProperties[index] }; columnProperties.isAscOrder = columnProperties.id === sortColumn ? sortOrder : undefined; const columnData = columnProperties; diff --git a/app/client/src/workers/evaluate.test.ts b/app/client/src/workers/evaluate.test.ts index d63dbcc442..ac75fc85d4 100644 --- a/app/client/src/workers/evaluate.test.ts +++ b/app/client/src/workers/evaluate.test.ts @@ -82,7 +82,7 @@ describe("evaluate", () => { }); it("gets triggers from a function", () => { const js = "showAlert('message', 'info')"; - const response = evaluate(js, dataTree); + const response = evaluate(js, dataTree, undefined, true); expect(response.result).toBe(undefined); expect(response.triggers).toStrictEqual([ { diff --git a/app/client/src/workers/evaluate.ts b/app/client/src/workers/evaluate.ts index dc2ad37fb9..989c847197 100644 --- a/app/client/src/workers/evaluate.ts +++ b/app/client/src/workers/evaluate.ts @@ -94,7 +94,6 @@ export default function evaluate( // so that eval can happen const unescapedJS = unescapeJS(js.replace(beginsWithLineBreakRegex, "")); const script = getScriptToEval(unescapedJS, evalArguments, isTriggerBased); - return (function() { let errors: EvaluationError[] = []; let result; @@ -103,25 +102,36 @@ export default function evaluate( const GLOBAL_DATA: Record = {}; ///// Adding callback data GLOBAL_DATA.ARGUMENTS = evalArguments; - //// Add internal functions to dataTree; - const dataTreeWithFunctions = addFunctions(data); - ///// Adding Data tree - Object.keys(dataTreeWithFunctions).forEach((datum) => { - GLOBAL_DATA[datum] = dataTreeWithFunctions[datum]; - }); - ///// Fixing action paths and capturing their execution response - if (dataTreeWithFunctions.actionPaths) { - GLOBAL_DATA.triggers = []; - const pusher = function(this: DataTree, action: any, ...payload: any[]) { - const actionPayload = action(...payload); - GLOBAL_DATA.triggers.push(actionPayload); - }; - GLOBAL_DATA.actionPaths.forEach((path: string) => { - const action = _.get(GLOBAL_DATA, path); - const entity = _.get(GLOBAL_DATA, path.split(".")[0]); - if (action) { - _.set(GLOBAL_DATA, path, pusher.bind(data, action.bind(entity))); - } + if (isTriggerBased) { + //// Add internal functions to dataTree; + const dataTreeWithFunctions = addFunctions(data); + ///// Adding Data tree with functions + Object.keys(dataTreeWithFunctions).forEach((datum) => { + GLOBAL_DATA[datum] = dataTreeWithFunctions[datum]; + }); + ///// Fixing action paths and capturing their execution response + if (dataTreeWithFunctions.actionPaths) { + GLOBAL_DATA.triggers = []; + const pusher = function( + this: DataTree, + action: any, + ...payload: any[] + ) { + const actionPayload = action(...payload); + GLOBAL_DATA.triggers.push(actionPayload); + }; + GLOBAL_DATA.actionPaths.forEach((path: string) => { + const action = _.get(GLOBAL_DATA, path); + const entity = _.get(GLOBAL_DATA, path.split(".")[0]); + if (action) { + _.set(GLOBAL_DATA, path, pusher.bind(data, action.bind(entity))); + } + }); + } + } else { + ///// Adding Data tree + Object.keys(data).forEach((datum) => { + GLOBAL_DATA[datum] = data[datum]; }); } @@ -150,9 +160,11 @@ export default function evaluate( }); try { result = Function(script)(); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - triggers = [...self.triggers]; + if (isTriggerBased) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + triggers = [...self.triggers]; + } } catch (e) { errors.push({ errorMessage: `${e.stack.split(`\n`)[0]}`,