SearchKit - Customizable "No Results" text
authorColeman Watts <coleman@civicrm.org>
Mon, 14 Feb 2022 15:30:37 +0000 (10:30 -0500)
committerColeman Watts <coleman@civicrm.org>
Mon, 14 Feb 2022 15:31:42 +0000 (10:31 -0500)
ext/search_kit/ang/crmSearchAdmin/displays/searchAdminDisplayTable.html
ext/search_kit/ang/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.component.js
ext/search_kit/ang/crmSearchDisplayTable/crmSearchDisplayTableBody.html

index 4794ea0e409a2f3de6eac023fce7b039c2656267..3a8a214ff86b19e1a389341c698fb5bdb94ff0eb 100644 (file)
   </div>
   <search-admin-css-rules label="{{:: ts('Row Style') }}" item="$ctrl.display.settings"></search-admin-css-rules>
   <search-admin-pager-config display="$ctrl.display"></search-admin-pager-config>
+  <div class="form-inline crm-search-admin-flex-row" title="{{:: ts('Text to display if the table is empty.') }}">
+    <label for="crm-search-admin-display-no-results-text">{{:: ts('No Results Text') }}</label>
+    <input class="form-control crm-flex-1" id="crm-search-admin-display-no-results-text" ng-model="$ctrl.display.settings.noResultsText" placeholder="{{:: ts('None found.') }}">
+  </div>
 </fieldset>
 <fieldset class="crm-search-admin-edit-columns-wrapper">
   <legend>
index 46cea6c5a7816bed49760ed06e32daf74d2947a0..110ce193a12033a707f9cf8f970f39b466aafa25 100644 (file)
         this.initializeDisplay($scope, $element);
         // Keep tab counts up-to-date - put rowCount in current tab if there are no other filters
         $scope.$watch('$ctrl.rowCount', function(val) {
-          if (typeof val === 'number' && angular.equals(['has_base'], _.keys(ctrl.filters))) {
+          if (typeof val === 'number' && angular.equals(['has_base'], getActiveFilters())) {
             ctrl.tabCount = val;
           }
         });
+        // Customize the noResultsText
+        $scope.$watch('$ctrl.filters', function() {
+          ctrl.settings.noResultsText = (angular.equals(['has_base'], getActiveFilters())) ?
+            ts('Welcome to Search Kit. Click the New Search button above to start composing your first search.') :
+            ts('No Saved Searches match filter criteria.');
+        }, true);
       };
 
+      // Get the names of in-use filters
+      function getActiveFilters() {
+        return _.keys(_.pick(ctrl.filters, function(val) {
+          return val !== null && (val === true || val === false || val.length);
+        }));
+      }
+
       this.onPostRun.push(function(result) {
         _.each(result, function(row) {
           row.permissionToEdit = CRM.checkPerm('all CiviCRM permissions and ACLs') || !_.includes(row.data.display_acl_bypass, true);
index 1bb55193a4f431cb46beef807b508842937716ee..e1310ae63b39c3c626bd919470a96978173025ff 100644 (file)
@@ -11,7 +11,7 @@
 <tr ng-if="$ctrl.rowCount === 0">
   <td colspan="{{ $ctrl.settings.columns.length + 2 }}">
     <p class="alert alert-info text-center">
-      {{:: ts('None Found') }}
+      {{ $ctrl.settings.noResultsText || ts('None Found') }}
     </p>
   </td>
 </tr>