Skip to content

Commit 1352be8

Browse files
author
epriestley
committed
Begin separating inline comment scaffolding from other renderers
Summary: Ref T2009. Inline comments have "scaffolding", which is basically some empty table cells/rows around them to get the layout correct. The scaffolding depends on the renderer, since the cells are different for side-by-side vs unified diffs. This is currently duplicated all over the place: - Edit view has 1up/2up. - Detail view has 1up/2up. - 1up renderer has 1up. - 2up renderer has four separate copies of the 2up logic. These all have subtle differences, which are mostly bugs. Start making the scaffolding more composable so we can get rid of that mess. Test Plan: Added, edited, and removed inline comments on unified and side-by-side diffs. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T2009 Differential Revision: https://secure.phabricator.com/D11997
1 parent 1088d34 commit 1352be8

12 files changed

+204
-45
lines changed

src/__phutil_library_map__.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,11 @@
11381138
'PHUICrumbsView' => 'view/phui/PHUICrumbsView.php',
11391139
'PHUIDiffInlineCommentDetailView' => 'infrastructure/diff/view/PHUIDiffInlineCommentDetailView.php',
11401140
'PHUIDiffInlineCommentEditView' => 'infrastructure/diff/view/PHUIDiffInlineCommentEditView.php',
1141+
'PHUIDiffInlineCommentRowScaffold' => 'infrastructure/diff/view/PHUIDiffInlineCommentRowScaffold.php',
1142+
'PHUIDiffInlineCommentTableScaffold' => 'infrastructure/diff/view/PHUIDiffInlineCommentTableScaffold.php',
11411143
'PHUIDiffInlineCommentView' => 'infrastructure/diff/view/PHUIDiffInlineCommentView.php',
1144+
'PHUIDiffOneUpInlineCommentRowScaffold' => 'infrastructure/diff/view/PHUIDiffOneUpInlineCommentRowScaffold.php',
1145+
'PHUIDiffTwoUpInlineCommentRowScaffold' => 'infrastructure/diff/view/PHUIDiffTwoUpInlineCommentRowScaffold.php',
11421146
'PHUIDocumentExample' => 'applications/uiexample/examples/PHUIDocumentExample.php',
11431147
'PHUIDocumentView' => 'view/phui/PHUIDocumentView.php',
11441148
'PHUIFeedStoryExample' => 'applications/uiexample/examples/PHUIFeedStoryExample.php',
@@ -4367,7 +4371,11 @@
43674371
'PHUICrumbsView' => 'AphrontView',
43684372
'PHUIDiffInlineCommentDetailView' => 'PHUIDiffInlineCommentView',
43694373
'PHUIDiffInlineCommentEditView' => 'PHUIDiffInlineCommentView',
4374+
'PHUIDiffInlineCommentRowScaffold' => 'AphrontView',
4375+
'PHUIDiffInlineCommentTableScaffold' => 'AphrontView',
43704376
'PHUIDiffInlineCommentView' => 'AphrontView',
4377+
'PHUIDiffOneUpInlineCommentRowScaffold' => 'PHUIDiffInlineCommentRowScaffold',
4378+
'PHUIDiffTwoUpInlineCommentRowScaffold' => 'PHUIDiffInlineCommentRowScaffold',
43714379
'PHUIDocumentExample' => 'PhabricatorUIExample',
43724380
'PHUIDocumentView' => 'AphrontTagView',
43734381
'PHUIFeedStoryExample' => 'PhabricatorUIExample',

