From 82be07315cbffd0b6053200e294d3308e5664488 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sat, 5 Dec 2015 11:09:05 -0800 Subject: [PATCH] Improve rendering of tokenizer tokens in Herald when editing rules Summary: Fixes T7848. @jasonfsmitty discussed an issue in great detail there and in D14359, and I completely missed it. Specifically: - If you save a "Change status to: Open" rule in Maniphest, and then edit it again, the token shows "Unknown Object (???)" instead of the correct token. - That's because loadHandles() has no idea what to do with the value "open", since it's not a real PHID. The way we render tokenizer tokens in Herald is quite hacky right now. Fortunately, I wrote a //slightly// better way for EditEngine yesterday or the day before. Use the slightly better way to fix the issue with D14359. This could still be better than it is, but the badness is mostly hidden now and can be cleaned up later without impacting anything. Test Plan: Edited a Herald rule with projects and status changes, saw proper tokens. Reviewers: chad Reviewed By: chad Subscribers: jasonfsmitty Maniphest Tasks: T7848 Differential Revision: https://secure.phabricator.com/D14682 --- resources/celerity/map.php | 22 +++++++++---------- .../herald/action/HeraldAction.php | 10 ++++++--- .../value/HeraldTokenizerFieldValue.php | 20 +++-------------- .../js/application/herald/HeraldRuleEditor.js | 3 ++- 4 files changed, 23 insertions(+), 32 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 9559dace87..b0c628baf0 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -399,7 +399,7 @@ return array( 'rsrc/js/application/drydock/drydock-live-operation-status.js' => '901935ef', 'rsrc/js/application/files/behavior-icon-composer.js' => '8ef9ab58', 'rsrc/js/application/files/behavior-launch-icon-composer.js' => '48086888', - 'rsrc/js/application/herald/HeraldRuleEditor.js' => '91a6031b', + 'rsrc/js/application/herald/HeraldRuleEditor.js' => '5bd8f385', 'rsrc/js/application/herald/PathTypeahead.js' => 'f7fc67ec', 'rsrc/js/application/herald/herald-rule-editor.js' => '7ebaeed3', 'rsrc/js/application/maniphest/behavior-batch-editor.js' => '782ab6e7', @@ -554,7 +554,7 @@ return array( 'global-drag-and-drop-css' => '697324ad', 'harbormaster-css' => 'b0758ca5', 'herald-css' => '826075fa', - 'herald-rule-editor' => '91a6031b', + 'herald-rule-editor' => '5bd8f385', 'herald-test-css' => 'a52e323e', 'inline-comment-summary-css' => '51efda3a', 'javelin-aphlict' => '5359e785', @@ -1225,6 +1225,15 @@ return array( 'javelin-uri', 'javelin-routable', ), + '5bd8f385' => array( + 'multirow-row-manager', + 'javelin-install', + 'javelin-util', + 'javelin-dom', + 'javelin-stratcom', + 'javelin-json', + 'phabricator-prefab', + ), '5c54cbf3' => array( 'javelin-behavior', 'javelin-stratcom', @@ -1533,15 +1542,6 @@ return array( 'javelin-dom', 'javelin-request', ), - '91a6031b' => array( - 'multirow-row-manager', - 'javelin-install', - 'javelin-util', - 'javelin-dom', - 'javelin-stratcom', - 'javelin-json', - 'phabricator-prefab', - ), '93d0c9e3' => array( 'javelin-behavior', 'javelin-stratcom', diff --git a/src/applications/herald/action/HeraldAction.php b/src/applications/herald/action/HeraldAction.php index 6b076fbddf..818e253998 100644 --- a/src/applications/herald/action/HeraldAction.php +++ b/src/applications/herald/action/HeraldAction.php @@ -95,9 +95,13 @@ abstract class HeraldAction extends Phobject { switch ($type) { case self::STANDARD_PHID_LIST: - $handles = $viewer->loadHandles($target); - $handles = iterator_to_array($handles); - return mpull($handles, 'getName', 'getPHID'); + $datasource = $this->getDatasource(); + + if (!$datasource) { + return array(); + } + + return $datasource->getWireTokens($target); } return $target; diff --git a/src/applications/herald/value/HeraldTokenizerFieldValue.php b/src/applications/herald/value/HeraldTokenizerFieldValue.php index cd54212324..bb3ceef1e7 100644 --- a/src/applications/herald/value/HeraldTokenizerFieldValue.php +++ b/src/applications/herald/value/HeraldTokenizerFieldValue.php @@ -80,24 +80,10 @@ final class HeraldTokenizerFieldValue $viewer = $this->getViewer(); $value = (array)$value; - // TODO: This should eventually render properly through the datasource - // to get icons and colors. + $datasource = $this->getDatasource() + ->setViewer($viewer); - if ($this->valueMap !== null) { - $map = array(); - foreach ($value as $v) { - $map[$v] = idx($this->valueMap, $v, $v); - } - return $map; - } - - $handles = $viewer->loadHandles($value); - - $map = array(); - foreach ($value as $v) { - $map[$v] = $handles[$v]->getName(); - } - return $map; + return $datasource->getWireTokens($value); } } diff --git a/webroot/rsrc/js/application/herald/HeraldRuleEditor.js b/webroot/rsrc/js/application/herald/HeraldRuleEditor.js index 82100062ed..6514567e19 100644 --- a/webroot/rsrc/js/application/herald/HeraldRuleEditor.js +++ b/webroot/rsrc/js/application/herald/HeraldRuleEditor.js @@ -293,7 +293,8 @@ JX.install('HeraldRuleEditor', { }, function(map) { for (var k in map) { - build.tokenizer.addToken(k, map[k]); + var v = JX.Prefab.transformDatasourceResults(map[k]); + build.tokenizer.addToken(k, v); } }]; },