Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SearchKit - Fix aggregated joins #21411

Merged
merged 2 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand All @@ -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));
}

/**
Expand Down
3 changes: 3 additions & 0 deletions ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
}
})
});
}
Expand Down