1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-29 16:08:22 +01:00

Convert "Diff Details" tabs to PHUITabGroup

Summary:
Ref T10628. Switch this to be nicer and more modern.

  - When there's only one tab, add an option to hide it.

Test Plan:
  - Viewed normal revisions (no tabs).
  - Viewed X vs Y revisions (two tabs, rightmost tab selected by default).

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10628

Differential Revision: https://secure.phabricator.com/D16206
This commit is contained in:
epriestley 2016-06-30 16:08:56 -07:00
parent 189910d615
commit 5a4ecc7a9c
2 changed files with 47 additions and 16 deletions

View file

@ -1031,28 +1031,26 @@ final class DifferentialRevisionViewController extends DifferentialController {
);
}
$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);
->setName($tab_name)
->appendChild($list_view);
$box->addPropertyList($list_view, $tab);
$last_tab = $tab;
$tab_group->addTab($tab);
$tab_group->selectTab($key);
}
if ($last_tab) {
$last_tab->setSelected(true);
}
return $box;
return id(new PHUIObjectBoxView())
->setHeaderText(pht('Diff Detail'))
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->setUser($viewer)
->addTabGroup($tab_group);
}
private function buildDiffPropertyList(

View file

@ -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 @@ final class PHUITabGroupView extends AphrontTagView {
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 @@ final class PHUITabGroupView extends AphrontTagView {
->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 @@ final class PHUITabGroupView extends AphrontTagView {
$tab);
}
if ($this->hideSingleTab && (count($this->tabs) == 1)) {
$tabs = null;
}
return array(
$tabs,
$content,