From ed9d212013cd0d8747f92bca4e7cb94900bccfd5 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Fri, 31 May 2024 16:40:37 +0200 Subject: [PATCH] Warn in comment field if task is closed as duplicate Summary: Display a placeholder text in the text comment field of a Maniphest task if the task status has been set to Duplicate. This makes it clearer to users (who may have not checked the task status at the top of the page) not to fragment conversations. Closes T15749 Test Plan: * Be logged in and go to a task which is closed as a duplicate and see the placeholder text in the field to add a comment. * Be logged in and go to tasks which are not closed as a duplicate and see no placeholder text in the field to add a comment. * Go to other places whose code calls a `PhabricatorApplicationTransactionCommentView` constructor and check that it still renders correctly, for example Ponder in http://phorge.localhost/Q1, Slowvote in http://phorge.localhost/V1, Differential in http://phorge.localhost/D1 Reviewers: O1 Blessed Committers, valerio.bozzolan, avivey Reviewed By: O1 Blessed Committers, valerio.bozzolan, avivey Subscribers: avivey, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15749 Differential Revision: https://we.phorge.it/D25546 --- .../maniphest/editor/ManiphestEditEngine.php | 8 ++++ .../controller/PholioMockViewController.php | 2 +- .../PonderQuestionViewController.php | 2 +- .../ponder/view/PonderAnswerView.php | 2 +- .../PhabricatorSlowvotePollController.php | 2 +- .../editengine/PhabricatorEditEngine.php | 15 ++++++- ...catorApplicationTransactionCommentView.php | 40 +++++++++++++++---- 7 files changed, 58 insertions(+), 13 deletions(-) diff --git a/src/applications/maniphest/editor/ManiphestEditEngine.php b/src/applications/maniphest/editor/ManiphestEditEngine.php index 46877168e7..e11c977436 100644 --- a/src/applications/maniphest/editor/ManiphestEditEngine.php +++ b/src/applications/maniphest/editor/ManiphestEditEngine.php @@ -69,6 +69,14 @@ final class ManiphestEditEngine return pht('Set Sail for Adventure'); } + public function getCommentFieldPlaceholderText($object) { + if ($object->getStatus() === ManiphestTaskStatus::STATUS_CLOSED_DUPLICATE) { + return pht('This task is closed as a duplicate. '. + 'Only comment if you think that this task is not a duplicate.'); + } + return ''; + } + protected function getObjectViewURI($object) { return '/'.$object->getMonogram(); } diff --git a/src/applications/pholio/controller/PholioMockViewController.php b/src/applications/pholio/controller/PholioMockViewController.php index f4695d120c..36a8ec8c81 100644 --- a/src/applications/pholio/controller/PholioMockViewController.php +++ b/src/applications/pholio/controller/PholioMockViewController.php @@ -223,7 +223,7 @@ final class PholioMockViewController extends PholioController { $form = id(new PhabricatorApplicationTransactionCommentView()) ->setUser($viewer) - ->setObjectPHID($mock->getPHID()) + ->setObject($mock) ->setFormID($comment_form_id) ->setDraft($draft) ->setHeaderText($title) diff --git a/src/applications/ponder/controller/PonderQuestionViewController.php b/src/applications/ponder/controller/PonderQuestionViewController.php index 2cd555204c..63fe4e3539 100644 --- a/src/applications/ponder/controller/PonderQuestionViewController.php +++ b/src/applications/ponder/controller/PonderQuestionViewController.php @@ -60,7 +60,7 @@ final class PonderQuestionViewController extends PonderController { $add_comment = id(new PhabricatorApplicationTransactionCommentView()) ->setUser($viewer) - ->setObjectPHID($question->getPHID()) + ->setObject($question) ->setShowPreview(false) ->setAction($this->getApplicationURI("/question/comment/{$id}/")) ->setSubmitButtonName(pht('Comment')); diff --git a/src/applications/ponder/view/PonderAnswerView.php b/src/applications/ponder/view/PonderAnswerView.php index 474661381c..a16e7bfbd4 100644 --- a/src/applications/ponder/view/PonderAnswerView.php +++ b/src/applications/ponder/view/PonderAnswerView.php @@ -121,7 +121,7 @@ final class PonderAnswerView extends AphrontTagView { $comment_view = id(new PhabricatorApplicationTransactionCommentView()) ->setUser($viewer) - ->setObjectPHID($answer->getPHID()) + ->setObject($answer) ->setShowPreview(false) ->setHeaderText(pht('Answer Comment')) ->setAction("/ponder/answer/comment/{$id}/") diff --git a/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php b/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php index 7ed83fb13f..1844a5f03c 100644 --- a/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php +++ b/src/applications/slowvote/controller/PhabricatorSlowvotePollController.php @@ -154,7 +154,7 @@ final class PhabricatorSlowvotePollController return id(new PhabricatorApplicationTransactionCommentView()) ->setUser($viewer) - ->setObjectPHID($poll->getPHID()) + ->setObject($poll) ->setDraft($draft) ->setHeaderText($add_comment_header) ->setAction($this->getApplicationURI('/comment/'.$poll->getID().'/')) diff --git a/src/applications/transactions/editengine/PhabricatorEditEngine.php b/src/applications/transactions/editengine/PhabricatorEditEngine.php index f70e172a99..a696fb6cf7 100644 --- a/src/applications/transactions/editengine/PhabricatorEditEngine.php +++ b/src/applications/transactions/editengine/PhabricatorEditEngine.php @@ -339,7 +339,17 @@ abstract class PhabricatorEditEngine return null; } - + /** + * Set default placeholder plain text in the comment textarea of the engine. + * To be overwritten by conditions defined in the child EditEngine class. + * + * @param object Object in which the comment textarea is displayed. + * @return string Placeholder text to display in the comment textarea. + * @task text + */ + public function getCommentFieldPlaceholderText($object) { + return ''; + } /** * Return a human-readable header describing what this engine is used to do, @@ -1664,10 +1674,11 @@ abstract class PhabricatorEditEngine $view = id(new PhabricatorApplicationTransactionCommentView()) ->setUser($viewer) - ->setObjectPHID($object_phid) ->setHeaderText($header_text) ->setAction($comment_uri) ->setRequiresMFA($requires_mfa) + ->setObject($object) + ->setEditEngine($this) ->setSubmitButtonName($button_text); $draft = PhabricatorVersionedDraft::loadDraft( diff --git a/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php b/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php index 2e469c5e0a..684c348914 100644 --- a/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php +++ b/src/applications/transactions/view/PhabricatorApplicationTransactionCommentView.php @@ -15,11 +15,12 @@ final class PhabricatorApplicationTransactionCommentView private $draft; private $requestURI; private $showPreview = true; - private $objectPHID; + private $object; private $headerText; private $noPermission; private $fullWidth; private $infoView; + private $editEngine; private $editEngineLock; private $noBorder; private $requiresMFA; @@ -30,13 +31,19 @@ final class PhabricatorApplicationTransactionCommentView private $commentActionGroups = array(); private $transactionTimeline; - public function setObjectPHID($object_phid) { - $this->objectPHID = $object_phid; + /** + * Set object in which this comment textarea field is displayed + */ + public function setObject($object) { + $this->object = $object; return $this; } - public function getObjectPHID() { - return $this->objectPHID; + /** + * Get object in which this comment textarea is displayed + */ + public function getObject() { + return $this->object; } public function setShowPreview($show_preview) { @@ -150,6 +157,15 @@ final class PhabricatorApplicationTransactionCommentView return $this->noPermission; } + public function setEditEngine(PhabricatorEditEngine $edit_engine) { + $this->editEngine = $edit_engine; + return $this; + } + + public function getEditEngine() { + return $this->editEngine; + } + public function setEditEngineLock(PhabricatorEditEngineLock $lock) { $this->editEngineLock = $lock; return $this; @@ -295,6 +311,15 @@ final class PhabricatorApplicationTransactionCommentView private function renderCommentPanel() { $viewer = $this->getViewer(); + $engine = $this->getEditEngine(); + // In a few rare cases PhabricatorApplicationTransactionCommentView gets + // initiated in a View or Controller class. Don't crash in that case. + if ($engine) { + $placeholder_text = $engine + ->getCommentFieldPlaceholderText($this->getObject()); + } else { + $placeholder_text = ''; + } $remarkup_control = id(new PhabricatorRemarkupControl()) ->setViewer($viewer) @@ -302,6 +327,7 @@ final class PhabricatorApplicationTransactionCommentView ->addClass('phui-comment-fullwidth-control') ->addClass('phui-comment-textarea-control') ->setCanPin(true) + ->setPlaceholder($placeholder_text) ->setName('comment'); $draft_comment = ''; @@ -331,7 +357,7 @@ final class PhabricatorApplicationTransactionCommentView } $remarkup_control->setRemarkupMetadata($draft_metadata); - if (!$this->getObjectPHID()) { + if (!$this->getObject()->getPHID()) { throw new PhutilInvalidStateException('setObjectPHID', 'render'); } @@ -345,7 +371,7 @@ final class PhabricatorApplicationTransactionCommentView ->setFullWidth($this->fullWidth) ->setMetadata( array( - 'objectPHID' => $this->getObjectPHID(), + 'objectPHID' => $this->getObject()->getPHID(), )) ->setAction($this->getAction()) ->setID($this->getFormID())