From b2ce0844b6ffce76065fe878969b6c1ecc5292ef Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 29 Apr 2020 11:25:43 -0700 Subject: [PATCH] When a user clicks "Cancel" on an inline comment to leave the "Editing" state, save the state change Summary: Ref T13513. Now that the "currently being edited" state of inlines is saved on the server side, clear the flag when the user clicks "Cancel" to leave the "editing" state on the client. This also serves to delete empty comments. Test Plan: - Clicked a line number to create a new comment. Then: - Clicked "Cancel". Reloaded page, saw no more comment. - Typed text, saved. Reloaded page, saw non-editing draft. Clicked "Edit", reloaded page, saw editing draft. Clicked "Cancel", reloaded page, saw non-editing draft. - Typed text, saved. Clicked "Edit", deleted text, saved. Reloaded page, saw no more comment. Maniphest Tasks: T13513 Differential Revision: https://secure.phabricator.com/D21187 --- resources/celerity/map.php | 12 ++++++------ .../diff/PhabricatorInlineCommentController.php | 13 +++++++++++++ webroot/rsrc/js/application/diff/DiffInline.js | 15 ++++++++++++++- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index b48de26153..057493ac09 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -13,7 +13,7 @@ return array( 'core.pkg.js' => '632fb8f5', 'dark-console.pkg.js' => '187792c2', 'differential.pkg.css' => '2d70b7b9', - 'differential.pkg.js' => 'b289f75d', + 'differential.pkg.js' => 'b35de23a', 'diffusion.pkg.css' => '42c75c37', 'diffusion.pkg.js' => 'a98c0bf7', 'maniphest.pkg.css' => '35995d6d', @@ -381,7 +381,7 @@ return array( 'rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js' => '0116d3e8', 'rsrc/js/application/diff/DiffChangeset.js' => '9a713ba5', 'rsrc/js/application/diff/DiffChangesetList.js' => '10726e6a', - 'rsrc/js/application/diff/DiffInline.js' => '7b0bdd6d', + 'rsrc/js/application/diff/DiffInline.js' => '02791ed9', 'rsrc/js/application/diff/DiffPathView.js' => '8207abf9', 'rsrc/js/application/diff/DiffTreeView.js' => '5d83623b', 'rsrc/js/application/diff/behavior-preview-link.js' => 'f51e9c17', @@ -778,7 +778,7 @@ return array( 'phabricator-dashboard-css' => '5a205b9d', 'phabricator-diff-changeset' => '9a713ba5', 'phabricator-diff-changeset-list' => '10726e6a', - 'phabricator-diff-inline' => '7b0bdd6d', + 'phabricator-diff-inline' => '02791ed9', 'phabricator-diff-path-view' => '8207abf9', 'phabricator-diff-tree-view' => '5d83623b', 'phabricator-drag-and-drop-file-upload' => '4370900d', @@ -944,6 +944,9 @@ return array( 'javelin-leader', 'javelin-json', ), + '02791ed9' => array( + 'javelin-dom', + ), '02cb4398' => array( 'javelin-behavior', 'javelin-dom', @@ -1616,9 +1619,6 @@ return array( 'phabricator-drag-and-drop-file-upload', 'phabricator-textareautils', ), - '7b0bdd6d' => array( - 'javelin-dom', - ), '7b139193' => array( 'javelin-behavior', 'javelin-stratcom', diff --git a/src/infrastructure/diff/PhabricatorInlineCommentController.php b/src/infrastructure/diff/PhabricatorInlineCommentController.php index bba4666bb9..fbf297c82a 100644 --- a/src/infrastructure/diff/PhabricatorInlineCommentController.php +++ b/src/infrastructure/diff/PhabricatorInlineCommentController.php @@ -215,6 +215,19 @@ abstract class PhabricatorInlineCommentController $view = $this->buildScaffoldForView($edit_dialog); return $this->newInlineResponse($inline, $view); + case 'cancel': + $inline = $this->loadCommentForEdit($this->getCommentID()); + + $inline->setIsEditing(false); + + $content = $inline->getContent(); + if (!strlen($content)) { + $this->deleteComment($inline); + } else { + $this->saveComment($inline); + } + + return $this->buildEmptyResponse(); case 'new': case 'reply': default: diff --git a/webroot/rsrc/js/application/diff/DiffInline.js b/webroot/rsrc/js/application/diff/DiffInline.js index ae56e28e59..9a86d9af13 100644 --- a/webroot/rsrc/js/application/diff/DiffInline.js +++ b/webroot/rsrc/js/application/diff/DiffInline.js @@ -647,12 +647,25 @@ JX.install('DiffInline', { } this.setEditing(false); - this.setInvisible(false); + var uri = this._getInlineURI(); + var data = this._newRequestData('cancel'); + var handler = JX.bind(this, this._onCancelResponse); + + this.setLoading(true); + + new JX.Request(uri, handler) + .setData(data) + .send(); + this._didUpdate(true); }, + _onCancelResponse: function(response) { + this.setLoading(false); + }, + _readText: function(row) { var textarea; try {