Skip to content

Commit 5a4ecc7

Browse files
author
epriestley
committedJul 1, 2016
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
1 parent 189910d commit 5a4ecc7

File tree

2 files changed

+47
-16
lines changed

2 files changed

+47
-16
lines changed
 

‎src/applications/differential/controller/DifferentialRevisionViewController.php

+12-14
Original file line numberDiff line numberDiff line change
@@ -1031,28 +1031,26 @@ private function buildDiffDetailView(
10311031
);
10321032
}
10331033

1034-
$box = id(new PHUIObjectBoxView())
1035-
->setHeaderText(pht('Diff Detail'))
1036-
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
1037-
->setUser($viewer);
1034+
$tab_group = id(new PHUITabGroupView())
1035+
->setHideSingleTab(true);
10381036

1039-
$last_tab = null;
10401037
foreach ($property_lists as $key => $property_list) {
10411038
list($tab_name, $list_view) = $property_list;
10421039

1043-
$tab = id(new PHUIListItemView())
1040+
$tab = id(new PHUITabView())
10441041
->setKey($key)
1045-
->setName($tab_name);
1046-
1047-
$box->addPropertyList($list_view, $tab);
1048-
$last_tab = $tab;
1049-
}
1042+
->setName($tab_name)
1043+
->appendChild($list_view);
10501044

1051-
if ($last_tab) {
1052-
$last_tab->setSelected(true);
1045+
$tab_group->addTab($tab);
1046+
$tab_group->selectTab($key);
10531047
}
10541048

1055-
return $box;
1049+
return id(new PHUIObjectBoxView())
1050+
->setHeaderText(pht('Diff Detail'))
1051+
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
1052+
->setUser($viewer)
1053+
->addTabGroup($tab_group);
10561054
}
10571055

10581056
private function buildDiffPropertyList(

‎src/view/phui/PHUITabGroupView.php

+35-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@
33
final class PHUITabGroupView extends AphrontTagView {
44

55
private $tabs = array();
6+
private $selectedTab;
7+
8+
private $hideSingleTab;
69

710
protected function canAppendChild() {
811
return false;
912
}
1013

14+
public function setHideSingleTab($hide_single_tab) {
15+
$this->hideSingleTab = $hide_single_tab;
16+
return $this;
17+
}
18+
19+
public function getHideSingleTab() {
20+
return $this->hideSingleTab;
21+
}
22+
1123
public function addTab(PHUITabView $tab) {
1224
$key = $tab->getKey();
1325
$tab->lockKey();
@@ -25,11 +37,28 @@ public function addTab(PHUITabView $tab) {
2537
return $this;
2638
}
2739

28-
public function getSelectedTab() {
40+
public function selectTab($key) {
41+
if (empty($this->tabs[$key])) {
42+
throw new Exception(
43+
pht(
44+
'Unable to select tab ("%s") which does not exist.',
45+
$key));
46+
}
47+
48+
$this->selectedTab = $key;
49+
50+
return $this;
51+
}
52+
53+
public function getSelectedTabKey() {
2954
if (!$this->tabs) {
3055
return null;
3156
}
3257

58+
if ($this->selectedTab !== null) {
59+
return $this->selectedTab;
60+
}
61+
3362
return head($this->tabs)->getKey();
3463
}
3564

@@ -51,7 +80,7 @@ protected function getTagContent() {
5180
->setType(PHUIListView::NAVBAR_LIST);
5281
$content = array();
5382

54-
$selected_tab = $this->getSelectedTab();
83+
$selected_tab = $this->getSelectedTabKey();
5584
foreach ($this->tabs as $tab) {
5685
$item = $tab->newMenuItem();
5786
$tab_key = $tab->getKey();
@@ -74,6 +103,10 @@ protected function getTagContent() {
74103
$tab);
75104
}
76105

106+
if ($this->hideSingleTab && (count($this->tabs) == 1)) {
107+
$tabs = null;
108+
}
109+
77110
return array(
78111
$tabs,
79112
$content,

0 commit comments

Comments
 (0)
Failed to load comments.