mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 08:42:41 +01:00
When picking a default menu item to render, don't pick disabled items
Summary: Depends on D20358. Fixes T12871. After refactoring, we can now tell when a "storage" menu item generated only disabled "display" menu items, and not pick any of them as the default rendering. This means that if you're looking at a portal/menu with several dashboards, but can't see some at the top, you'll get the first one you can see. Also clean up a lot of minor issues with less-common states. Test Plan: - Created a portal with two private dashboards and a public dashboard. - Viewed it as another user, saw the default view show the dashboard I can actually see. - Minor fix: Disabled and enabled the hard-coded "Home" item, now worked cleanly with the right menu state. - Minor fix: added a motivator panel. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T12871 Differential Revision: https://secure.phabricator.com/D20359
This commit is contained in:
parent
5192ae4750
commit
dfe47157d3
5 changed files with 89 additions and 49 deletions
|
@ -30,10 +30,21 @@ final class PhabricatorDashboardPortalProfileMenuEngine
|
||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function newNoMenuItemsView() {
|
protected function newNoMenuItemsView(array $items) {
|
||||||
|
$object = $this->getProfileObject();
|
||||||
|
$builtins = $this->getBuiltinProfileItems($object);
|
||||||
|
|
||||||
|
if (count($items) <= count($builtins)) {
|
||||||
return $this->newEmptyView(
|
return $this->newEmptyView(
|
||||||
pht('New Portal'),
|
pht('New Portal'),
|
||||||
pht('Use "Edit Menu" to add menu items to this portal.'));
|
pht('Use "Edit Menu" to add menu items to this portal.'));
|
||||||
|
} else {
|
||||||
|
return $this->newEmptyValue(
|
||||||
|
pht('No Portal Content'),
|
||||||
|
pht(
|
||||||
|
'None of the visible menu items in this portal can render any '.
|
||||||
|
'content.'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,10 +142,14 @@ abstract class PhabricatorProfileMenuEngine extends Phobject {
|
||||||
|
|
||||||
$view_list = $this->newProfileMenuItemViewList();
|
$view_list = $this->newProfileMenuItemViewList();
|
||||||
|
|
||||||
$selected_item = $this->selectItem(
|
if ($is_view) {
|
||||||
$view_list,
|
$selected_item = $this->selectViewItem($view_list, $item_id);
|
||||||
$item_id,
|
} else {
|
||||||
$is_view);
|
if (!strlen($item_id)) {
|
||||||
|
$item_id = self::ITEM_MANAGE;
|
||||||
|
}
|
||||||
|
$selected_item = $this->selectEditItem($view_list, $item_id);
|
||||||
|
}
|
||||||
|
|
||||||
switch ($item_action) {
|
switch ($item_action) {
|
||||||
case 'view':
|
case 'view':
|
||||||
|
@ -177,8 +181,6 @@ abstract class PhabricatorProfileMenuEngine extends Phobject {
|
||||||
$crumbs = $controller->buildApplicationCrumbsForEditEngine();
|
$crumbs = $controller->buildApplicationCrumbsForEditEngine();
|
||||||
|
|
||||||
if (!$is_view) {
|
if (!$is_view) {
|
||||||
$navigation->selectFilter(self::ITEM_MANAGE);
|
|
||||||
|
|
||||||
if ($selected_item) {
|
if ($selected_item) {
|
||||||
if ($selected_item->getCustomPHID()) {
|
if ($selected_item->getCustomPHID()) {
|
||||||
$edit_mode = 'custom';
|
$edit_mode = 'custom';
|
||||||
|
@ -222,7 +224,7 @@ abstract class PhabricatorProfileMenuEngine extends Phobject {
|
||||||
|
|
||||||
$crumbs->addTextCrumb($selected_item->getDisplayName());
|
$crumbs->addTextCrumb($selected_item->getDisplayName());
|
||||||
} else {
|
} else {
|
||||||
$content = $this->newNoMenuItemsView();
|
$content = $this->newNoContentView($this->getItems());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$content) {
|
if (!$content) {
|
||||||
|
@ -320,8 +322,6 @@ abstract class PhabricatorProfileMenuEngine extends Phobject {
|
||||||
return $page;
|
return $page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private function getItems() {
|
private function getItems() {
|
||||||
if ($this->items === null) {
|
if ($this->items === null) {
|
||||||
$this->items = $this->loadItems(self::MODE_COMBINED);
|
$this->items = $this->loadItems(self::MODE_COMBINED);
|
||||||
|
@ -1258,10 +1258,10 @@ abstract class PhabricatorProfileMenuEngine extends Phobject {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function newNoMenuItemsView() {
|
protected function newNoContentView(array $items) {
|
||||||
return $this->newEmptyView(
|
return $this->newEmptyView(
|
||||||
pht('No Menu Items'),
|
pht('No Content'),
|
||||||
pht('There are no menu items.'));
|
pht('No visible menu items can render content.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1298,15 +1298,13 @@ abstract class PhabricatorProfileMenuEngine extends Phobject {
|
||||||
return $view_list;
|
return $view_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function selectItem(
|
private function selectViewItem(
|
||||||
PhabricatorProfileMenuItemViewList $view_list,
|
PhabricatorProfileMenuItemViewList $view_list,
|
||||||
$item_id,
|
$item_id) {
|
||||||
$want_default) {
|
|
||||||
|
|
||||||
// Figure out which view's content we're going to render. In most cases,
|
// Figure out which view's content we're going to render. In most cases,
|
||||||
// the URI tells us. If we don't have an identifier in the URI, we'll
|
// the URI tells us. If we don't have an identifier in the URI, we'll
|
||||||
// render the default view instead if this is a workflow that falls back
|
// render the default view instead.
|
||||||
// to default rendering.
|
|
||||||
|
|
||||||
$selected_view = null;
|
$selected_view = null;
|
||||||
if (strlen($item_id)) {
|
if (strlen($item_id)) {
|
||||||
|
@ -1315,13 +1313,11 @@ abstract class PhabricatorProfileMenuEngine extends Phobject {
|
||||||
$selected_view = head($item_views);
|
$selected_view = head($item_views);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($want_default) {
|
|
||||||
$default_views = $view_list->getDefaultViews();
|
$default_views = $view_list->getDefaultViews();
|
||||||
if ($default_views) {
|
if ($default_views) {
|
||||||
$selected_view = head($default_views);
|
$selected_view = head($default_views);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($selected_view) {
|
if ($selected_view) {
|
||||||
$view_list->setSelectedView($selected_view);
|
$view_list->setSelectedView($selected_view);
|
||||||
|
@ -1333,5 +1329,32 @@ abstract class PhabricatorProfileMenuEngine extends Phobject {
|
||||||
return $selected_item;
|
return $selected_item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function selectEditItem(
|
||||||
|
PhabricatorProfileMenuItemViewList $view_list,
|
||||||
|
$item_id) {
|
||||||
|
|
||||||
|
// First, try to select a visible item using the normal view selection
|
||||||
|
// pathway. If this works, it also highlights the menu properly.
|
||||||
|
|
||||||
|
if ($item_id) {
|
||||||
|
$selected_item = $this->selectViewItem($view_list, $item_id);
|
||||||
|
if ($selected_item) {
|
||||||
|
return $selected_item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we didn't find an item in the view list, we may be enabling an item
|
||||||
|
// which is currently disabled or editing an item which is not generating
|
||||||
|
// any actual items in the menu.
|
||||||
|
|
||||||
|
foreach ($this->getItems() as $item) {
|
||||||
|
if ($item->matchesIdentifier($item_id)) {
|
||||||
|
return $item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,34 +62,15 @@ final class PhabricatorProfileMenuItemViewList
|
||||||
public function getViewsWithItemIdentifier($identifier) {
|
public function getViewsWithItemIdentifier($identifier) {
|
||||||
$views = $this->getItemViews();
|
$views = $this->getItemViews();
|
||||||
|
|
||||||
if (!strlen($identifier)) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ctype_digit($identifier)) {
|
|
||||||
$identifier_int = (int)$identifier;
|
|
||||||
} else {
|
|
||||||
$identifier_int = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$identifier_str = (string)$identifier;
|
|
||||||
|
|
||||||
$results = array();
|
$results = array();
|
||||||
foreach ($views as $view) {
|
foreach ($views as $view) {
|
||||||
$config = $view->getMenuItemConfiguration();
|
$config = $view->getMenuItemConfiguration();
|
||||||
|
|
||||||
if ($identifier_int !== null) {
|
if (!$config->matchesIdentifier($identifier)) {
|
||||||
$config_id = (int)$config->getID();
|
|
||||||
if ($config_id === $identifier_int) {
|
|
||||||
$results[] = $view;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($config->getBuiltinKey() === $identifier_str) {
|
|
||||||
$results[] = $view;
|
$results[] = $view;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
|
@ -112,6 +93,13 @@ final class PhabricatorProfileMenuItemViewList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove disabled views.
|
||||||
|
foreach ($views as $key => $view) {
|
||||||
|
if ($view->getDisabled()) {
|
||||||
|
unset($views[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If this engine supports pinning items and we have candidate views from a
|
// If this engine supports pinning items and we have candidate views from a
|
||||||
// valid pinned item, they are the default views.
|
// valid pinned item, they are the default views.
|
||||||
if ($can_pin) {
|
if ($can_pin) {
|
||||||
|
|
|
@ -70,7 +70,7 @@ final class PhabricatorMotivatorProfileMenuItem
|
||||||
->setName($fact_name)
|
->setName($fact_name)
|
||||||
->setIcon($fact_icon)
|
->setIcon($fact_icon)
|
||||||
->setTooltip($fact_text)
|
->setTooltip($fact_text)
|
||||||
->setHref('#');
|
->setURI('#');
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
$item,
|
$item,
|
||||||
|
|
|
@ -237,6 +237,24 @@ final class PhabricatorProfileMenuItemConfiguration
|
||||||
return $this->isTailItem;
|
return $this->isTailItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function matchesIdentifier($identifier) {
|
||||||
|
if (!strlen($identifier)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctype_digit($identifier)) {
|
||||||
|
if ((int)$this->getID() === (int)$identifier) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((string)$this->getBuiltinKey() === (string)$identifier) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue