SearchKit - Only allow real fields to be sortable
authorColeman Watts <coleman@civicrm.org>
Wed, 15 Sep 2021 22:01:48 +0000 (18:01 -0400)
committerColeman Watts <coleman@civicrm.org>
Wed, 15 Sep 2021 22:01:48 +0000 (18:01 -0400)
ext/search_kit/ang/crmSearchAdmin.module.js
ext/search_kit/ang/crmSearchAdmin/displays/searchAdminDisplayTable.component.js
ext/search_kit/ang/crmSearchAdmin/resultsTable/crmSearchAdminResultsTable.component.js
ext/search_kit/ang/crmSearchAdmin/resultsTable/crmSearchAdminResultsTable.html
ext/search_kit/ang/crmSearchDisplay/traits/searchDisplaySortableTrait.service.js
ext/search_kit/ang/crmSearchDisplayTable/crmSearchDisplayTable.html

index 207c10670d300b9aa8d0ce74de8cea505703f69c..a3688afa9bf4ecbfb7dea172d66fff90eac11f7b 100644 (file)
         if (defaults.label === true) {
           values.label = getDefaultLabel(fieldExpr);
         }
+        if (defaults.sortable) {
+          values.sortable = (info.field.type === 'Field');
+        }
         return values;
       }
       return {
index 7d546a38ef0b656d83bd25009a63eececd8d6e71..c4df08c5c5da9a454188e24b53e17f184472ad1f 100644 (file)
@@ -43,7 +43,7 @@
         }
         // Displays created prior to 5.43 may not have this property
         ctrl.display.settings.classes = ctrl.display.settings.classes || [];
-        ctrl.parent.initColumns({label: true});
+        ctrl.parent.initColumns({label: true, sortable: true});
       };
 
     }
index 2329ade4eaa8cf56c4d3f336f25c2166dc193e53..025f1e60632fe767d264cca2668c7ea6de158a36 100644 (file)
@@ -37,7 +37,7 @@
             classes: ['table', 'table-striped'],
             button: ts('Search'),
             columns: _.transform(ctrl.search.api_params.select, function(columns, fieldExpr) {
-              var column = {label: true},
+              var column = {label: true, sortable: true},
                 link = getViewLink(fieldExpr, links);
               if (link) {
                 column.title = link.title;
index ab98ae853453eaed0b92f48cfaa51b7977c99da4..f8c04f2f6cfe6b088e520acb98736067ed604653 100644 (file)
@@ -11,7 +11,7 @@
           <input type="checkbox" ng-disabled="$ctrl.loading || !$ctrl.results.length" ng-checked="$ctrl.allRowsSelected" ng-click="$ctrl.selectAllRows()" >
         </th>
         <th ng-repeat="item in $ctrl.search.api_params.select" ng-click="$ctrl.setSort($ctrl.settings.columns[$index], $event)" title="{{$index || !$ctrl.crmSearchAdmin.groupExists ? ts('Drag to reorder columns, click to sort results (shift-click to sort by multiple).') : ts('Column reserved for smart group.')}}">
-          <i class="crm-i {{ $ctrl.getSort($ctrl.settings.columns[$index]) }}"></i>
+          <i ng-if=":: $ctrl.isSortable($ctrl.settings.columns[$index])" class="crm-i {{ $ctrl.getSort($ctrl.settings.columns[$index]) }}"></i>
           <span ng-class="{'crm-draggable': $index || !$ctrl.crmSearchAdmin.groupExists}">{{ $ctrl.settings.columns[$index].label }}</span>
           <span ng-switch="$index || !$ctrl.crmSearchAdmin.groupExists ? 'sortable' : 'locked'">
             <i ng-switch-when="locked" class="crm-i fa-lock" aria-hidden="true"></i>
index 207da88e10e9f0a96c482a38fb51de4414692bdd..403ddeab5398fffd752fc4684ed0053aca39a0ce 100644 (file)
 
       sort: [],
 
+      isSortable: function(col) {
+        return col.type === 'field' && col.sortable !== false;
+      },
+
       getSort: function(col) {
         var dir = _.reduce(this.sort, function(dir, item) {
           return item[0] === col.key ? item[1] : dir;
@@ -21,7 +25,7 @@
       },
 
       setSort: function(col, $event) {
-        if (col.type !== 'field') {
+        if (!this.isSortable(col)) {
           return;
         }
         var dir = this.getSort(col) === 'fa-sort-asc' ? 'DESC' : 'ASC';
index f3bd7b697bf5cfd2deb5d95936af3e4ca67d1a54..5857239c13684814984f958f3c61e95f1c4fa488 100644 (file)
@@ -9,8 +9,8 @@
         <th class="crm-search-result-select" ng-if=":: $ctrl.settings.actions">
           <input type="checkbox" ng-disabled="$ctrl.loading || !$ctrl.results.length" ng-checked="$ctrl.allRowsSelected" ng-click="$ctrl.selectAllRows()" >
         </th>
-        <th ng-repeat="col in $ctrl.settings.columns" ng-click="$ctrl.setSort(col, $event)" title="{{:: col.type === 'field' ? ts('Click to sort results (shift-click to sort by multiple).') : '' }}">
-          <i ng-if=":: col.type === 'field'" class="crm-i {{ $ctrl.getSort(col) }}"></i>
+        <th ng-repeat="col in $ctrl.settings.columns" ng-click="$ctrl.setSort(col, $event)" title="{{:: $ctrl.isSortable(col) ? ts('Click to sort results (shift-click to sort by multiple).') : '' }}">
+          <i ng-if=":: $ctrl.isSortable(col)" class="crm-i {{ $ctrl.getSort(col) }}"></i>
           <span>{{:: col.label }}</span>
         </th>
       </tr>