@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

In Herald transcripts, render some field values in a more readable way

Summary:
Ref T13480. Currently, some Herald field types are rendered in an unfriendly way on transcripts. Particularly, PHID lists are rendered as raw PHIDs.

Improve this by delegating rendering to Value objects and letting "PHID List" value objects render more sensible handle lists. Also improve "bool" fields a bit and make more fields render an explicit "None" / empty value rather than just rendering nothing.

Test Plan: Viewed various transcripts, including transcripts covering boolean values, the "Always" condition, large blocks of text, and PHID lists.

Maniphest Tasks: T13480

Differential Revision: https://secure.phabricator.com/D20951

+131 -29
+2
src/__phutil_library_map__.php
··· 1528 1528 'HeraldApplicationActionGroup' => 'applications/herald/action/HeraldApplicationActionGroup.php', 1529 1529 'HeraldApplyTranscript' => 'applications/herald/storage/transcript/HeraldApplyTranscript.php', 1530 1530 'HeraldBasicFieldGroup' => 'applications/herald/field/HeraldBasicFieldGroup.php', 1531 + 'HeraldBoolFieldValue' => 'applications/herald/value/HeraldBoolFieldValue.php', 1531 1532 'HeraldBuildableState' => 'applications/herald/state/HeraldBuildableState.php', 1532 1533 'HeraldCallWebhookAction' => 'applications/herald/action/HeraldCallWebhookAction.php', 1533 1534 'HeraldCommentAction' => 'applications/herald/action/HeraldCommentAction.php', ··· 7633 7634 'HeraldApplicationActionGroup' => 'HeraldActionGroup', 7634 7635 'HeraldApplyTranscript' => 'Phobject', 7635 7636 'HeraldBasicFieldGroup' => 'HeraldFieldGroup', 7637 + 'HeraldBoolFieldValue' => 'HeraldFieldValue', 7636 7638 'HeraldBuildableState' => 'HeraldState', 7637 7639 'HeraldCallWebhookAction' => 'HeraldAction', 7638 7640 'HeraldCommentAction' => 'HeraldAction',
+20
src/applications/herald/adapter/HeraldAdapter.php
··· 1071 1071 $condition->getValue()); 1072 1072 } 1073 1073 1074 + public function renderFieldTranscriptValue( 1075 + PhabricatorUser $viewer, 1076 + $field_type, 1077 + $field_value) { 1078 + 1079 + $field = $this->getFieldImplementation($field_type); 1080 + if ($field) { 1081 + return $field->renderTranscriptValue( 1082 + $viewer, 1083 + $field_value); 1084 + } 1085 + 1086 + return phutil_tag( 1087 + 'em', 1088 + array(), 1089 + pht( 1090 + 'Unable to render value for unknown field type ("%s").', 1091 + $field_type)); 1092 + } 1093 + 1074 1094 1075 1095 /* -( Applying Effects )--------------------------------------------------- */ 1076 1096
+11 -18
src/applications/herald/controller/HeraldTranscriptController.php
··· 447 447 } 448 448 449 449 private function buildObjectTranscriptPanel(HeraldTranscript $xscript) { 450 + $viewer = $this->getViewer(); 451 + $adapter = $this->getAdapter(); 450 452 451 - $adapter = $this->getAdapter(); 452 453 $field_names = $adapter->getFieldNameMap(); 453 454 454 455 $object_xscript = $xscript->getObjectTranscript(); ··· 487 488 } 488 489 489 490 if ($object_xscript) { 490 - foreach ($object_xscript->getFields() as $field => $value) { 491 - if (isset($field_names[$field])) { 492 - $field_name = pht('Field: %s', $field_names[$field]); 491 + foreach ($object_xscript->getFields() as $field_type => $value) { 492 + if (isset($field_names[$field_type])) { 493 + $field_name = pht('Field: %s', $field_names[$field_type]); 493 494 } else { 494 - $field_name = pht('Unknown Field ("%s")', $field_name); 495 + $field_name = pht('Unknown Field ("%s")', $field_type); 495 496 } 496 497 497 - if (!is_scalar($value) && !is_null($value)) { 498 - $value = implode("\n", $value); 499 - } 500 - 501 - if (strlen($value) > 256) { 502 - $value = phutil_tag( 503 - 'textarea', 504 - array( 505 - 'class' => 'herald-field-value-transcript', 506 - ), 507 - $value); 508 - } 498 + $field_value = $adapter->renderFieldTranscriptValue( 499 + $viewer, 500 + $field_type, 501 + $value); 509 502 510 503 $rows[] = array( 511 504 $field_name, 512 - $value, 505 + $field_value, 513 506 ); 514 507 } 515 508 }
+1 -1
src/applications/herald/field/HeraldAlwaysField.php
··· 23 23 } 24 24 25 25 public function getHeraldFieldValueType($condition) { 26 - return new HeraldEmptyFieldValue(); 26 + return new HeraldBoolFieldValue(); 27 27 } 28 28 29 29 public function supportsObject($object) {
+14 -1
src/applications/herald/field/HeraldField.php
··· 105 105 } 106 106 107 107 public function getHeraldFieldValueType($condition) { 108 + 109 + // NOTE: The condition type may be "null" to indicate that the caller 110 + // wants a generic field value type. This is used when rendering field 111 + // values in the object transcript. 112 + 108 113 $standard_type = $this->getHeraldFieldStandardType(); 109 114 switch ($standard_type) { 110 115 case self::STANDARD_BOOL: 111 116 case self::STANDARD_PHID_BOOL: 112 - return new HeraldEmptyFieldValue(); 117 + return new HeraldBoolFieldValue(); 113 118 case self::STANDARD_TEXT: 114 119 case self::STANDARD_TEXT_LIST: 115 120 case self::STANDARD_TEXT_MAP: ··· 174 179 $value_type = $this->getHeraldFieldValueType($condition); 175 180 $value_type->setViewer($viewer); 176 181 return $value_type->renderEditorValue($value); 182 + } 183 + 184 + public function renderTranscriptValue( 185 + PhabricatorUser $viewer, 186 + $field_value) { 187 + $value_type = $this->getHeraldFieldValueType($condition_type = null); 188 + $value_type->setViewer($viewer); 189 + return $value_type->renderTranscriptValue($field_value); 177 190 } 178 191 179 192 public function getPHIDsAffectedByCondition(HeraldCondition $condition) {
+30
src/applications/herald/value/HeraldBoolFieldValue.php
··· 1 + <?php 2 + 3 + final class HeraldBoolFieldValue 4 + extends HeraldFieldValue { 5 + 6 + public function getFieldValueKey() { 7 + return 'bool'; 8 + } 9 + 10 + public function getControlType() { 11 + return self::CONTROL_NONE; 12 + } 13 + 14 + public function renderFieldValue($value) { 15 + return null; 16 + } 17 + 18 + public function renderEditorValue($value) { 19 + return null; 20 + } 21 + 22 + public function renderTranscriptValue($value) { 23 + if ($value) { 24 + return pht('true'); 25 + } else { 26 + return pht('false'); 27 + } 28 + } 29 + 30 + }
+4
src/applications/herald/value/HeraldFieldValue.php
··· 36 36 return array(); 37 37 } 38 38 39 + public function renderTranscriptValue($value) { 40 + return $this->renderFieldValue($value); 41 + } 42 + 39 43 }
+21
src/applications/herald/value/HeraldTextFieldValue.php
··· 19 19 return $value; 20 20 } 21 21 22 + public function renderTranscriptValue($value) { 23 + if (is_array($value)) { 24 + $value = implode('', $value); 25 + } 26 + 27 + if (!strlen($value)) { 28 + return phutil_tag('em', array(), pht('None')); 29 + } 30 + 31 + if (strlen($value) > 256) { 32 + $value = phutil_tag( 33 + 'textarea', 34 + array( 35 + 'class' => 'herald-field-value-transcript', 36 + ), 37 + $value); 38 + } 39 + 40 + return $value; 41 + } 42 + 22 43 }
+28 -9
src/applications/herald/value/HeraldTokenizerFieldValue.php
··· 64 64 } 65 65 66 66 public function renderFieldValue($value) { 67 + return $this->renderValueAsList($value, $for_transcript = false); 68 + } 69 + 70 + public function renderEditorValue($value) { 67 71 $viewer = $this->getViewer(); 68 72 $value = (array)$value; 69 73 74 + $datasource = $this->getDatasource() 75 + ->setViewer($viewer); 76 + 77 + return $datasource->getWireTokens($value); 78 + } 79 + 80 + public function renderTranscriptValue($value) { 81 + return $this->renderValueAsList($value, $for_transcript = true); 82 + } 83 + 84 + private function renderValueAsList($value, $for_transcript) { 85 + $viewer = $this->getViewer(); 86 + $value = (array)$value; 87 + 88 + if (!$value) { 89 + return phutil_tag('em', array(), pht('None')); 90 + } 91 + 70 92 if ($this->valueMap !== null) { 71 93 foreach ($value as $k => $v) { 72 94 $value[$k] = idx($this->valueMap, $v, $v); 73 95 } 96 + 74 97 return implode(', ', $value); 75 98 } 76 99 77 - return $viewer->renderHandleList((array)$value)->setAsInline(true); 78 - } 79 - 80 - public function renderEditorValue($value) { 81 - $viewer = $this->getViewer(); 82 - $value = (array)$value; 100 + $list = $viewer->renderHandleList($value); 83 101 84 - $datasource = $this->getDatasource() 85 - ->setViewer($viewer); 102 + if (!$for_transcript) { 103 + $list->setAsInline(true); 104 + } 86 105 87 - return $datasource->getWireTokens($value); 106 + return $list; 88 107 } 89 108 90 109 }