diff --git a/src/applications/differential/controller/DifferentialRevisionViewController.php b/src/applications/differential/controller/DifferentialRevisionViewController.php --- a/src/applications/differential/controller/DifferentialRevisionViewController.php +++ b/src/applications/differential/controller/DifferentialRevisionViewController.php @@ -1031,28 +1031,26 @@ ); } - $box = id(new PHUIObjectBoxView()) - ->setHeaderText(pht('Diff Detail')) - ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) - ->setUser($viewer); + $tab_group = id(new PHUITabGroupView()) + ->setHideSingleTab(true); - $last_tab = null; foreach ($property_lists as $key => $property_list) { list($tab_name, $list_view) = $property_list; - $tab = id(new PHUIListItemView()) + $tab = id(new PHUITabView()) ->setKey($key) - ->setName($tab_name); - - $box->addPropertyList($list_view, $tab); - $last_tab = $tab; - } + ->setName($tab_name) + ->appendChild($list_view); - if ($last_tab) { - $last_tab->setSelected(true); + $tab_group->addTab($tab); + $tab_group->selectTab($key); } - return $box; + return id(new PHUIObjectBoxView()) + ->setHeaderText(pht('Diff Detail')) + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) + ->setUser($viewer) + ->addTabGroup($tab_group); } private function buildDiffPropertyList( diff --git a/src/view/phui/PHUITabGroupView.php b/src/view/phui/PHUITabGroupView.php --- a/src/view/phui/PHUITabGroupView.php +++ b/src/view/phui/PHUITabGroupView.php @@ -3,11 +3,23 @@ final class PHUITabGroupView extends AphrontTagView { private $tabs = array(); + private $selectedTab; + + private $hideSingleTab; protected function canAppendChild() { return false; } + public function setHideSingleTab($hide_single_tab) { + $this->hideSingleTab = $hide_single_tab; + return $this; + } + + public function getHideSingleTab() { + return $this->hideSingleTab; + } + public function addTab(PHUITabView $tab) { $key = $tab->getKey(); $tab->lockKey(); @@ -25,11 +37,28 @@ return $this; } - public function getSelectedTab() { + public function selectTab($key) { + if (empty($this->tabs[$key])) { + throw new Exception( + pht( + 'Unable to select tab ("%s") which does not exist.', + $key)); + } + + $this->selectedTab = $key; + + return $this; + } + + public function getSelectedTabKey() { if (!$this->tabs) { return null; } + if ($this->selectedTab !== null) { + return $this->selectedTab; + } + return head($this->tabs)->getKey(); } @@ -51,7 +80,7 @@ ->setType(PHUIListView::NAVBAR_LIST); $content = array(); - $selected_tab = $this->getSelectedTab(); + $selected_tab = $this->getSelectedTabKey(); foreach ($this->tabs as $tab) { $item = $tab->newMenuItem(); $tab_key = $tab->getKey(); @@ -74,6 +103,10 @@ $tab); } + if ($this->hideSingleTab && (count($this->tabs) == 1)) { + $tabs = null; + } + return array( $tabs, $content,