@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Reduce code duplication for inline "Undo"

Summary:
Ref T2009. This is another almost-identical copy of the row scaffolding, which has the same 1up/2up bugs as the 8 other copies of this code.

Turn the "undo" element into an InlineCommentView so we can scaffold it.

Then, scaffold it with the same code as everything else.

Test Plan: Hit "Undo", swapped from 1up to 2up, hit "undo" again, swapped back, tried left/right, everything rendered with proper scaffolding.

Reviewers: btrahan, chad

Reviewed By: chad

Subscribers: epriestley

Maniphest Tasks: T2009

Differential Revision: https://secure.phabricator.com/D12019

+101 -48
+2
src/__phutil_library_map__.php
··· 1139 1139 'PHUIDiffInlineCommentEditView' => 'infrastructure/diff/view/PHUIDiffInlineCommentEditView.php', 1140 1140 'PHUIDiffInlineCommentRowScaffold' => 'infrastructure/diff/view/PHUIDiffInlineCommentRowScaffold.php', 1141 1141 'PHUIDiffInlineCommentTableScaffold' => 'infrastructure/diff/view/PHUIDiffInlineCommentTableScaffold.php', 1142 + 'PHUIDiffInlineCommentUndoView' => 'infrastructure/diff/view/PHUIDiffInlineCommentUndoView.php', 1142 1143 'PHUIDiffInlineCommentView' => 'infrastructure/diff/view/PHUIDiffInlineCommentView.php', 1143 1144 'PHUIDiffOneUpInlineCommentRowScaffold' => 'infrastructure/diff/view/PHUIDiffOneUpInlineCommentRowScaffold.php', 1144 1145 'PHUIDiffTwoUpInlineCommentRowScaffold' => 'infrastructure/diff/view/PHUIDiffTwoUpInlineCommentRowScaffold.php', ··· 4371 4372 'PHUIDiffInlineCommentEditView' => 'PHUIDiffInlineCommentView', 4372 4373 'PHUIDiffInlineCommentRowScaffold' => 'AphrontView', 4373 4374 'PHUIDiffInlineCommentTableScaffold' => 'AphrontView', 4375 + 'PHUIDiffInlineCommentUndoView' => 'PHUIDiffInlineCommentView', 4374 4376 'PHUIDiffInlineCommentView' => 'AphrontView', 4375 4377 'PHUIDiffOneUpInlineCommentRowScaffold' => 'PHUIDiffInlineCommentRowScaffold', 4376 4378 'PHUIDiffTwoUpInlineCommentRowScaffold' => 'PHUIDiffInlineCommentRowScaffold',
+2 -1
src/applications/differential/controller/DifferentialChangesetViewController.php
··· 217 217 218 218 return id(new PhabricatorChangesetResponse()) 219 219 ->setRenderedChangeset($parser->renderChangeset()) 220 - ->setCoverage($coverage); 220 + ->setCoverage($coverage) 221 + ->setUndoTemplates($parser->getRenderer()->renderUndoTemplates()); 221 222 } 222 223 223 224 $diff = $changeset->getDiff();
+15
src/applications/differential/render/DifferentialChangesetRenderer.php
··· 600 600 return array($old, $new); 601 601 } 602 602 603 + public function renderUndoTemplates() { 604 + $views = array( 605 + 'l' => id(new PHUIDiffInlineCommentUndoView())->setIsOnRight(false), 606 + 'r' => id(new PHUIDiffInlineCommentUndoView())->setIsOnRight(true), 607 + ); 608 + 609 + foreach ($views as $key => $view) { 610 + $scaffold = $this->getRowScaffoldForInline($view); 611 + $views[$key] = id(new PHUIDiffInlineCommentTableScaffold()) 612 + ->addRowScaffold($scaffold); 613 + } 614 + 615 + return $views; 616 + } 617 + 603 618 }
+5
src/applications/differential/view/DifferentialChangesetDetailView.php
··· 208 208 $icon = id(new PHUIIconView()) 209 209 ->setIconFont($display_icon); 210 210 211 + $renderer = DifferentialChangesetHTMLRenderer::getHTMLRendererByKey( 212 + $this->getRenderer()); 213 + 211 214 return javelin_tag( 212 215 'div', 213 216 array( ··· 224 227 'ref' => $this->getRenderingRef(), 225 228 'autoload' => $this->getAutoload(), 226 229 'loaded' => $this->getLoaded(), 230 + 'undoTemplates' => $renderer->renderUndoTemplates(), 227 231 ), 228 232 'class' => $class, 229 233 'id' => $id, ··· 251 255 $this->renderChildren()), 252 256 )); 253 257 } 258 + 254 259 255 260 }
+1 -41
src/applications/differential/view/DifferentialChangesetListView.php
··· 123 123 'collapsed' => pht('This file content has been collapsed.'), 124 124 ), 125 125 )); 126 + 126 127 Javelin::initBehavior( 127 128 'differential-dropdown-menus', 128 129 array( ··· 230 231 $this->initBehavior('differential-comment-jump', array()); 231 232 232 233 if ($this->inlineURI) { 233 - $undo_templates = $this->renderUndoTemplates(); 234 - 235 234 Javelin::initBehavior('differential-edit-inline-comments', array( 236 235 'uri' => $this->inlineURI, 237 - 'undo_templates' => $undo_templates, 238 236 'stage' => 'differential-review-stage', 239 237 )); 240 238 } ··· 255 253 ->appendChild($content); 256 254 257 255 return $object_box; 258 - } 259 - 260 - /** 261 - * Render the "Undo" markup for the inline comment undo feature. 262 - */ 263 - private function renderUndoTemplates() { 264 - $link = javelin_tag( 265 - 'a', 266 - array( 267 - 'href' => '#', 268 - 'sigil' => 'differential-inline-comment-undo', 269 - ), 270 - pht('Undo')); 271 - 272 - $div = phutil_tag( 273 - 'div', 274 - array( 275 - 'class' => 'differential-inline-undo', 276 - ), 277 - array('Changes discarded. ', $link)); 278 - 279 - return array( 280 - 'l' => phutil_tag('table', array(), 281 - phutil_tag('tr', array(), array( 282 - phutil_tag('th', array()), 283 - phutil_tag('td', array(), $div), 284 - phutil_tag('th', array()), 285 - phutil_tag('td', array('colspan' => 3)), 286 - ))), 287 - 288 - 'r' => phutil_tag('table', array(), 289 - phutil_tag('tr', array(), array( 290 - phutil_tag('th', array()), 291 - phutil_tag('td', array()), 292 - phutil_tag('th', array()), 293 - phutil_tag('td', array('colspan' => 3), $div), 294 - ))), 295 - ); 296 256 } 297 257 298 258 private function renderViewOptionsDropdown(
+2 -1
src/applications/diffusion/controller/DiffusionDiffController.php
··· 130 130 $parser->setMask($mask); 131 131 132 132 return id(new PhabricatorChangesetResponse()) 133 - ->setRenderedChangeset($parser->renderChangeset()); 133 + ->setRenderedChangeset($parser->renderChangeset()) 134 + ->setUndoTemplates($parser->getRenderer()->renderUndoTemplates()); 134 135 } 135 136 }
+10
src/infrastructure/diff/PhabricatorChangesetResponse.php
··· 4 4 5 5 private $renderedChangeset; 6 6 private $coverage; 7 + private $undoTemplates; 7 8 8 9 public function setRenderedChangeset($rendered_changeset) { 9 10 $this->renderedChangeset = $rendered_changeset; ··· 15 16 return $this; 16 17 } 17 18 19 + public function setUndoTemplates($undo_templates) { 20 + $this->undoTemplates = $undo_templates; 21 + return $this; 22 + } 23 + 18 24 protected function buildProxy() { 19 25 return new AphrontAjaxResponse(); 20 26 } ··· 26 32 27 33 if ($this->coverage) { 28 34 $content['coverage'] = $this->coverage; 35 + } 36 + 37 + if ($this->undoTemplates) { 38 + $content['undoTemplates'] = $this->undoTemplates; 29 39 } 30 40 31 41 return $this->getProxy()->setContent($content);
+40
src/infrastructure/diff/view/PHUIDiffInlineCommentUndoView.php
··· 1 + <?php 2 + 3 + /** 4 + * Render the "Undo" action to recover discarded inline comments. 5 + * 6 + * This extends @{class:PHUIDiffInlineCommentView} so it can use the same 7 + * scaffolding code as other kinds of inline comments. 8 + */ 9 + final class PHUIDiffInlineCommentUndoView 10 + extends PHUIDiffInlineCommentView { 11 + 12 + private $isOnRight; 13 + 14 + public function setIsOnRight($is_on_right) { 15 + $this->isOnRight = $is_on_right; 16 + return $this; 17 + } 18 + 19 + public function getIsOnRight() { 20 + return $this->isOnRight; 21 + } 22 + 23 + public function render() { 24 + $link = javelin_tag( 25 + 'a', 26 + array( 27 + 'href' => '#', 28 + 'sigil' => 'differential-inline-comment-undo', 29 + ), 30 + pht('Undo')); 31 + 32 + return phutil_tag( 33 + 'div', 34 + array( 35 + 'class' => 'differential-inline-undo', 36 + ), 37 + array('Changes discarded. ', $link)); 38 + } 39 + 40 + }
+5 -3
webroot/rsrc/css/application/differential/changeset-view.css
··· 379 379 .differential-inline-undo { 380 380 padding: 4px; 381 381 text-align: center; 382 - background: #ffeeaa; 382 + background: {$lightyellow}; 383 + border: 1px solid {$yellow}; 383 384 margin: 3px 0 1px; 384 - font: 12px; 385 - color: 444444; 385 + color: {$darkgreytext}; 386 + font: {$basefont}; 387 + font-size: 12px; 386 388 } 387 389 388 390 .differential-inline-undo a {
+17
webroot/rsrc/js/application/differential/ChangesetViewManager.js
··· 38 38 _renderer: null, 39 39 _highlight: null, 40 40 _encoding: null, 41 + _undoTemplates: null, 41 42 42 43 43 44 /** ··· 193 194 var root = target.parentNode; 194 195 this._moveRows(table, root, target); 195 196 root.removeChild(target); 197 + 198 + this._onchangesetresponse(response); 196 199 }, 197 200 198 201 _moveRows: function(src, dst, before) { ··· 254 257 // complicated mess and you could lose inline comments, cursor positions, 255 258 // etc. 256 259 return (JX.Device.getDevice() == 'desktop') ? '2up' : '1up'; 260 + }, 261 + 262 + getUndoTemplates: function() { 263 + return this._undoTemplates; 257 264 }, 258 265 259 266 setEncoding: function(encoding) { ··· 333 340 this._stabilize = false; 334 341 } 335 342 343 + this._onchangesetresponse(response); 344 + }, 345 + 346 + _onchangesetresponse: function(response) { 347 + // Code shared by autoload and context responses. 348 + 336 349 if (response.coverage) { 337 350 for (var k in response.coverage) { 338 351 try { ··· 341 354 // Not terribly important. 342 355 } 343 356 } 357 + } 358 + 359 + if (response.undoTemplates) { 360 + this._undoTemplates = response.undoTemplates; 344 361 } 345 362 }, 346 363
+2 -2
webroot/rsrc/js/application/differential/behavior-edit-inline-comments.js
··· 243 243 var view = JX.ChangesetViewManager.getForNode(root); 244 244 245 245 editor = new JX.DifferentialInlineCommentEditor(config.uri) 246 - .setTemplates(config.undo_templates) 246 + .setTemplates(view.getUndoTemplates()) 247 247 .setOperation('new') 248 248 .setChangesetID(changeset) 249 249 .setLineNumber(o) ··· 335 335 var view = JX.ChangesetViewManager.getForNode(changeset_root); 336 336 337 337 editor = new JX.DifferentialInlineCommentEditor(config.uri) 338 - .setTemplates(config.undo_templates) 338 + .setTemplates(view.getUndoTemplates()) 339 339 .setOperation(op) 340 340 .setID(data.id) 341 341 .setChangesetID(data.changesetID)