src/applications/differential/render/DifferentialChangesetHTMLRenderer.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,20 @@
33
abstract class DifferentialChangesetHTMLRenderer
44
extends DifferentialChangesetRenderer {
55

6+
public static function getHTMLRendererByKey($key) {
7+
switch ($key) {
8+
case '1up':
9+
return new DifferentialChangesetOneUpRenderer();
10+
case '2up':
11+
default:
12+
return new DifferentialChangesetTwoUpRenderer();
13+
}
14+
throw new Exception(pht('Unknown HTML renderer "%s"!', $key));
15+
}
16+
617
abstract protected function getRendererTableClass();
18+
abstract public function getRowScaffoldForInline(
19+
PHUIDiffInlineCommentView $view);
720

821
protected function renderChangeTypeHeader($force) {
922
$changeset = $this->getChangeset();

src/applications/differential/render/DifferentialChangesetOneUpRenderer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ public function renderTextChange(
9595
$inline = $this->buildInlineComment(
9696
$p['comment'],
9797
$p['right']);
98-
$inline->setBuildScaffolding(false);
9998

10099
$out[] = phutil_tag(
101100
'tr',
@@ -160,4 +159,9 @@ public function renderFileChange(
160159
throw new PhutilMethodNotImplementedException();
161160
}
162161

162+
public function getRowScaffoldForInline(PHUIDiffInlineCommentView $view) {
163+
return id(new PHUIDiffOneUpInlineCommentRowScaffold())
164+
->addInlineView($view);
165+
}
166+
163167
}

src/applications/differential/render/DifferentialChangesetTwoUpRenderer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,9 @@ public function renderFileChange($old_file = null,
397397
return $this->renderChangesetTable($output);
398398
}
399399

400+
public function getRowScaffoldForInline(PHUIDiffInlineCommentView $view) {
401+
return id(new PHUIDiffTwoUpInlineCommentRowScaffold())
402+
->addInlineView($view);
403+
}
404+
400405
}

src/infrastructure/diff/PhabricatorInlineCommentController.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public function processRequest() {
114114

115115
$edit_dialog->addHiddenInput('id', $this->getCommentID());
116116
$edit_dialog->addHiddenInput('op', 'edit');
117+
$edit_dialog->addHiddenInput('renderer', $this->getRenderer());
117118

118119
$edit_dialog->appendChild(
119120
$this->renderTextArea(
@@ -236,11 +237,16 @@ private function buildRenderedCommentResponse(
236237
$view = id(new PHUIDiffInlineCommentDetailView())
237238
->setInlineComment($inline)
238239
->setOnRight($on_right)
239-
->setBuildScaffolding(true)
240240
->setMarkupEngine($engine)
241241
->setHandles($handles)
242-
->setEditable(true)
243-
->setRenderer($this->getRenderer());
242+
->setEditable(true);
243+
244+
$renderer = DifferentialChangesetHTMLRenderer::getHTMLRendererByKey(
245+
$this->getRenderer());
246+
247+
$view = $renderer->getRowScaffoldForInline($view);
248+
$view = id(new PHUIDiffInlineCommentTableScaffold())
249+
->addRowScaffold($view);
244250

245251
return id(new AphrontAjaxResponse())
246252
->setContent(

src/infrastructure/diff/view/PHUIDiffInlineCommentDetailView.php

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ final class PHUIDiffInlineCommentDetailView
55

66
private $inlineComment;
77
private $onRight;
8-
private $buildScaffolding;
98
private $handles;
109
private $markupEngine;
1110
private $editable;
1211
private $preview;
1312
private $allowReply;
1413
private $renderer;
1514

15+
public function getIsOnRight() {
16+
return $this->onRight;
17+
}
18+
1619
public function setInlineComment(PhabricatorInlineCommentInterface $comment) {
1720
$this->inlineComment = $comment;
1821
return $this;
@@ -23,11 +26,6 @@ public function setOnRight($on_right) {
2326
return $this;
2427
}
2528

26-
public function setBuildScaffolding($scaffold) {
27-
$this->buildScaffolding = $scaffold;
28-
return $this;
29-
}
30-
3129
public function setHandles(array $handles) {
3230
assert_instances_of($handles, 'PhabricatorObjectHandle');
3331
$this->handles = $handles;
@@ -254,40 +252,7 @@ public function render() {
254252
phutil_tag_div('phabricator-remarkup', $content)),
255253
));
256254

257-
return $this->scaffoldMarkup($markup);
258-
}
259-
260-
private function scaffoldMarkup($markup) {
261-
if (!$this->buildScaffolding) {
262-
return $markup;
263-
}
264-
265-
if ($this->renderer == '1up') {
266-
$cells = array(
267-
phutil_tag('th', array()),
268-
phutil_tag('th', array()),
269-
phutil_tag(
270-
'td',
271-
array('colspan' => 3, 'class' => 'right3'),
272-
$markup),
273-
);
274-
} else {
275-
$left_markup = !$this->onRight ? $markup : '';
276-
$right_markup = $this->onRight ? $markup : '';
277-
278-
$cells = array(
279-
phutil_tag('th', array()),
280-
phutil_tag('td', array('class' => 'left'), $left_markup),
281-
phutil_tag('th', array()),
282-
phutil_tag(
283-
'td',
284-
array('colspan' => 3, 'class' => 'right3'),
285-
$right_markup),
286-
);
287-
}
288-
289-
$row = phutil_tag('tr', array(), $cells);
290-
return phutil_tag('table', array(), $row);
255+
return $markup;
291256
}
292257

293258
}

src/infrastructure/diff/view/PHUIDiffInlineCommentEditView.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ final class PHUIDiffInlineCommentEditView
1111
private $length;
1212
private $renderer;
1313

14+
public function getIsOnRight() {
15+
return $this->onRight;
16+
}
17+
1418
public function setRenderer($renderer) {
1519
$this->renderer = $renderer;
1620
return $this;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/**
4+
* Wraps an inline comment in a table row.
5+
*
6+
* Inline comments need different wrapping cells when shown in unified vs
7+
* side-by-side diffs, as the two tables have different layouts. This wraps
8+
* an inline comment element in an appropriate table row.
9+
*/
10+
abstract class PHUIDiffInlineCommentRowScaffold extends AphrontView {
11+
12+
private $views = array();
13+
14+
public function getInlineViews() {
15+
return $this->views;
16+
}
17+
18+
public function addInlineView(PHUIDiffInlineCommentView $view) {
19+
$this->views[] = $view;
20+
return $this;
21+
}
22+
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/**
4+
* Wraps an inline comment row scaffold in a table.
5+
*
6+
* This scaffold is used to ship inlines over the wire to the client, so they
7+
* arrive in a form that's easy to mainipulate (a valid table node).
8+
*/
9+
final class PHUIDiffInlineCommentTableScaffold extends AphrontView {
10+
11+
private $rows = array();
12+
13+
public function addRowScaffold(PHUIDiffInlineCommentRowScaffold $row) {
14+
$this->rows[] = $row;
15+
return $this;
16+
}
17+
18+
public function render() {
19+
return phutil_tag('table', array(), $this->rows);
20+
}
21+
22+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
<?php
22

3-
abstract class PHUIDiffInlineCommentView extends AphrontView {}
3+
abstract class PHUIDiffInlineCommentView extends AphrontView {
4+
5+
abstract public function getIsOnRight();
6+
7+
}

0 commit comments

Comments
 (0)