@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.

On portals, make the "selected" / "default" logic more straightforward

Summary:
Depends on D20349. Ref T13275. Currently, a default item is selected as a side effect of generating the full list of items, for absolutely no reason.

The logic to pick the currently selected item can also be separated out pretty easily.

(And fix a bug in with a weird edge case in projects.)

This doesn't really change anything, but it will probably make T12949 a bit easier to fix.

Test Plan: Viewed Home / projects / portals, clicked various links, got same default/selection behavior as before.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13275

Differential Revision: https://secure.phabricator.com/D20352

+67 -61
+1 -1
src/applications/project/controller/PhabricatorProjectViewController.php
··· 28 28 $default_key = PhabricatorProject::ITEM_MANAGE; 29 29 } 30 30 31 - switch ($default->getBuiltinKey()) { 31 + switch ($default_key) { 32 32 case PhabricatorProject::ITEM_WORKBOARD: 33 33 $controller_object = new PhabricatorProjectBoardViewController(); 34 34 break;
+66 -60
src/applications/search/engine/PhabricatorProfileMenuEngine.php
··· 6 6 private $profileObject; 7 7 private $customPHID; 8 8 private $items; 9 - private $defaultItem; 10 9 private $controller; 11 10 private $navigation; 12 11 private $showNavigation = true; ··· 79 78 } 80 79 81 80 public function getDefaultItem() { 82 - $this->getItems(); 83 - return $this->defaultItem; 81 + return $this->pickDefaultItem($this->getItems()); 84 82 } 85 83 86 84 public function setShowNavigation($show) { ··· 154 152 155 153 $item_list = $this->getItems(); 156 154 157 - $selected_item = null; 158 - if (strlen($item_id)) { 159 - $item_id_int = (int)$item_id; 160 - foreach ($item_list as $item) { 161 - if ($item_id_int) { 162 - if ((int)$item->getID() === $item_id_int) { 163 - $selected_item = $item; 164 - break; 165 - } 166 - } 167 - 168 - $builtin_key = $item->getBuiltinKey(); 169 - if ($builtin_key === (string)$item_id) { 170 - $selected_item = $item; 171 - break; 172 - } 173 - } 174 - } 175 - 176 - if (!$selected_item) { 177 - if ($is_view) { 178 - $selected_item = $this->getDefaultItem(); 179 - } 180 - } 155 + $selected_item = $this->pickSelectedItem( 156 + $item_list, 157 + $item_id, 158 + $is_view); 181 159 182 160 switch ($item_action) { 183 161 case 'view': ··· 485 463 } 486 464 } 487 465 488 - $items = $this->arrangeItems($items, $mode); 489 - 490 - // Make sure exactly one valid item is marked as default. 491 - $default = null; 492 - $first = null; 493 - foreach ($items as $item) { 494 - if (!$item->canMakeDefault() || $item->isDisabled()) { 495 - continue; 496 - } 497 - 498 - // If this engine doesn't support pinning items, don't respect any 499 - // setting which might be present in the database. 500 - if ($this->isMenuEnginePinnable()) { 501 - if ($item->isDefault()) { 502 - $default = $item; 503 - break; 504 - } 505 - } 506 - 507 - if ($first === null) { 508 - $first = $item; 509 - } 510 - } 511 - 512 - if (!$default) { 513 - $default = $first; 514 - } 515 - 516 - if ($default) { 517 - $this->setDefaultItem($default); 518 - } 519 - 520 - return $items; 466 + return $this->arrangeItems($items, $mode); 521 467 } 522 468 523 469 private function loadBuiltinProfileItems($mode) { ··· 1359 1305 return $this->newEmptyView( 1360 1306 pht('No Menu Items'), 1361 1307 pht('There are no menu items.')); 1308 + } 1309 + 1310 + private function pickDefaultItem(array $items) { 1311 + // Remove all the items which can not be the default item. 1312 + foreach ($items as $key => $item) { 1313 + if (!$item->canMakeDefault()) { 1314 + unset($items[$key]); 1315 + continue; 1316 + } 1317 + 1318 + if ($item->isDisabled()) { 1319 + unset($items[$key]); 1320 + continue; 1321 + } 1322 + } 1323 + 1324 + // If this engine supports pinning items and a valid item is pinned, 1325 + // pick that item as the default. 1326 + if ($this->isMenuEnginePinnable()) { 1327 + foreach ($items as $key => $item) { 1328 + if ($item->isDefault()) { 1329 + return $item; 1330 + } 1331 + } 1332 + } 1333 + 1334 + // If we have some other valid items, pick the first one as the default. 1335 + if ($items) { 1336 + return head($items); 1337 + } 1338 + 1339 + return null; 1340 + } 1341 + 1342 + private function pickSelectedItem(array $items, $item_id, $is_view) { 1343 + if (strlen($item_id)) { 1344 + $item_id_int = (int)$item_id; 1345 + foreach ($items as $item) { 1346 + if ($item_id_int) { 1347 + if ((int)$item->getID() === $item_id_int) { 1348 + return $item; 1349 + } 1350 + } 1351 + 1352 + $builtin_key = $item->getBuiltinKey(); 1353 + if ($builtin_key === (string)$item_id) { 1354 + return $item; 1355 + } 1356 + } 1357 + 1358 + // Nothing matches the selected item ID, so we don't have a valid 1359 + // selection. 1360 + return null; 1361 + } 1362 + 1363 + if ($is_view) { 1364 + return $this->pickDefaultItem($items); 1365 + } 1366 + 1367 + return null; 1362 1368 } 1363 1369 1364 1370 }