SearchKit - Fix in-place edit of relationships and dates
authorColeman Watts <coleman@civicrm.org>
Sun, 19 Sep 2021 01:37:03 +0000 (21:37 -0400)
committerColeman Watts <coleman@civicrm.org>
Sun, 19 Sep 2021 01:37:03 +0000 (21:37 -0400)
Date fields were not rendering correctly, and relationships
could not be edited due to the read-only nature of the relationshipCache table.

ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php
ext/search_kit/Civi/Search/Admin.php
ext/search_kit/ang/crmSearchAdmin/crmSearchAdminDisplay.component.js
ext/search_kit/ang/crmSearchDisplay/crmSearchDisplayEditable.component.js

index d2790dd47b5aa08699f9f0a08091f48cf586f11c..88451018d24b88e35f65cfd97836add9f3ca5f26 100644 (file)
@@ -380,6 +380,7 @@ abstract class AbstractRunAction extends \Civi\Api4\Generic\AbstractAction {
       // Select value fields for in-place editing
       if (isset($column['editable']['value'])) {
         $additions[] = $column['editable']['value'];
+        $additions[] = $column['editable']['id'];
       }
     }
     // Add fields referenced via token
index 9036b1c1b510be670a653a0999bb53a141d4125a..bec6337299d005a1d94f94991a3cdc1fcc861f39 100644 (file)
@@ -118,6 +118,13 @@ class Admin {
         ]);
         foreach ($getFields as $field) {
           $field['fieldName'] = $field['name'];
+          // Hack for RelationshipCache to make Relationship fields editable
+          if ($entity['name'] === 'RelationshipCache') {
+            $entity['primary_key'] = ['relationship_id'];
+            if (in_array($field['name'], ['is_active', 'start_date', 'end_date'])) {
+              $field['readonly'] = FALSE;
+            }
+          }
           $entity['fields'][] = $field;
         }
         $params = $entity['get'][0];
index 96e3947021ef48f17a56b6a8da50d59392618bb4..6fc1cfce2838d6a606423b18709d848dcbbb6bf9 100644 (file)
         }
 
         var info = searchMeta.parseExpr(col.key),
-          field = info.args[0] && info.args[0].field,
+          arg = _.findWhere(info.args, {type: 'field'}) || {},
           value = col.key.split(':')[0];
-        if (!field || info.fn) {
+        if (!arg.field || info.fn) {
           delete col.editable;
           return;
         }
         // If field is an implicit join, use the original fk field
-        if (field.name !== field.fieldName) {
+        if (arg.field.name !== arg.field.fieldName) {
           value = value.substr(0, value.lastIndexOf('.'));
           info = searchMeta.parseExpr(value);
-          field = info.args[0].field;
+          arg = info.args[0];
         }
         col.editable = {
-          entity: field.baseEntity,
-          options: !!field.options,
-          serialize: !!field.serialize,
-          fk_entity: field.fk_entity,
-          id: info.prefix + 'id',
-          name: field.name,
+          // Hack to support editing relationships
+          entity: arg.field.entity.replace('RelationshipCache', 'Relationship'),
+          input_type: arg.field.input_type,
+          data_type: arg.field.data_type,
+          options: !!arg.field.options,
+          serialize: !!arg.field.serialize,
+          fk_entity: arg.field.fk_entity,
+          id: arg.prefix + searchMeta.getEntity(arg.field.entity).primary_key[0],
+          name: arg.field.name,
           value: value
         };
       };
index b6b6957562d0b7d92a5763a70bde087296baa8c8..55cb13b943c70deb5f9acb715a5d6d4e847844d4 100644 (file)
@@ -23,7 +23,8 @@
         initialValue = _.cloneDeep(this.row[col.editable.value].raw);
 
         this.field = {
-          data_type: col.dataType,
+          data_type: col.editable.data_type,
+          input_type: col.editable.input_type,
           name: col.editable.name,
           options: col.editable.options,
           fk_entity: col.editable.fk_entity,