diff --git a/app/client/src/entities/DataTree/dataTreeAction.ts b/app/client/src/entities/DataTree/dataTreeAction.ts index c99388e5fb..ab528cae64 100644 --- a/app/client/src/entities/DataTree/dataTreeAction.ts +++ b/app/client/src/entities/DataTree/dataTreeAction.ts @@ -47,7 +47,7 @@ export const generateDataTreeAction = ( pluginType: action.config.pluginType, config: action.config.actionConfiguration, dynamicBindingPathList, - data: action.data ? action.data.body : {}, + data: action.data ? action.data.body : undefined, responseMeta: { statusCode: action.data?.statusCode, isExecutionSuccess: action.data?.isExecutionSuccess || false, diff --git a/app/client/src/workers/DataTreeEvaluator.ts b/app/client/src/workers/DataTreeEvaluator.ts index a02ae2ff80..a849900254 100644 --- a/app/client/src/workers/DataTreeEvaluator.ts +++ b/app/client/src/workers/DataTreeEvaluator.ts @@ -1385,6 +1385,7 @@ export default class DataTreeEvaluator { // In this case if the path exists in the dependency map // remove it. else if (fullPropertyPath in this.dependencyMap) { + didUpdateDependencyMap = true; delete this.dependencyMap[fullPropertyPath]; } } diff --git a/app/client/src/workers/evaluationUtils.test.ts b/app/client/src/workers/evaluationUtils.test.ts index 4c2b86733f..d88d91a807 100644 --- a/app/client/src/workers/evaluationUtils.test.ts +++ b/app/client/src/workers/evaluationUtils.test.ts @@ -8,13 +8,18 @@ import { PrivateWidgets, } from "entities/DataTree/dataTreeFactory"; import { + DataTreeDiff, + DataTreeDiffEvent, getAllPaths, getAllPrivateWidgetsInDataTree, getDataTreeWithoutPrivateWidgets, isPrivateEntityPath, makeParentsDependOnChildren, + translateDiffEventToDataTreeDiffEvent, } from "./evaluationUtils"; import { warn as logWarn } from "loglevel"; +import { Diff } from "deep-diff"; +import { flatten } from "lodash"; // to check if logWarn was called. // use jest.unmock, if the mock needs to be removed. @@ -274,3 +279,118 @@ describe("makeParentsDependOnChildren", () => { ); }); }); + +describe("translateDiffEvent", () => { + it("noop when diff path does not exist", () => { + const noDiffPath: Diff = { + kind: "E", + lhs: undefined, + rhs: undefined, + }; + const result = translateDiffEventToDataTreeDiffEvent(noDiffPath, {}); + expect(result).toStrictEqual({ + payload: { + propertyPath: "", + value: "", + }, + event: DataTreeDiffEvent.NOOP, + }); + }); + it("translates new and delete events", () => { + const diffs: Diff[] = [ + { + kind: "N", + path: ["Widget1"], + rhs: {}, + }, + { + kind: "N", + path: ["Widget1", "name"], + rhs: "Widget1", + }, + { + kind: "D", + path: ["Widget1"], + lhs: {}, + }, + { + kind: "D", + path: ["Widget1", "name"], + lhs: "Widget1", + }, + { + kind: "E", + path: ["Widget2", "name"], + rhs: "test", + lhs: "test2", + }, + ]; + + const expectedTranslations: DataTreeDiff[] = [ + { + payload: { + propertyPath: "Widget1", + }, + event: DataTreeDiffEvent.NEW, + }, + { + payload: { + propertyPath: "Widget1.name", + }, + event: DataTreeDiffEvent.NEW, + }, + { + payload: { + propertyPath: "Widget1", + }, + event: DataTreeDiffEvent.DELETE, + }, + { + payload: { + propertyPath: "Widget1.name", + }, + event: DataTreeDiffEvent.DELETE, + }, + { + payload: { + propertyPath: "", + value: "", + }, + event: DataTreeDiffEvent.NOOP, + }, + ]; + + const actualTranslations = flatten( + diffs.map((diff) => translateDiffEventToDataTreeDiffEvent(diff, {})), + ); + + expect(expectedTranslations).toStrictEqual(actualTranslations); + }); + + it("properly categorises the edit events", () => { + const diffs: Diff[] = [ + { + kind: "E", + path: ["Widget2", "name"], + rhs: "test", + lhs: "test2", + }, + ]; + + const expectedTranslations: DataTreeDiff[] = [ + { + payload: { + propertyPath: "", + value: "", + }, + event: DataTreeDiffEvent.NOOP, + }, + ]; + + const actualTranslations = flatten( + diffs.map((diff) => translateDiffEventToDataTreeDiffEvent(diff, {})), + ); + + expect(expectedTranslations).toStrictEqual(actualTranslations); + }); +}); diff --git a/app/client/src/workers/evaluationUtils.ts b/app/client/src/workers/evaluationUtils.ts index bc734e5598..502b615b8b 100644 --- a/app/client/src/workers/evaluationUtils.ts +++ b/app/client/src/workers/evaluationUtils.ts @@ -164,11 +164,17 @@ export const translateDiffEventToDataTreeDiffEvent = ( } else if (difference.lhs === undefined || difference.rhs === undefined) { // Handle static value changes that change structure that can lead to // old bindings being eligible - if (difference.lhs === undefined && isTrueObject(difference.rhs)) { + if ( + difference.lhs === undefined && + (isTrueObject(difference.rhs) || Array.isArray(difference.rhs)) + ) { result.event = DataTreeDiffEvent.NEW; result.payload = { propertyPath }; } - if (difference.rhs === undefined && isTrueObject(difference.lhs)) { + if ( + difference.rhs === undefined && + (isTrueObject(difference.lhs) || Array.isArray(difference.lhs)) + ) { result.event = DataTreeDiffEvent.DELETE; result.payload = { propertyPath }; }