1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-06 20:08:29 +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()) $tab_group = id(new PHUITabGroupView())
->setHeaderText(pht('Diff Detail')) ->setHideSingleTab(true);
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->setUser($viewer);
$last_tab = null;
foreach ($property_lists as $key => $property_list) { foreach ($property_lists as $key => $property_list) {
list($tab_name, $list_view) = $property_list; list($tab_name, $list_view) = $property_list;
$tab = id(new PHUIListItemView()) $tab = id(new PHUITabView())
->setKey($key) ->setKey($key)
->setName($tab_name); ->setName($tab_name)
->appendChild($list_view);
$box->addPropertyList($list_view, $tab); $tab_group->addTab($tab);
$last_tab = $tab; $tab_group->selectTab($key);
} }
if ($last_tab) { return id(new PHUIObjectBoxView())
$last_tab->setSelected(true); ->setHeaderText(pht('Diff Detail'))
} ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->setUser($viewer)
return $box; ->addTabGroup($tab_group);
} }
private function buildDiffPropertyList( private function buildDiffPropertyList(

View file

@ -3,11 +3,23 @@
final class PHUITabGroupView extends AphrontTagView { final class PHUITabGroupView extends AphrontTagView {
private $tabs = array(); private $tabs = array();
private $selectedTab;
private $hideSingleTab;
protected function canAppendChild() { protected function canAppendChild() {
return false; 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) { public function addTab(PHUITabView $tab) {
$key = $tab->getKey(); $key = $tab->getKey();
$tab->lockKey(); $tab->lockKey();
@ -25,11 +37,28 @@ final class PHUITabGroupView extends AphrontTagView {
return $this; 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) { if (!$this->tabs) {
return null; return null;
} }
if ($this->selectedTab !== null) {
return $this->selectedTab;
}
return head($this->tabs)->getKey(); return head($this->tabs)->getKey();
} }
@ -51,7 +80,7 @@ final class PHUITabGroupView extends AphrontTagView {
->setType(PHUIListView::NAVBAR_LIST); ->setType(PHUIListView::NAVBAR_LIST);
$content = array(); $content = array();
$selected_tab = $this->getSelectedTab(); $selected_tab = $this->getSelectedTabKey();
foreach ($this->tabs as $tab) { foreach ($this->tabs as $tab) {
$item = $tab->newMenuItem(); $item = $tab->newMenuItem();
$tab_key = $tab->getKey(); $tab_key = $tab->getKey();
@ -74,6 +103,10 @@ final class PHUITabGroupView extends AphrontTagView {
$tab); $tab);
} }
if ($this->hideSingleTab && (count($this->tabs) == 1)) {
$tabs = null;
}
return array( return array(
$tabs, $tabs,
$content, $content,