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 Campaign, State, Country selectors (again) #25053

Merged
merged 1 commit into from
Nov 30, 2022
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
7 changes: 6 additions & 1 deletion Civi/Api4/Service/Spec/Provider/AddressGetSpecProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ class AddressGetSpecProvider extends \Civi\Core\Service\AutoService implements G
* @param \Civi\Api4\Service\Spec\RequestSpec $spec
*/
public function modifySpec(RequestSpec $spec) {
// Groups field
// These fields do not have any sensible "name" pseudoconstant so should just use the ID
foreach (['state_province_id', 'country_id', 'county_id'] as $name) {
$spec->getFieldByName($name)->setSuffixes(['label', 'abbr']);
}

// Proximity search field
$field = new FieldSpec('proximity', 'Address', 'Boolean');
$field->setLabel(ts('Address Proximity'))
->setTitle(ts('Address Proximity'))
Expand Down
2 changes: 1 addition & 1 deletion ext/search_kit/ang/crmSearchAdmin.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@
// For fields with both an FK and an option list, prefer the FK
// because it's more efficient to render an autocomplete than to
// pre-load potentially thousands of options into a select dropdown.
where: [['options', '!=', false], ['fk_entity', 'IS NULL']],
where: [['options', '!=', false], ['suffixes', 'CONTAINS', 'name']],
select: ['options']
}, {name: 'options'}];
}
Expand Down
4 changes: 2 additions & 2 deletions ext/search_kit/ang/crmSearchAdmin/crmSearchAdmin.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,8 @@
prefix = typeof prefix === 'undefined' ? '' : prefix;
_.each(fields, function(field) {
var item = {
// Use suffix only if the field is not an FK. EntityRef fields look-up by id.
id: prefix + field.name + (!field.fk_entity && _.includes(field.suffixes || [], suffix.replace(':', '')) ? suffix : ''),
// Use options suffix if available.
id: prefix + field.name + (field.options && _.includes(field.suffixes || [], suffix.replace(':', '')) ? suffix : ''),
text: field.label,
description: field.description
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,13 @@
}

if (!_.includes(['>', '<', '>=', '<='], ctrl.op)) {
// For fields with both an FK and an option list, prefer the FK
// because it's more efficient to render an autocomplete than to
// pre-load potentially thousands of options into a select dropdown.
if ((field.fk_entity || field.name === 'id')) {
return '~/crmSearchTasks/crmSearchInput/entityRef.html';
}
if (field.options) {
// Only use option list if the field has a "name" suffix
if (field.options && field.suffixes && field.suffixes.includes('name')) {
return '~/crmSearchTasks/crmSearchInput/select.html';
}
if (field.fk_entity || field.name === 'id') {
return '~/crmSearchTasks/crmSearchInput/entityRef.html';
}
}

if (field.data_type === 'Integer') {
Expand Down