Skip to content

Commit

Permalink
Merge pull request #25053 from colemanw/fixStateCampaignSelectors
Browse files Browse the repository at this point in the history
SearchKit - Fix Campaign, State, Country selectors (again)
  • Loading branch information
eileenmcnaughton authored Nov 30, 2022
2 parents c8af6e2 + 5511ef1 commit 66daecc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
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

0 comments on commit 66daecc

Please sign in to comment.