From 8821e60abf8243951a062aeecf68b2252f0e6f86 Mon Sep 17 00:00:00 2001 From: colemanw Date: Thu, 8 Jun 2023 16:20:34 -0400 Subject: [PATCH] Fixes dev/core#4348 - Fix leaky variable in SearchKit traits "Grand tally" rows at the bottom of searchKit displays were leaking into each other due to the reuse of traits. This fixes it by copying each trait before using it. --- .../displays/crmSearchDisplayEntity.component.js | 4 ++-- .../resultsTable/crmSearchAdminResultsTable.component.js | 4 ++-- .../searchListing/crmSearchAdminSearchListing.component.js | 2 +- .../crmSearchAdminSegmentListing.component.js | 2 +- .../crmSearchDisplayGrid/crmSearchDisplayGrid.component.js | 4 ++-- .../crmSearchDisplayList/crmSearchDisplayList.component.js | 4 ++-- .../crmSearchDisplayTable/crmSearchDisplayTable.component.js | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ext/search_kit/ang/crmSearchAdmin/displays/crmSearchDisplayEntity.component.js b/ext/search_kit/ang/crmSearchAdmin/displays/crmSearchDisplayEntity.component.js index 5ee7e63294..f58dd343a4 100644 --- a/ext/search_kit/ang/crmSearchAdmin/displays/crmSearchDisplayEntity.component.js +++ b/ext/search_kit/ang/crmSearchAdmin/displays/crmSearchDisplayEntity.component.js @@ -13,8 +13,8 @@ templateUrl: '~/crmSearchDisplayTable/crmSearchDisplayTable.html', controller: function($scope, $element, searchDisplayBaseTrait) { var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'), - // Mix in traits to this controller - ctrl = angular.extend(this, searchDisplayBaseTrait); + // Mix in a copy of searchDisplayBaseTrait + ctrl = angular.extend(this, _.cloneDeep(searchDisplayBaseTrait)); this.$onInit = function() { // Adding this stuff for the sake of preview, but pollutes the display settings diff --git a/ext/search_kit/ang/crmSearchAdmin/resultsTable/crmSearchAdminResultsTable.component.js b/ext/search_kit/ang/crmSearchAdmin/resultsTable/crmSearchAdminResultsTable.component.js index 38940d9fbe..2e7d40857f 100644 --- a/ext/search_kit/ang/crmSearchAdmin/resultsTable/crmSearchAdminResultsTable.component.js +++ b/ext/search_kit/ang/crmSearchAdmin/resultsTable/crmSearchAdminResultsTable.component.js @@ -12,8 +12,8 @@ templateUrl: '~/crmSearchAdmin/resultsTable/crmSearchAdminResultsTable.html', controller: function($scope, $element, searchMeta, searchDisplayBaseTrait, searchDisplayTasksTrait, searchDisplaySortableTrait) { var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'), - // Mix in traits to this controller - ctrl = angular.extend(this, searchDisplayBaseTrait, searchDisplayTasksTrait, searchDisplaySortableTrait); + // Mix in copies of traits to this controller + ctrl = angular.extend(this, _.cloneDeep(searchDisplayBaseTrait), _.cloneDeep(searchDisplayTasksTrait), _.cloneDeep(searchDisplaySortableTrait)); function buildSettings() { ctrl.apiEntity = ctrl.search.api_entity; diff --git a/ext/search_kit/ang/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.component.js b/ext/search_kit/ang/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.component.js index c9b75271f1..dfdba47691 100644 --- a/ext/search_kit/ang/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.component.js +++ b/ext/search_kit/ang/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.component.js @@ -11,7 +11,7 @@ controller: function($scope, $element, $q, crmApi4, crmStatus, searchMeta, searchDisplayBaseTrait, searchDisplaySortableTrait) { var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'), // Mix in traits to this controller - ctrl = angular.extend(this, searchDisplayBaseTrait, searchDisplaySortableTrait), + ctrl = angular.extend(this, _.cloneDeep(searchDisplayBaseTrait), _.cloneDeep(searchDisplaySortableTrait)), afformLoad; this.searchDisplayPath = CRM.url('civicrm/search'); diff --git a/ext/search_kit/ang/crmSearchAdmin/searchSegmentListing/crmSearchAdminSegmentListing.component.js b/ext/search_kit/ang/crmSearchAdmin/searchSegmentListing/crmSearchAdminSegmentListing.component.js index 16ad1dc19d..c72ef73ada 100644 --- a/ext/search_kit/ang/crmSearchAdmin/searchSegmentListing/crmSearchAdminSegmentListing.component.js +++ b/ext/search_kit/ang/crmSearchAdmin/searchSegmentListing/crmSearchAdminSegmentListing.component.js @@ -11,7 +11,7 @@ controller: function($scope, $element, crmApi4, searchMeta, searchDisplayBaseTrait, searchDisplaySortableTrait) { var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'), // Mix in traits to this controller - ctrl = angular.extend(this, searchDisplayBaseTrait, searchDisplaySortableTrait); + ctrl = angular.extend(this, _.cloneDeep(searchDisplayBaseTrait), _.cloneDeep(searchDisplaySortableTrait)); this.apiEntity = 'SearchSegment'; this.search = { diff --git a/ext/search_kit/ang/crmSearchDisplayGrid/crmSearchDisplayGrid.component.js b/ext/search_kit/ang/crmSearchDisplayGrid/crmSearchDisplayGrid.component.js index 300d861d0f..59a846fa0d 100644 --- a/ext/search_kit/ang/crmSearchDisplayGrid/crmSearchDisplayGrid.component.js +++ b/ext/search_kit/ang/crmSearchDisplayGrid/crmSearchDisplayGrid.component.js @@ -17,8 +17,8 @@ templateUrl: '~/crmSearchDisplayGrid/crmSearchDisplayGrid.html', controller: function($scope, $element, searchDisplayBaseTrait) { var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'), - // Mix in properties of searchDisplayBaseTrait - ctrl = angular.extend(this, searchDisplayBaseTrait); + // Mix in a copy of searchDisplayBaseTrait + ctrl = angular.extend(this, _.cloneDeep(searchDisplayBaseTrait)); this.$onInit = function() { this.initializeDisplay($scope, $element); diff --git a/ext/search_kit/ang/crmSearchDisplayList/crmSearchDisplayList.component.js b/ext/search_kit/ang/crmSearchDisplayList/crmSearchDisplayList.component.js index 7982f36307..6a2b72431a 100644 --- a/ext/search_kit/ang/crmSearchDisplayList/crmSearchDisplayList.component.js +++ b/ext/search_kit/ang/crmSearchDisplayList/crmSearchDisplayList.component.js @@ -17,8 +17,8 @@ templateUrl: '~/crmSearchDisplayList/crmSearchDisplayList.html', controller: function($scope, $element, searchDisplayBaseTrait) { var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'), - // Mix in properties of searchDisplayBaseTrait - ctrl = angular.extend(this, searchDisplayBaseTrait); + // Mix in a copy of searchDisplayBaseTrait + ctrl = angular.extend(this, _.cloneDeep(searchDisplayBaseTrait)); this.$onInit = function() { this.initializeDisplay($scope, $element); diff --git a/ext/search_kit/ang/crmSearchDisplayTable/crmSearchDisplayTable.component.js b/ext/search_kit/ang/crmSearchDisplayTable/crmSearchDisplayTable.component.js index ed0b95042e..04f8120ffa 100644 --- a/ext/search_kit/ang/crmSearchDisplayTable/crmSearchDisplayTable.component.js +++ b/ext/search_kit/ang/crmSearchDisplayTable/crmSearchDisplayTable.component.js @@ -16,8 +16,8 @@ templateUrl: '~/crmSearchDisplayTable/crmSearchDisplayTable.html', controller: function($scope, $element, searchDisplayBaseTrait, searchDisplayTasksTrait, searchDisplaySortableTrait, crmApi4) { var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'), - // Mix in traits to this controller - ctrl = angular.extend(this, searchDisplayBaseTrait, searchDisplayTasksTrait, searchDisplaySortableTrait); + // Mix in copies of traits to this controller + ctrl = angular.extend(this, _.cloneDeep(searchDisplayBaseTrait), _.cloneDeep(searchDisplayTasksTrait), _.cloneDeep(searchDisplaySortableTrait)); this.$onInit = function() { var tallyParams; -- 2.25.1