mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-20 02:38:39 +01:00
Remember action in Differential comment draft
Summary: It happens to me quite often that I leave the window with revision (by closing it or by visiting a link from it). When I return then the comment draft is there so I clowncopterize it but forget that I wanted to take some other action than Comment. Test Plan: Selected "Add Reviewers", added some reviewers, closed the window, opened it - the action and reviewers were still there. Reviewers: btrahan, epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3530
This commit is contained in:
parent
8d0918885d
commit
d119ac672f
7 changed files with 72 additions and 13 deletions
4
resources/sql/patches/draft-metadata.sql
Normal file
4
resources/sql/patches/draft-metadata.sql
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
ALTER TABLE `{$NAMESPACE}_draft`.`draft`
|
||||||
|
ADD `metadata` longtext NOT NULL DEFAULT '' AFTER `draft`;
|
||||||
|
|
||||||
|
UPDATE `{$NAMESPACE}_draft`.`draft` SET `metadata` = '[]';
|
|
@ -85,4 +85,12 @@ final class DifferentialAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function allowReviewers($action) {
|
||||||
|
if ($action == DifferentialAction::ACTION_ADDREVIEWERS ||
|
||||||
|
$action == DifferentialAction::ACTION_REQUEST) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,18 +42,15 @@ final class DifferentialCommentPreviewController
|
||||||
|
|
||||||
$handles = array($author_phid);
|
$handles = array($author_phid);
|
||||||
|
|
||||||
$reviewers = $request->getStr('reviewers');
|
$reviewers = $request->getStrList('reviewers');
|
||||||
if (($action == DifferentialAction::ACTION_ADDREVIEWERS
|
if (DifferentialAction::allowReviewers($action) && $reviewers) {
|
||||||
|| $action == DifferentialAction::ACTION_REQUEST) && $reviewers) {
|
|
||||||
$reviewers = explode(',', $reviewers);
|
|
||||||
$comment->setMetadata(array(
|
$comment->setMetadata(array(
|
||||||
DifferentialComment::METADATA_ADDED_REVIEWERS => $reviewers));
|
DifferentialComment::METADATA_ADDED_REVIEWERS => $reviewers));
|
||||||
$handles = array_merge($handles, $reviewers);
|
$handles = array_merge($handles, $reviewers);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ccs = $request->getStr('ccs');
|
$ccs = $request->getStrList('ccs');
|
||||||
if ($action == DifferentialAction::ACTION_ADDCCS && $ccs) {
|
if ($action == DifferentialAction::ACTION_ADDCCS && $ccs) {
|
||||||
$ccs = explode(',', $ccs);
|
|
||||||
$comment->setMetadata(array(
|
$comment->setMetadata(array(
|
||||||
DifferentialComment::METADATA_ADDED_CCS => $ccs));
|
DifferentialComment::METADATA_ADDED_CCS => $ccs));
|
||||||
$handles = array_merge($handles, $ccs);
|
$handles = array_merge($handles, $ccs);
|
||||||
|
@ -74,6 +71,11 @@ final class DifferentialCommentPreviewController
|
||||||
->setAuthorPHID($author_phid)
|
->setAuthorPHID($author_phid)
|
||||||
->setDraftKey('differential-comment-'.$this->id)
|
->setDraftKey('differential-comment-'.$this->id)
|
||||||
->setDraft($comment->getContent())
|
->setDraft($comment->getContent())
|
||||||
|
->setMetadata(array(
|
||||||
|
'action' => $action,
|
||||||
|
'reviewers' => $reviewers,
|
||||||
|
'ccs' => $ccs,
|
||||||
|
))
|
||||||
->replace();
|
->replace();
|
||||||
|
|
||||||
return id(new AphrontAjaxResponse())
|
return id(new AphrontAjaxResponse())
|
||||||
|
|
|
@ -353,10 +353,17 @@ final class DifferentialRevisionViewController extends DifferentialController {
|
||||||
'authorPHID = %s AND draftKey = %s',
|
'authorPHID = %s AND draftKey = %s',
|
||||||
$user->getPHID(),
|
$user->getPHID(),
|
||||||
'differential-comment-'.$revision->getID());
|
'differential-comment-'.$revision->getID());
|
||||||
|
|
||||||
|
$reviewers = array();
|
||||||
|
$ccs = array();
|
||||||
if ($draft) {
|
if ($draft) {
|
||||||
$draft = $draft->getDraft();
|
$reviewers = idx($draft->getMetadata(), 'reviewers', array());
|
||||||
} else {
|
$ccs = idx($draft->getMetadata(), 'ccs', array());
|
||||||
$draft = null;
|
if ($reviewers || $ccs) {
|
||||||
|
$handles = $this->loadViewerHandles(array_merge($reviewers, $ccs));
|
||||||
|
$reviewers = array_select_keys($handles, $reviewers);
|
||||||
|
$ccs = array_select_keys($handles, $ccs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$comment_form = new DifferentialAddCommentView();
|
$comment_form = new DifferentialAddCommentView();
|
||||||
|
@ -366,6 +373,8 @@ final class DifferentialRevisionViewController extends DifferentialController {
|
||||||
$comment_form->setActionURI('/differential/comment/save/');
|
$comment_form->setActionURI('/differential/comment/save/');
|
||||||
$comment_form->setUser($user);
|
$comment_form->setUser($user);
|
||||||
$comment_form->setDraft($draft);
|
$comment_form->setDraft($draft);
|
||||||
|
$comment_form->setReviewers(mpull($reviewers, 'getFullName', 'getPHID'));
|
||||||
|
$comment_form->setCCs(mpull($ccs, 'getFullName', 'getPHID'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$pane_id = celerity_generate_unique_node_id();
|
$pane_id = celerity_generate_unique_node_id();
|
||||||
|
|
|
@ -24,6 +24,8 @@ final class DifferentialAddCommentView extends AphrontView {
|
||||||
private $user;
|
private $user;
|
||||||
private $draft;
|
private $draft;
|
||||||
private $auxFields;
|
private $auxFields;
|
||||||
|
private $reviewers = array();
|
||||||
|
private $ccs = array();
|
||||||
|
|
||||||
public function setRevision($revision) {
|
public function setRevision($revision) {
|
||||||
$this->revision = $revision;
|
$this->revision = $revision;
|
||||||
|
@ -51,11 +53,21 @@ final class DifferentialAddCommentView extends AphrontView {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDraft($draft) {
|
public function setDraft(PhabricatorDraft $draft = null) {
|
||||||
$this->draft = $draft;
|
$this->draft = $draft;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setReviewers(array $names) {
|
||||||
|
$this->reviewers = $names;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCCs(array $names) {
|
||||||
|
$this->ccs = $names;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
private function generateWarningView(
|
private function generateWarningView(
|
||||||
$status,
|
$status,
|
||||||
array $titles,
|
array $titles,
|
||||||
|
@ -79,6 +91,14 @@ final class DifferentialAddCommentView extends AphrontView {
|
||||||
|
|
||||||
$revision = $this->revision;
|
$revision = $this->revision;
|
||||||
|
|
||||||
|
$action = null;
|
||||||
|
if ($this->draft) {
|
||||||
|
$action = idx($this->draft->getMetadata(), 'action');
|
||||||
|
}
|
||||||
|
|
||||||
|
$enable_reviewers = DifferentialAction::allowReviewers($action);
|
||||||
|
$enable_ccs = ($action == DifferentialAction::ACTION_ADDCCS);
|
||||||
|
|
||||||
$form = new AphrontFormView();
|
$form = new AphrontFormView();
|
||||||
$form
|
$form
|
||||||
->setWorkflow(true)
|
->setWorkflow(true)
|
||||||
|
@ -89,6 +109,7 @@ final class DifferentialAddCommentView extends AphrontView {
|
||||||
id(new AphrontFormSelectControl())
|
id(new AphrontFormSelectControl())
|
||||||
->setLabel('Action')
|
->setLabel('Action')
|
||||||
->setName('action')
|
->setName('action')
|
||||||
|
->setValue($action)
|
||||||
->setID('comment-action')
|
->setID('comment-action')
|
||||||
->setOptions($this->actions))
|
->setOptions($this->actions))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
|
@ -96,7 +117,7 @@ final class DifferentialAddCommentView extends AphrontView {
|
||||||
->setLabel('Add Reviewers')
|
->setLabel('Add Reviewers')
|
||||||
->setName('reviewers')
|
->setName('reviewers')
|
||||||
->setControlID('add-reviewers')
|
->setControlID('add-reviewers')
|
||||||
->setControlStyle('display: none')
|
->setControlStyle($enable_reviewers ? null : 'display: none')
|
||||||
->setID('add-reviewers-tokenizer')
|
->setID('add-reviewers-tokenizer')
|
||||||
->setDisableBehavior(true))
|
->setDisableBehavior(true))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
|
@ -104,7 +125,7 @@ final class DifferentialAddCommentView extends AphrontView {
|
||||||
->setLabel('Add CCs')
|
->setLabel('Add CCs')
|
||||||
->setName('ccs')
|
->setName('ccs')
|
||||||
->setControlID('add-ccs')
|
->setControlID('add-ccs')
|
||||||
->setControlStyle('display: none')
|
->setControlStyle($enable_ccs ? null : 'display: none')
|
||||||
->setID('add-ccs-tokenizer')
|
->setID('add-ccs-tokenizer')
|
||||||
->setDisableBehavior(true))
|
->setDisableBehavior(true))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
|
@ -113,7 +134,7 @@ final class DifferentialAddCommentView extends AphrontView {
|
||||||
->setID('comment-content')
|
->setID('comment-content')
|
||||||
->setLabel('Comment')
|
->setLabel('Comment')
|
||||||
->setEnableDragAndDropFileUploads(true)
|
->setEnableDragAndDropFileUploads(true)
|
||||||
->setValue($this->draft))
|
->setValue($this->draft->getDraft()))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormSubmitControl())
|
id(new AphrontFormSubmitControl())
|
||||||
->setValue($is_serious ? 'Submit' : 'Clowncopterize'));
|
->setValue($is_serious ? 'Submit' : 'Clowncopterize'));
|
||||||
|
@ -125,6 +146,7 @@ final class DifferentialAddCommentView extends AphrontView {
|
||||||
'add-reviewers-tokenizer' => array(
|
'add-reviewers-tokenizer' => array(
|
||||||
'actions' => array('request_review' => 1, 'add_reviewers' => 1),
|
'actions' => array('request_review' => 1, 'add_reviewers' => 1),
|
||||||
'src' => '/typeahead/common/users/',
|
'src' => '/typeahead/common/users/',
|
||||||
|
'value' => $this->reviewers,
|
||||||
'row' => 'add-reviewers',
|
'row' => 'add-reviewers',
|
||||||
'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'),
|
'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'),
|
||||||
'placeholder' => 'Type a user name...',
|
'placeholder' => 'Type a user name...',
|
||||||
|
@ -132,6 +154,7 @@ final class DifferentialAddCommentView extends AphrontView {
|
||||||
'add-ccs-tokenizer' => array(
|
'add-ccs-tokenizer' => array(
|
||||||
'actions' => array('add_ccs' => 1),
|
'actions' => array('add_ccs' => 1),
|
||||||
'src' => '/typeahead/common/mailable/',
|
'src' => '/typeahead/common/mailable/',
|
||||||
|
'value' => $this->ccs,
|
||||||
'row' => 'add-ccs',
|
'row' => 'add-ccs',
|
||||||
'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'),
|
'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'),
|
||||||
'placeholder' => 'Type a user or mailing list...',
|
'placeholder' => 'Type a user or mailing list...',
|
||||||
|
|
|
@ -21,5 +21,14 @@ final class PhabricatorDraft extends PhabricatorDraftDAO {
|
||||||
protected $authorPHID;
|
protected $authorPHID;
|
||||||
protected $draftKey;
|
protected $draftKey;
|
||||||
protected $draft;
|
protected $draft;
|
||||||
|
protected $metadata = array();
|
||||||
|
|
||||||
|
public function getConfiguration() {
|
||||||
|
return array(
|
||||||
|
self::CONFIG_SERIALIZATION => array(
|
||||||
|
'metadata' => self::SERIALIZATION_JSON,
|
||||||
|
),
|
||||||
|
) + parent::getConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -984,6 +984,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
|
||||||
'type' => 'sql',
|
'type' => 'sql',
|
||||||
'name' => $this->getPatchPath('xhprof.sql'),
|
'name' => $this->getPatchPath('xhprof.sql'),
|
||||||
),
|
),
|
||||||
|
'draft-metadata.sql' => array(
|
||||||
|
'type' => 'sql',
|
||||||
|
'name' => $this->getPatchPath('draft-metadata.sql'),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue