From c977168797cc7a44b4de58adea566a313163ca28 Mon Sep 17 00:00:00 2001 From: Bian Jiang Date: Wed, 10 Jul 2013 11:05:53 -0700 Subject: [PATCH] Show add reviewer typehead when user selects resign as a reviewer. Summary: 1. Show add reviewer typehead when user selects resign as a reviewer. 2. Change the label for add reviewers typehead when user selects resign as a reviewer. Test Plan: 1. Add yourself as a reviewer in a diff. 2. Select "Resign as Reviewer" in comment editor. Add reviewer typehead should display, with label "Suggest Another Reviewer". Add reviewer typehead is also displayed after user refreshed the page with "Resign as Reviewer" selected. Reviewers: wez, epriestley Reviewed By: epriestley CC: aran, epriestley, akramer, person Differential Revision: https://secure.phabricator.com/D6340 --- .../differential/constants/DifferentialAction.php | 3 ++- .../editor/DifferentialCommentEditor.php | 7 +++++++ .../view/DifferentialAddCommentView.php | 14 ++++++++++++-- .../differential/behavior-add-reviewers-and-ccs.js | 9 ++++++++- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/applications/differential/constants/DifferentialAction.php b/src/applications/differential/constants/DifferentialAction.php index 89ad3a2a04..daf7f2fa7a 100644 --- a/src/applications/differential/constants/DifferentialAction.php +++ b/src/applications/differential/constants/DifferentialAction.php @@ -74,7 +74,8 @@ final class DifferentialAction { public static function allowReviewers($action) { if ($action == DifferentialAction::ACTION_ADDREVIEWERS || - $action == DifferentialAction::ACTION_REQUEST) { + $action == DifferentialAction::ACTION_REQUEST || + $action == DifferentialAction::ACTION_RESIGN) { return true; } return false; diff --git a/src/applications/differential/editor/DifferentialCommentEditor.php b/src/applications/differential/editor/DifferentialCommentEditor.php index 9c5d873824..144a301a50 100644 --- a/src/applications/differential/editor/DifferentialCommentEditor.php +++ b/src/applications/differential/editor/DifferentialCommentEditor.php @@ -139,6 +139,13 @@ final class DifferentialCommentEditor extends PhabricatorEditor { "You can not resign from this revision because you are not ". "a reviewer."); } + + list($added_reviewers, $ignored) = $this->alterReviewers(); + if ($added_reviewers) { + $key = DifferentialComment::METADATA_ADDED_REVIEWERS; + $metadata[$key] = $added_reviewers; + } + DifferentialRevisionEditor::alterReviewers( $revision, $reviewer_phids, diff --git a/src/applications/differential/view/DifferentialAddCommentView.php b/src/applications/differential/view/DifferentialAddCommentView.php index e73679b874..c1fb8c7c55 100644 --- a/src/applications/differential/view/DifferentialAddCommentView.php +++ b/src/applications/differential/view/DifferentialAddCommentView.php @@ -61,6 +61,10 @@ final class DifferentialAddCommentView extends AphrontView { $enable_reviewers = DifferentialAction::allowReviewers($action); $enable_ccs = ($action == DifferentialAction::ACTION_ADDCCS); + $add_reviewers_labels = array( + 'add_reviewers' => pht('Add Reviewers'), + 'resign' => pht('Suggest Reviewers'), + ); $form = new AphrontFormView(); $form @@ -78,7 +82,8 @@ final class DifferentialAddCommentView extends AphrontView { ->setOptions($this->actions)) ->appendChild( id(new AphrontFormTokenizerControl()) - ->setLabel(pht('Add Reviewers')) + ->setLabel($enable_reviewers ? $add_reviewers_labels[$action] : + $add_reviewers_labels['add_reviewers']) ->setName('reviewers') ->setControlID('add-reviewers') ->setControlStyle($enable_reviewers ? null : 'display: none') @@ -108,11 +113,16 @@ final class DifferentialAddCommentView extends AphrontView { array( 'dynamic' => array( 'add-reviewers-tokenizer' => array( - 'actions' => array('request_review' => 1, 'add_reviewers' => 1), + 'actions' => array( + 'request_review' => 1, + 'add_reviewers' => 1, + 'resign' => 1, + ), 'src' => '/typeahead/common/users/', 'value' => $this->reviewers, 'row' => 'add-reviewers', 'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'), + 'labels' => $add_reviewers_labels, 'placeholder' => pht('Type a user name...'), ), 'add-ccs-tokenizer' => array( diff --git a/webroot/rsrc/js/application/differential/behavior-add-reviewers-and-ccs.js b/webroot/rsrc/js/application/differential/behavior-add-reviewers-and-ccs.js index 6c2d72b6b5..216c1d4492 100644 --- a/webroot/rsrc/js/application/differential/behavior-add-reviewers-and-ccs.js +++ b/webroot/rsrc/js/application/differential/behavior-add-reviewers-and-ccs.js @@ -18,7 +18,8 @@ JX.behavior('differential-add-reviewers-and-ccs', function(config) { dynamic[k] = { row : JX.$(props.row), tokenizer : tokenizer, - actions : props.actions + actions : props.actions, + labels: props.labels }; } @@ -31,6 +32,12 @@ JX.behavior('differential-add-reviewers-and-ccs', function(config) { for (var k in dynamic) { if (dynamic[k].actions[v]) { JX.DOM.show(dynamic[k].row); + if (dynamic[k].labels) { + var label_node = JX.DOM.find(dynamic[k].row, 'label'); + if (label_node) { + JX.DOM.setContent(label_node, dynamic[k].labels[v]); + } + } dynamic[k].tokenizer.refresh(); } else { JX.DOM.hide(dynamic[k].row);