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, event & primary address dropdowns #24963

Merged
merged 4 commits into from
Nov 16, 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
11 changes: 10 additions & 1 deletion CRM/Campaign/DAO/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Campaign/Campaign.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:99376d5b37f09370bab36f3a3cd37e0a)
* (GenCodeChecksum:0db877ff95e04216a2c4553e5e1f0594)
*/

/**
Expand Down Expand Up @@ -276,6 +276,7 @@ public static function &fields() {
'localizable' => 0,
'html' => [
'type' => 'Number',
'label' => ts("ID"),
],
'readonly' => TRUE,
'add' => '3.3',
Expand All @@ -297,6 +298,7 @@ public static function &fields() {
'localizable' => 0,
'html' => [
'type' => 'Text',
'label' => ts("Name"),
],
'add' => '3.3',
],
Expand All @@ -316,6 +318,7 @@ public static function &fields() {
'localizable' => 0,
'html' => [
'type' => 'Text',
'label' => ts("Title"),
],
'add' => '3.3',
],
Expand All @@ -333,6 +336,7 @@ public static function &fields() {
'localizable' => 0,
'html' => [
'type' => 'TextArea',
'label' => ts("Description"),
],
'add' => '3.3',
],
Expand All @@ -352,6 +356,7 @@ public static function &fields() {
'html' => [
'type' => 'Select Date',
'formatType' => 'activityDateTime',
'label' => ts("Start Date"),
],
'add' => '3.3',
],
Expand All @@ -371,6 +376,7 @@ public static function &fields() {
'html' => [
'type' => 'Select Date',
'formatType' => 'activityDateTime',
'label' => ts("End Date"),
],
'add' => '3.3',
],
Expand All @@ -389,6 +395,7 @@ public static function &fields() {
'localizable' => 0,
'html' => [
'type' => 'Select',
'label' => ts("Type"),
],
'pseudoconstant' => [
'optionGroupName' => 'campaign_type',
Expand All @@ -411,6 +418,7 @@ public static function &fields() {
'localizable' => 0,
'html' => [
'type' => 'Select',
'label' => ts("Status"),
],
'pseudoconstant' => [
'optionGroupName' => 'campaign_status',
Expand All @@ -436,6 +444,7 @@ public static function &fields() {
'localizable' => 0,
'html' => [
'type' => 'Text',
'label' => ts("External ID"),
],
'add' => '3.3',
],
Expand Down
4 changes: 4 additions & 0 deletions CRM/Core/I18n/SchemaStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,14 +624,17 @@ public static function &widgets() {
],
'civicrm_event' => [
'title' => [
'label' => "Title",
'type' => "Text",
],
'summary' => [
'label' => "Summary",
'type' => "TextArea",
'rows' => "4",
'cols' => "60",
],
'description' => [
'label' => "Description",
'type' => "RichTextEditor",
'rows' => "8",
'cols' => "60",
Expand All @@ -640,6 +643,7 @@ public static function &widgets() {
'type' => "Text",
],
'event_full_text' => [
'label' => "Event Full Message",
'type' => "TextArea",
'rows' => "4",
'cols' => "60",
Expand Down
13 changes: 12 additions & 1 deletion CRM/Event/DAO/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Event/Event.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:52019312abec7e5c00cc499d0c547ef0)
* (GenCodeChecksum:82ed6a487ce2639e83cada1ac876c895)
*/

