diff --git a/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php b/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php index 03d392d51189..d18254c7c1b9 100644 --- a/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php +++ b/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php @@ -319,6 +319,9 @@ protected function getOrderByFromSort() { * @param array $apiParams */ protected function augmentSelectClause(&$apiParams): void { + $existing = array_map(function($item) { + return explode(' AS ', $item)[1] ?? $item; + }, $apiParams['select']); $additions = []; // Add primary key field if actions are enabled if (!empty($this->display['settings']['actions'])) { @@ -334,14 +337,16 @@ protected function augmentSelectClause(&$apiParams): void { } // Select value fields for in-place editing - if (isset($column['editable']['value']) && !in_array($column['editable']['value'], $apiParams['select'])) { - $apiParams['select'][] = $column['editable']['value']; + if (isset($column['editable']['value'])) { + $additions[] = $column['editable']['value']; } } // Add fields referenced via token $tokens = []; preg_match_all('/\\[([^]]+)\\]/', $possibleTokens, $tokens); - $apiParams['select'] = array_unique(array_merge($apiParams['select'], $additions, $tokens[1])); + // Only add fields not already in SELECT clause + $additions = array_diff(array_merge($additions, $tokens[1]), $existing); + $apiParams['select'] = array_unique(array_merge($apiParams['select'], $additions)); } /** diff --git a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js index d8f13c449d39..c53ffc7e3a50 100644 --- a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js +++ b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js @@ -613,9 +613,12 @@ _.each(ctrl.savedSearch.api_params.join, function(joinClause) { var join = searchMeta.getJoin(joinClause[0]), joinEntity = searchMeta.getEntity(join.entity), + primaryKey = joinEntity.primary_key[0], + isAggregate = ctrl.canAggregate(join.alias + '.' + primaryKey), bridgeEntity = _.isString(joinClause[2]) ? searchMeta.getEntity(joinClause[2]) : null; _.each(joinEntity.paths, function(path) { var link = _.cloneDeep(path); + link.isAggregate = isAggregate; link.path = link.path.replace(/\[/g, '[' + join.alias + '.'); link.join = join.alias; addTitle(link, join.label); diff --git a/ext/search_kit/ang/crmSearchAdmin/resultsTable/crmSearchAdminResultsTable.component.js b/ext/search_kit/ang/crmSearchAdmin/resultsTable/crmSearchAdminResultsTable.component.js index 194449d167df..71f09c22ea1b 100644 --- a/ext/search_kit/ang/crmSearchAdmin/resultsTable/crmSearchAdminResultsTable.component.js +++ b/ext/search_kit/ang/crmSearchAdmin/resultsTable/crmSearchAdminResultsTable.component.js @@ -58,13 +58,15 @@ style: 'secondary-outline', alignment: 'text-right', links: _.transform(links, function(links, link) { - links.push({ - path: link.path, - text: link.title, - icon: link.icon, - style: link.style, - target: link.action === 'view' ? '_blank' : 'crm-popup' - }); + if (!link.isAggregate) { + links.push({ + path: link.path, + text: link.title, + icon: link.icon, + style: link.style, + target: link.action === 'view' ? '_blank' : 'crm-popup' + }); + } }) }); }