From 7acda7e94e60473c70c67755c1094d04e4df6ace Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 7 Jun 2018 11:52:03 -0700 Subject: [PATCH] Truncate package names in diff table of contents views Summary: Ref T13151. See PHI654. Depends on D19477. If you have long package names, the table of contents (e.g., in Differential) can end up expanding to be gigantic. Getting tables to behave nicely is hard (or, at least, I can't figure it out after spending a decent amount of time on it; see also `AphrontTableView::renderSingleDisplayLine()`). I tried a bunch of things and Googled for a bit but didn't make any progress on finding a CSS solution. Just truncate the package names to get reasonable behavior without falling down any kind of CSS rabbit hole. Test Plan: - Created a package named "Very long package name...". - Created a package named "MMMMMMMMMMMMMMMMMMMMMM...". - Had them own a file in a Differential revision, viewed that revision. - Before: table is pushed out to several times the browser window width and everything is kind of a mess. - After: package names get truncated to something reasonable. {F5652953} Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13151 Differential Revision: https://secure.phabricator.com/D19478 --- .../phid/view/PHUIHandleListView.php | 15 +++++++++++++++ src/applications/phid/view/PHUIHandleView.php | 19 ++++++++++++++++++- .../view/PHUIDiffTableOfContentsItemView.php | 3 ++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/applications/phid/view/PHUIHandleListView.php b/src/applications/phid/view/PHUIHandleListView.php index d15b3d15c6..24104fe76d 100644 --- a/src/applications/phid/view/PHUIHandleListView.php +++ b/src/applications/phid/view/PHUIHandleListView.php @@ -14,6 +14,7 @@ final class PHUIHandleListView private $asInline; private $asText; private $showStateIcons; + private $glyphLimit; public function setHandleList(PhabricatorHandleList $list) { $this->handleList = $list; @@ -47,6 +48,15 @@ final class PHUIHandleListView return $this->showStateIcons; } + public function setGlyphLimit($glyph_limit) { + $this->glyphLimit = $glyph_limit; + return $this; + } + + public function getGlyphLimit() { + return $this->glyphLimit; + } + protected function getTagName() { if ($this->getAsText()) { return null; @@ -61,6 +71,7 @@ final class PHUIHandleListView $list = $this->handleList; $show_state_icons = $this->getShowStateIcons(); + $glyph_limit = $this->getGlyphLimit(); $items = array(); foreach ($list as $handle) { @@ -72,6 +83,10 @@ final class PHUIHandleListView $view->setShowStateIcon(true); } + if ($glyph_limit) { + $view->setGlyphLimit($glyph_limit); + } + $items[] = $view; } diff --git a/src/applications/phid/view/PHUIHandleView.php b/src/applications/phid/view/PHUIHandleView.php index 96ae7de025..fe3c62a9ac 100644 --- a/src/applications/phid/view/PHUIHandleView.php +++ b/src/applications/phid/view/PHUIHandleView.php @@ -18,6 +18,7 @@ final class PHUIHandleView private $useShortName; private $showHovercard; private $showStateIcon; + private $glyphLimit; public function setHandleList(PhabricatorHandleList $list) { $this->handleList = $list; @@ -58,6 +59,15 @@ final class PHUIHandleView return $this->showStateIcon; } + public function setGlyphLimit($glyph_limit) { + $this->glyphLimit = $glyph_limit; + return $this; + } + + public function getGlyphLimit() { + return $this->glyphLimit; + } + public function render() { $handle = $this->handleList[$this->handlePHID]; @@ -78,7 +88,14 @@ final class PHUIHandleView if ($this->useShortName) { $name = $handle->getName(); } else { - $name = null; + $name = $handle->getLinkName(); + } + + $glyph_limit = $this->getGlyphLimit(); + if ($glyph_limit) { + $name = id(new PhutilUTF8StringTruncator()) + ->setMaximumGlyphs($glyph_limit) + ->truncateString($name); } if ($this->showHovercard) { diff --git a/src/infrastructure/diff/view/PHUIDiffTableOfContentsItemView.php b/src/infrastructure/diff/view/PHUIDiffTableOfContentsItemView.php index 8f6e4e48d7..6d76319de8 100644 --- a/src/infrastructure/diff/view/PHUIDiffTableOfContentsItemView.php +++ b/src/infrastructure/diff/view/PHUIDiffTableOfContentsItemView.php @@ -294,7 +294,8 @@ final class PHUIDiffTableOfContentsItemView extends AphrontView { $viewer = $this->getUser(); $package_phids = mpull($packages, 'getPHID'); - return $viewer->renderHandleList($package_phids); + return $viewer->renderHandleList($package_phids) + ->setGlyphLimit(48); } private function renderRename($self, $other, $arrow) {