/**
Expand Down Expand Up @@ -740,6 +740,7 @@ public static function &fields() {
'localizable' => 0,
'html' => [
'type' => 'Number',
'label' => ts("ID"),
],
'readonly' => TRUE,
'add' => '1.7',
Expand All @@ -761,6 +762,7 @@ public static function &fields() {
'localizable' => 1,
'html' => [
'type' => 'Text',
'label' => ts("Title"),
],
'add' => '1.7',
],
Expand All @@ -778,6 +780,7 @@ public static function &fields() {
'localizable' => 1,
'html' => [
'type' => 'TextArea',
'label' => ts("Summary"),
],
'add' => '1.7',
],
Expand All @@ -795,6 +798,7 @@ public static function &fields() {
'localizable' => 1,
'html' => [
'type' => 'RichTextEditor',
'label' => ts("Description"),
],
'add' => '1.7',
],
Expand All @@ -811,6 +815,7 @@ public static function &fields() {
'localizable' => 0,
'html' => [
'type' => 'Select',
'label' => ts("Type"),
],
'pseudoconstant' => [
'optionGroupName' => 'event_type',
Expand Down Expand Up @@ -852,6 +857,7 @@ public static function &fields() {
'localizable' => 0,
'html' => [
'type' => 'CheckBox',
'label' => ts("Public"),
],
'add' => '1.7',
],
Expand All @@ -871,6 +877,7 @@ public static function &fields() {
'html' => [
'type' => 'Select Date',
'formatType' => 'activityDateTime',
'label' => ts("Start Date"),
],
'add' => '1.7',
],
Expand All @@ -890,6 +897,7 @@ public static function &fields() {
'html' => [
'type' => 'Select Date',
'formatType' => 'activityDateTime',
'label' => ts("End Date"),
],
'add' => '1.7',
],
Expand All @@ -907,6 +915,7 @@ public static function &fields() {
'localizable' => 0,
'html' => [
'type' => 'CheckBox',
'label' => ts("Online Registration"),
],
'add' => '1.7',
],
Expand Down Expand Up @@ -991,6 +1000,7 @@ public static function &fields() {
'localizable' => 1,
'html' => [
'type' => 'TextArea',
'label' => ts("Event Full Message"),
],
'add' => '1.7',
],
Expand All @@ -1008,6 +1018,7 @@ public static function &fields() {
'localizable' => 0,
'html' => [
'type' => 'CheckBox',
'label' => ts("Paid Event"),
],
'add' => '1.7',
],
Expand Down
50 changes: 50 additions & 0 deletions Civi/Api4/Service/Autocomplete/CountryAutocompleteProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

namespace Civi\Api4\Service\Autocomplete;

use Civi\Core\Event\GenericHookEvent;
use Civi\Core\HookInterface;

/**
* @service
* @internal
*/
class CountryAutocompleteProvider extends \Civi\Core\Service\AutoService implements HookInterface {

/**
* Provide default SearchDisplay for Country autocompletes
*
* @param \Civi\Core\Event\GenericHookEvent $e
*/
public static function on_civi_search_defaultDisplay(GenericHookEvent $e) {
if ($e->display['settings'] || $e->display['type'] !== 'autocomplete' || $e->savedSearch['api_entity'] !== 'Country') {
return;
}
$e->display['settings'] = [
'sort' => [
['name', 'ASC'],
],
'columns' => [
[
'type' => 'field',
'key' => 'name',
],
[
'type' => 'field',
'key' => 'iso_code',
],
],
];
}

}
3 changes: 2 additions & 1 deletion ang/crmUi.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,8 @@
$timeout(function() {
$element.crmAutocomplete(ctrl.entity, ctrl.crmAutocompleteParams, {
multiple: ctrl.multi,
minimumInputLength: ctrl.autoOpen && !ctrl.staticOptions ? 0 : 1,
// Only auto-open if there are no static options
minimumInputLength: ctrl.autoOpen && _.isEmpty(ctrl.staticOptions) ? 0 : 1,
static: ctrl.staticOptions || [],
});
});
Expand Down
5 changes: 4 additions & 1 deletion ext/search_kit/ang/crmSearchAdmin.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,10 @@
entity.optionsLoaded = false;
entitiesToLoad[entityName] = [entityName, 'getFields', {
loadOptions: ['id', 'name', 'label', 'description', 'color', 'icon'],
where: [['options', '!=', false]],
// 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']],
select: ['options']
}, {name: 'options'}];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,8 @@
prefix = typeof prefix === 'undefined' ? '' : prefix;
_.each(fields, function(field) {
var item = {
id: prefix + field.name + (field.suffixes && _.includes(field.suffixes, suffix.replace(':', '')) ? suffix : ''),
// 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 : ''),
text: field.label,
description: field.description
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,16 @@
return '~/crmSearchTasks/crmSearchInput/boolean.html';
}

if (field.options) {
return '~/crmSearchTasks/crmSearchInput/select.html';
}

if ((field.fk_entity || field.name === 'id') && !_.includes(['>', '<', '>=', '<='], ctrl.op)) {
return '~/crmSearchTasks/crmSearchInput/entityRef.html';
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) {
return '~/crmSearchTasks/crmSearchInput/select.html';
}
}

if (field.data_type === 'Integer') {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Utils/TokenConsistencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ protected function getEventTokens(): array {
'{event.title}' => 'Event Title',
'{event.start_date}' => 'Event Start Date',
'{event.end_date}' => 'Event End Date',
'{event.event_type_id:label}' => 'Event Type',
'{event.event_type_id:label}' => 'Type',
'{event.summary}' => 'Event Summary',
'{event.contact_email}' => 'Event Contact Email',
'{event.contact_phone}' => 'Event Contact Phone',
Expand Down
10 changes: 10 additions & 0 deletions xml/schema/Campaign/Campaign.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<import>true</import>
<html>
<type>Number</type>
<label>ID</label>
</html>
<add>3.3</add>
</field>
Expand All @@ -41,6 +42,7 @@
<import>true</import>
<html>
<type>Text</type>
<label>Name</label>
</html>
<add>3.3</add>
</field>
Expand All @@ -58,6 +60,7 @@
<import>true</import>
<html>
<type>Text</type>
<label>Title</label>
</html>
<add>3.3</add>
</field>
Expand All @@ -70,6 +73,7 @@
<type>TextArea</type>
<rows>8</rows>
<cols>60</cols>
<label>Description</label>
</html>
<comment>Full description of Campaign.</comment>
<add>3.3</add>
Expand All @@ -83,6 +87,7 @@
<comment>Date and time that Campaign starts.</comment>
<import>true</import>
<html>
<label>Start Date</label>
<type>Select Date</type>
<formatType>activityDateTime</formatType>
</html>
Expand All @@ -97,6 +102,7 @@
<comment>Date and time that Campaign ends.</comment>
<import>true</import>
<html>
<label>End Date</label>
<type>Select Date</type>
<formatType>activityDateTime</formatType>
</html>
Expand All @@ -114,6 +120,7 @@
<optionGroupName>campaign_type</optionGroupName>
</pseudoconstant>
<html>
<label>Type</label>
<type>Select</type>
</html>
<add>3.3</add>
Expand All @@ -135,6 +142,7 @@
<optionGroupName>campaign_status</optionGroupName>
</pseudoconstant>
<html>
<label>Status</label>
<type>Select</type>
</html>
<add>3.3</add>
Expand All @@ -156,6 +164,7 @@
<import>true</import>
<add>3.3</add>
<html>
<label>External ID</label>
<type>Text</type>
</html>
</field>
Expand Down Expand Up @@ -196,6 +205,7 @@
<comment>Is this Campaign enabled or disabled/cancelled?</comment>
<add>3.3</add>
<html>
<label>Enabled</label>
<type>CheckBox</type>
<label>Enabled</label>
</html>
Expand Down
Loading