@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+89 -49
+15 -4
src/applications/dashboard/engine/PhabricatorDashboardPortalProfileMenuEngine.php
··· 30 30 return $items; 31 31 } 32 32 33 - protected function newNoMenuItemsView() { 34 - return $this->newEmptyView( 35 - pht('New Portal'), 36 - pht('Use "Edit Menu" to add menu items to this portal.')); 33 + protected function newNoMenuItemsView(array $items) { 34 + $object = $this->getProfileObject(); 35 + $builtins = $this->getBuiltinProfileItems($object); 36 + 37 + if (count($items) <= count($builtins)) { 38 + return $this->newEmptyView( 39 + pht('New Portal'), 40 + pht('Use "Edit Menu" to add menu items to this portal.')); 41 + } else { 42 + return $this->newEmptyValue( 43 + pht('No Portal Content'), 44 + pht( 45 + 'None of the visible menu items in this portal can render any '. 46 + 'content.')); 47 + } 37 48 } 38 49 39 50 }
+45 -22
src/applications/search/engine/PhabricatorProfileMenuEngine.php
··· 142 142 143 143 $view_list = $this->newProfileMenuItemViewList(); 144 144 145 - $selected_item = $this->selectItem( 146 - $view_list, 147 - $item_id, 148 - $is_view); 145 + if ($is_view) { 146 + $selected_item = $this->selectViewItem($view_list, $item_id); 147 + } else { 148 + if (!strlen($item_id)) { 149 + $item_id = self::ITEM_MANAGE; 150 + } 151 + $selected_item = $this->selectEditItem($view_list, $item_id); 152 + } 149 153 150 154 switch ($item_action) { 151 155 case 'view': ··· 177 181 $crumbs = $controller->buildApplicationCrumbsForEditEngine(); 178 182 179 183 if (!$is_view) { 180 - $navigation->selectFilter(self::ITEM_MANAGE); 181 - 182 184 if ($selected_item) { 183 185 if ($selected_item->getCustomPHID()) { 184 186 $edit_mode = 'custom'; ··· 222 224 223 225 $crumbs->addTextCrumb($selected_item->getDisplayName()); 224 226 } else { 225 - $content = $this->newNoMenuItemsView(); 227 + $content = $this->newNoContentView($this->getItems()); 226 228 } 227 229 228 230 if (!$content) { ··· 319 321 320 322 return $page; 321 323 } 322 - 323 - 324 324 325 325 private function getItems() { 326 326 if ($this->items === null) { ··· 1258 1258 )); 1259 1259 } 1260 1260 1261 - protected function newNoMenuItemsView() { 1261 + protected function newNoContentView(array $items) { 1262 1262 return $this->newEmptyView( 1263 - pht('No Menu Items'), 1264 - pht('There are no menu items.')); 1263 + pht('No Content'), 1264 + pht('No visible menu items can render content.')); 1265 1265 } 1266 1266 1267 1267 ··· 1298 1298 return $view_list; 1299 1299 } 1300 1300 1301 - private function selectItem( 1301 + private function selectViewItem( 1302 1302 PhabricatorProfileMenuItemViewList $view_list, 1303 - $item_id, 1304 - $want_default) { 1303 + $item_id) { 1305 1304 1306 1305 // Figure out which view's content we're going to render. In most cases, 1307 1306 // the URI tells us. If we don't have an identifier in the URI, we'll 1308 - // render the default view instead if this is a workflow that falls back 1309 - // to default rendering. 1307 + // render the default view instead. 1310 1308 1311 1309 $selected_view = null; 1312 1310 if (strlen($item_id)) { ··· 1315 1313 $selected_view = head($item_views); 1316 1314 } 1317 1315 } else { 1318 - if ($want_default) { 1319 - $default_views = $view_list->getDefaultViews(); 1320 - if ($default_views) { 1321 - $selected_view = head($default_views); 1322 - } 1316 + $default_views = $view_list->getDefaultViews(); 1317 + if ($default_views) { 1318 + $selected_view = head($default_views); 1323 1319 } 1324 1320 } 1325 1321 ··· 1331 1327 } 1332 1328 1333 1329 return $selected_item; 1330 + } 1331 + 1332 + private function selectEditItem( 1333 + PhabricatorProfileMenuItemViewList $view_list, 1334 + $item_id) { 1335 + 1336 + // First, try to select a visible item using the normal view selection 1337 + // pathway. If this works, it also highlights the menu properly. 1338 + 1339 + if ($item_id) { 1340 + $selected_item = $this->selectViewItem($view_list, $item_id); 1341 + if ($selected_item) { 1342 + return $selected_item; 1343 + } 1344 + } 1345 + 1346 + // If we didn't find an item in the view list, we may be enabling an item 1347 + // which is currently disabled or editing an item which is not generating 1348 + // any actual items in the menu. 1349 + 1350 + foreach ($this->getItems() as $item) { 1351 + if ($item->matchesIdentifier($item_id)) { 1352 + return $item; 1353 + } 1354 + } 1355 + 1356 + return null; 1334 1357 } 1335 1358 1336 1359
+10 -22
src/applications/search/engine/PhabricatorProfileMenuItemViewList.php
··· 62 62 public function getViewsWithItemIdentifier($identifier) { 63 63 $views = $this->getItemViews(); 64 64 65 - if (!strlen($identifier)) { 66 - return array(); 67 - } 68 - 69 - if (ctype_digit($identifier)) { 70 - $identifier_int = (int)$identifier; 71 - } else { 72 - $identifier_int = null; 73 - } 74 - 75 - $identifier_str = (string)$identifier; 76 - 77 65 $results = array(); 78 66 foreach ($views as $view) { 79 67 $config = $view->getMenuItemConfiguration(); 80 68 81 - if ($identifier_int !== null) { 82 - $config_id = (int)$config->getID(); 83 - if ($config_id === $identifier_int) { 84 - $results[] = $view; 85 - continue; 86 - } 69 + if (!$config->matchesIdentifier($identifier)) { 70 + continue; 87 71 } 88 72 89 - if ($config->getBuiltinKey() === $identifier_str) { 90 - $results[] = $view; 91 - continue; 92 - } 73 + $results[] = $view; 93 74 } 94 75 95 76 return $results; ··· 109 90 if (!$config->canMakeDefault()) { 110 91 unset($views[$key]); 111 92 continue; 93 + } 94 + } 95 + 96 + // Remove disabled views. 97 + foreach ($views as $key => $view) { 98 + if ($view->getDisabled()) { 99 + unset($views[$key]); 112 100 } 113 101 } 114 102
+1 -1
src/applications/search/menuitem/PhabricatorMotivatorProfileMenuItem.php
··· 70 70 ->setName($fact_name) 71 71 ->setIcon($fact_icon) 72 72 ->setTooltip($fact_text) 73 - ->setHref('#'); 73 + ->setURI('#'); 74 74 75 75 return array( 76 76 $item,
+18
src/applications/search/storage/PhabricatorProfileMenuItemConfiguration.php
··· 237 237 return $this->isTailItem; 238 238 } 239 239 240 + public function matchesIdentifier($identifier) { 241 + if (!strlen($identifier)) { 242 + return false; 243 + } 244 + 245 + if (ctype_digit($identifier)) { 246 + if ((int)$this->getID() === (int)$identifier) { 247 + return true; 248 + } 249 + } 250 + 251 + if ((string)$this->getBuiltinKey() === (string)$identifier) { 252 + return true; 253 + } 254 + 255 + return false; 256 + } 257 + 240 258 241 259 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 242 260