@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

Further modularize Herald values

Summary: Ref T8726. Modularize action values. Fully modularize "text", "none" and "select" controls. Only tokenizers remain.

Test Plan:
- Used all affected value types in UI.
- Reviewed rules using new modular rendering, saw sensible output.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T8726

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

+68 -77
+11 -11
resources/celerity/map.php
··· 382 382 'rsrc/js/application/doorkeeper/behavior-doorkeeper-tag.js' => 'e5822781', 383 383 'rsrc/js/application/files/behavior-icon-composer.js' => '8ef9ab58', 384 384 'rsrc/js/application/files/behavior-launch-icon-composer.js' => '48086888', 385 - 'rsrc/js/application/herald/HeraldRuleEditor.js' => '0f85bdfd', 385 + 'rsrc/js/application/herald/HeraldRuleEditor.js' => '797e4876', 386 386 'rsrc/js/application/herald/PathTypeahead.js' => 'f7fc67ec', 387 387 'rsrc/js/application/herald/herald-rule-editor.js' => '7ebaeed3', 388 388 'rsrc/js/application/maniphest/behavior-batch-editor.js' => '782ab6e7', ··· 538 538 'global-drag-and-drop-css' => '697324ad', 539 539 'harbormaster-css' => '49d64eb4', 540 540 'herald-css' => '826075fa', 541 - 'herald-rule-editor' => '0f85bdfd', 541 + 'herald-rule-editor' => '797e4876', 542 542 'herald-test-css' => '778b008e', 543 543 'inline-comment-summary-css' => '51efda3a', 544 544 'javelin-aphlict' => '5359e785', ··· 918 918 'javelin-install', 919 919 'javelin-util', 920 920 ), 921 - '0f85bdfd' => array( 922 - 'multirow-row-manager', 923 - 'javelin-install', 924 - 'javelin-util', 925 - 'javelin-dom', 926 - 'javelin-stratcom', 927 - 'javelin-json', 928 - 'phabricator-prefab', 929 - ), 930 921 '13c739ea' => array( 931 922 'javelin-behavior', 932 923 'javelin-stratcom', ··· 1424 1415 '7927a7d3' => array( 1425 1416 'javelin-behavior', 1426 1417 'javelin-quicksand', 1418 + ), 1419 + '797e4876' => array( 1420 + 'multirow-row-manager', 1421 + 'javelin-install', 1422 + 'javelin-util', 1423 + 'javelin-dom', 1424 + 'javelin-stratcom', 1425 + 'javelin-json', 1426 + 'phabricator-prefab', 1427 1427 ), 1428 1428 '7a68dda3' => array( 1429 1429 'owners-path-editor',
+5 -17
src/applications/diffusion/herald/DiffusionPreCommitRefChangeHeraldField.php
··· 21 21 } 22 22 23 23 public function getHeraldFieldValueType($condition) { 24 - return HeraldPreCommitRefAdapter::VALUE_REF_CHANGE; 25 - } 26 - 27 - public function renderConditionValue( 28 - PhabricatorUser $viewer, 29 - $value) { 30 - 31 - $change_map = 32 - PhabricatorRepositoryPushLog::getHeraldChangeFlagConditionOptions(); 33 - foreach ($value as $index => $val) { 34 - $name = idx($change_map, $val); 35 - if ($name) { 36 - $value[$index] = $name; 37 - } 38 - } 39 - 40 - return phutil_implode_html(', ', $value); 24 + return id(new HeraldSelectFieldValue()) 25 + ->setKey(self::FIELDCONST) 26 + ->setOptions( 27 + PhabricatorRepositoryPushLog::getHeraldChangeFlagConditionOptions()) 28 + ->setDefault(PhabricatorRepositoryPushLog::CHANGEFLAG_ADD); 41 29 } 42 30 43 31 }
+10 -1
src/applications/diffusion/herald/DiffusionPreCommitRefTypeHeraldField.php
··· 21 21 } 22 22 23 23 public function getHeraldFieldValueType($condition) { 24 - return HeraldPreCommitRefAdapter::VALUE_REF_TYPE; 24 + $types = array( 25 + PhabricatorRepositoryPushLog::REFTYPE_BRANCH => pht('branch (git/hg)'), 26 + PhabricatorRepositoryPushLog::REFTYPE_TAG => pht('tag (git)'), 27 + PhabricatorRepositoryPushLog::REFTYPE_BOOKMARK => pht('bookmark (hg)'), 28 + ); 29 + 30 + return id(new HeraldSelectFieldValue()) 31 + ->setKey(self::FIELDCONST) 32 + ->setOptions($types) 33 + ->setDefault(PhabricatorRepositoryPushLog::REFTYPE_BRANCH); 25 34 } 26 35 27 36 }
-3
src/applications/diffusion/herald/HeraldPreCommitRefAdapter.php
··· 2 2 3 3 final class HeraldPreCommitRefAdapter extends HeraldPreCommitAdapter { 4 4 5 - const VALUE_REF_TYPE = 'value-ref-type'; 6 - const VALUE_REF_CHANGE = 'value-ref-change'; 7 - 8 5 public function getAdapterContentName() { 9 6 return pht('Commit Hook: Branches/Tags/Bookmarks'); 10 7 }
+10 -6
src/applications/herald/adapter/HeraldAdapter.php
··· 41 41 const ACTION_BLOCK = 'block'; 42 42 const ACTION_REQUIRE_SIGNATURE = 'signature'; 43 43 44 - const VALUE_TEXT = 'text'; 45 44 const VALUE_NONE = 'none'; 46 45 const VALUE_EMAIL = 'email'; 47 46 const VALUE_USER = 'user'; ··· 49 48 const VALUE_REPOSITORY = 'repository'; 50 49 const VALUE_OWNERS_PACKAGE = 'package'; 51 50 const VALUE_PROJECT = 'project'; 52 - const VALUE_FLAG_COLOR = 'flagcolor'; 53 - const VALUE_CONTENT_SOURCE = 'contentsource'; 54 51 const VALUE_USER_OR_PROJECT = 'userorproject'; 55 52 const VALUE_BUILD_PLAN = 'buildplan'; 56 53 const VALUE_TASK_PRIORITY = 'taskpriority'; ··· 766 763 case self::ACTION_ADD_BLOCKING_REVIEWERS: 767 764 return self::VALUE_NONE; 768 765 case self::ACTION_FLAG: 769 - return self::VALUE_FLAG_COLOR; 766 + return $this->buildFlagColorFieldValue(); 770 767 case self::ACTION_ADD_PROJECTS: 771 768 case self::ACTION_REMOVE_PROJECTS: 772 769 return self::VALUE_PROJECT; ··· 783 780 case self::ACTION_REMOVE_PROJECTS: 784 781 return self::VALUE_PROJECT; 785 782 case self::ACTION_FLAG: 786 - return self::VALUE_FLAG_COLOR; 783 + return $this->buildFlagColorFieldValue(); 787 784 case self::ACTION_ASSIGN_TASK: 788 785 return self::VALUE_USER; 789 786 case self::ACTION_AUDIT: ··· 795 792 case self::ACTION_REQUIRE_SIGNATURE: 796 793 return self::VALUE_LEGAL_DOCUMENTS; 797 794 case self::ACTION_BLOCK: 798 - return self::VALUE_TEXT; 795 + return new HeraldTextFieldValue(); 799 796 } 800 797 } 801 798 ··· 807 804 throw new Exception(pht("Unknown or invalid action '%s'.", $action)); 808 805 } 809 806 807 + private function buildFlagColorFieldValue() { 808 + return id(new HeraldSelectFieldValue()) 809 + ->setKey('flag.color') 810 + ->setOptions(PhabricatorFlagColor::getColorNameMap()) 811 + ->setDefault(PhabricatorFlagColor::COLOR_BLUE); 812 + } 810 813 811 814 /* -( Repetition )--------------------------------------------------------- */ 812 815 ··· 1019 1022 if ($impl) { 1020 1023 return $impl->renderConditionValue( 1021 1024 $viewer, 1025 + $condition->getFieldCondition(), 1022 1026 $condition->getValue()); 1023 1027 } 1024 1028
+9 -26
src/applications/herald/controller/HeraldRuleController.php
··· 471 471 472 472 foreach ($config_info['actions'] as $action => $name) { 473 473 try { 474 - $action_value = $adapter->getValueTypeForAction( 474 + $value_key = $adapter->getValueTypeForAction( 475 475 $action, 476 476 $rule->getRuleType()); 477 477 } catch (Exception $ex) { 478 - $action_value = array(HeraldAdapter::VALUE_NONE); 478 + $value_key = new HeraldEmptyFieldValue(); 479 479 } 480 480 481 - $config_info['targets'][$action] = $action_value; 481 + if ($value_key instanceof HeraldFieldValue) { 482 + $spec = $value_key->getControlSpecificationDictionary(); 483 + $value_key = $value_key->getFieldValueKey(); 484 + $config_info['valueMap'][$value_key] = $spec; 485 + } 486 + 487 + $config_info['targets'][$action] = $value_key; 482 488 } 483 489 484 - $changeflag_options = 485 - PhabricatorRepositoryPushLog::getHeraldChangeFlagConditionOptions(); 486 490 Javelin::initBehavior( 487 491 'herald-rule-editor', 488 492 array( 489 493 'root' => 'herald-rule-edit-form', 490 494 'conditions' => (object)$serial_conditions, 491 495 'actions' => (object)$serial_actions, 492 - 'select' => array( 493 - HeraldAdapter::VALUE_FLAG_COLOR => array( 494 - 'options' => PhabricatorFlagColor::getColorNameMap(), 495 - 'default' => PhabricatorFlagColor::COLOR_BLUE, 496 - ), 497 - HeraldPreCommitRefAdapter::VALUE_REF_TYPE => array( 498 - 'options' => array( 499 - PhabricatorRepositoryPushLog::REFTYPE_BRANCH 500 - => pht('branch (git/hg)'), 501 - PhabricatorRepositoryPushLog::REFTYPE_TAG 502 - => pht('tag (git)'), 503 - PhabricatorRepositoryPushLog::REFTYPE_BOOKMARK 504 - => pht('bookmark (hg)'), 505 - ), 506 - 'default' => PhabricatorRepositoryPushLog::REFTYPE_BRANCH, 507 - ), 508 - HeraldPreCommitRefAdapter::VALUE_REF_CHANGE => array( 509 - 'options' => $changeflag_options, 510 - 'default' => PhabricatorRepositoryPushLog::CHANGEFLAG_ADD, 511 - ), 512 - ), 513 496 'template' => $this->buildTokenizerTemplates($handles) + array( 514 497 'rules' => $all_rules, 515 498 ),
+6
src/applications/herald/field/HeraldField.php
··· 108 108 109 109 public function renderConditionValue( 110 110 PhabricatorUser $viewer, 111 + $condition, 111 112 $value) { 113 + 114 + $value_type = $this->getHeraldFieldValueType($condition); 115 + if ($value_type instanceof HeraldFieldValue) { 116 + return $value_type->renderValue($viewer, $value); 117 + } 112 118 113 119 // TODO: While this is less of a mess than it used to be, it would still 114 120 // be nice to push this down into individual fields better eventually and
+4
src/applications/herald/value/HeraldEmptyFieldValue.php
··· 11 11 return self::CONTROL_NONE; 12 12 } 13 13 14 + public function renderValue(PhabricatorUser $viewer, $value) { 15 + return null; 16 + } 17 + 14 18 }
+1
src/applications/herald/value/HeraldFieldValue.php
··· 9 9 10 10 abstract public function getFieldValueKey(); 11 11 abstract public function getControlType(); 12 + abstract public function renderValue(PhabricatorUser $viewer, $value); 12 13 13 14 final public function getControlSpecificationDictionary() { 14 15 return array(
+5
src/applications/herald/value/HeraldSelectFieldValue.php
··· 56 56 ); 57 57 } 58 58 59 + public function renderValue(PhabricatorUser $viewer, $value) { 60 + $options = $this->getOptions(); 61 + return idx($options, $value, $value); 62 + } 63 + 59 64 }
+5
src/applications/herald/value/HeraldTextFieldValue.php
··· 11 11 return self::CONTROL_TEXT; 12 12 } 13 13 14 + 15 + public function renderValue(PhabricatorUser $viewer, $value) { 16 + return $value; 17 + } 18 + 14 19 }
+1
src/applications/maniphest/herald/ManiphestTaskPriorityHeraldField.php
··· 23 23 24 24 public function renderConditionValue( 25 25 PhabricatorUser $viewer, 26 + $condition, 26 27 $value) { 27 28 28 29 $priority_map = ManiphestTaskPriority::getTaskPriorityMap();
+1
src/applications/maniphest/herald/ManiphestTaskStatusHeraldField.php
··· 23 23 24 24 public function renderConditionValue( 25 25 PhabricatorUser $viewer, 26 + $condition, 26 27 $value) { 27 28 28 29 $status_map = ManiphestTaskStatus::getTaskStatusMap();
-13
webroot/rsrc/js/application/herald/HeraldRuleEditor.js
··· 269 269 get_fn = tokenizer[1]; 270 270 set_fn = tokenizer[2]; 271 271 break; 272 - case 'none': 273 - input = ''; 274 - get_fn = JX.bag; 275 - set_fn = JX.bag; 276 - break; 277 - case 'flagcolor': 278 - case 'value-ref-type': 279 - case 'value-ref-change': 280 - input = this._renderSelect(this._config.select[type].options); 281 - get_fn = function() { return input.value; }; 282 - set_fn = function(v) { input.value = v; }; 283 - set_fn(this._config.select[type]['default']); 284 - break; 285 272 default: 286 273 input = JX.$N('input', {type: 'text'}); 287 274 get_fn = function() { return input.value; };