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
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Row scaffold for 2up (side-by-side) changeset views.
|
||||
*
|
||||
* Although this scaffold is normally straightforward, it may also accept
|
||||
* two inline comments and display them adjacently.
|
||||
*/
|
||||
final class PHUIDiffTwoUpInlineCommentRowScaffold
|
||||
extends PHUIDiffInlineCommentRowScaffold {
|
||||
|
||||
public function render() {
|
||||
$inlines = $this->getInlineViews();
|
||||
|
||||
if (!$inlines) {
|
||||
throw new Exception(
|
||||
pht('Two-up inline row scaffold must have at least one inline view.'));
|
||||
}
|
||||
|
||||
if (count($inlines) > 2) {
|
||||
throw new Exception(
|
||||
pht('Two-up inline row scaffold must have at most two inline views.'));
|
||||
}
|
||||
|
||||
if (count($inlines) == 1) {
|
||||
$inline = head($inlines);
|
||||
if ($inline->getIsOnRight()) {
|
||||
$left_side = null;
|
||||
$right_side = $inline;
|
||||
} else {
|
||||
$left_side = $inline;
|
||||
$right_side = null;
|
||||
}
|
||||
} else {
|
||||
list($u, $v) = $inlines;
|
||||
|
||||
if ($u->getIsOnRight() == $v->getIsOnRight()) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Two-up inline row scaffold must have one comment on the left and '.
|
||||
'one comment on the right when showing two comments.'));
|
||||
}
|
||||
|
||||
if ($v->getIsOnRight()) {
|
||||
$left_side = $u;
|
||||
$right_side = $v;
|
||||
} else {
|
||||
$left_side = $v;
|
||||
$right_side = $u;
|
||||
}
|
||||
}
|
||||
|
||||
$left_attrs = array(
|
||||
'class' => 'left',
|
||||
);
|
||||
|
||||
$right_attrs = array(
|
||||
'colspan' => 3,
|
||||
'class' => 'right3',
|
||||
);
|
||||
|
||||
$cells = array(
|
||||
phutil_tag('th', array()),
|
||||
phutil_tag('td', $left_attrs, $left_side),
|
||||
phutil_tag('th', array()),
|
||||
phutil_tag('td', $right_attrs, $right_side),
|
||||
);
|
||||
|
||||
return phutil_tag('tr', array(), $cells);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user