From 3944d7e43e17ee4bb3869a515a2ce57984bb3d1f Mon Sep 17 00:00:00 2001 From: Hetu Nandu Date: Wed, 24 Feb 2021 21:56:00 +0530 Subject: [PATCH] Sort order fix if property path gets updated via multiple start nodes (#3194) --- app/client/src/workers/DataTreeEvaluator.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/app/client/src/workers/DataTreeEvaluator.ts b/app/client/src/workers/DataTreeEvaluator.ts index 6fe0f04ffc..45d3d85cc9 100644 --- a/app/client/src/workers/DataTreeEvaluator.ts +++ b/app/client/src/workers/DataTreeEvaluator.ts @@ -243,13 +243,27 @@ export default class DataTreeEvaluator { // Remove duplicates from this list. Since we explicitly walk down the tree and implicitly (by fetching parents) walk // up the tree, there are bound to be many duplicates. - const uniqueKeysInSortOrder = [...new Set(finalSortOrder)]; + const uniqueKeysInSortOrder = new Set(finalSortOrder); - const sortOrderPropertyPaths = Array.from(uniqueKeysInSortOrder); + // if a property path evaluation gets triggered by diff top order changes + // this could lead to incorrect sort order in spite of the bfs traversal + const sortOrderPropertyPaths: string[] = []; + this.sortedDependencies.forEach((path) => { + if (uniqueKeysInSortOrder.has(path)) { + sortOrderPropertyPaths.push(path); + // remove from the uniqueKeysInSortOrder + uniqueKeysInSortOrder.delete(path); + } + }); + // Add any remaining paths in the uniqueKeysInSortOrder + const completeSortOrder = [ + ...Array.from(uniqueKeysInSortOrder), + ...sortOrderPropertyPaths, + ]; //Trim this list to now remove the property paths which are simply entity names const finalSortOrderArray: Array = []; - sortOrderPropertyPaths.forEach((propertyPath) => { + completeSortOrder.forEach((propertyPath) => { const lastIndexOfDot = propertyPath.lastIndexOf("."); // Only do this for property paths and not the entity themselves if (lastIndexOfDot !== -1) {