From: Coleman Watts Date: Thu, 21 Apr 2022 14:07:44 +0000 (-0400) Subject: SearchKit - Fix aggregation issues X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=587f387746091091aa575e7cfdc72233c75308ea;p=civicrm-core.git SearchKit - Fix aggregation issues In the UI, "Extra" fields like Contact.age_years were not being aggregated properly. On the server, fixes mismatch when checking an aggregate field with a suffix. Fixes recent test regression. --- diff --git a/ext/search_kit/Civi/Api4/Action/SearchDisplay/SavedSearchInspectorTrait.php b/ext/search_kit/Civi/Api4/Action/SearchDisplay/SavedSearchInspectorTrait.php index a1157b3c07..1f935a4619 100644 --- a/ext/search_kit/Civi/Api4/Action/SearchDisplay/SavedSearchInspectorTrait.php +++ b/ext/search_kit/Civi/Api4/Action/SearchDisplay/SavedSearchInspectorTrait.php @@ -157,8 +157,10 @@ trait SavedSearchInspectorTrait { * @return bool */ private function canAggregate($fieldPath) { - $apiParams = $this->savedSearch['api_params'] ?? []; + // Disregard suffix + [$fieldPath] = explode(':', $fieldPath); $field = $this->getField($fieldPath); + $apiParams = $this->savedSearch['api_params'] ?? []; // If the query does not use grouping or the field doesn't exist, never if (empty($apiParams['groupBy']) || !$field) { @@ -170,8 +172,7 @@ trait SavedSearchInspectorTrait { } // If the entity this column belongs to is being grouped by id, then also no - $suffix = strstr($fieldPath, ':') ?: ''; - $idField = substr($fieldPath, 0, 0 - strlen($field['name'] . $suffix)) . CoreUtil::getIdFieldName($field['entity']); + $idField = substr($fieldPath, 0, 0 - strlen($field['name'])) . CoreUtil::getIdFieldName($field['entity']); return !in_array($idField, $apiParams['groupBy']); } diff --git a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js index bf6311ebbb..d95e711e80 100644 --- a/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js +++ b/ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js @@ -430,7 +430,7 @@ } var arg = _.findWhere(searchMeta.parseExpr(col).args, {type: 'field'}) || {}; // If the column is not a database field, no - if (!arg.field || !arg.field.entity || !_.includes(['Field', 'Custom'], arg.field.type)) { + if (!arg.field || !arg.field.entity || !_.includes(['Field', 'Custom', 'Extra'], arg.field.type)) { return false; } // If the column is used for a groupBy, no