From 067d12d7168a580bce695cb26331df785f86c2e9 Mon Sep 17 00:00:00 2001 From: Josh Cox Date: Thu, 25 Aug 2016 20:53:08 -0400 Subject: [PATCH] Converted the pinned applications selector to a typeahead. Summary: Fixes T11513. Previously the selector was just a giant dropdown which was just... just too much. Now there's a handy typeahead. Test Plan: Happy Path: Go to `Settings -> Home Page -> Pin Application`, start typing in the form then select one of the options. Click on "Pin Application". The application should now be in the list. Other paths: - Type nothing into the box and submit, nothing should happen. - Choose an application that is already pinned. The list should stay the same. - Type nonsense into the box and submit, nothing should happen. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: chad, Korvin, epriestley, yelirekim Maniphest Tasks: T11513 Differential Revision: https://secure.phabricator.com/D16459 --- .../PhabricatorApplicationDatasource.php | 4 +++- ...habricatorHomePreferencesSettingsPanel.php | 22 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/applications/meta/typeahead/PhabricatorApplicationDatasource.php b/src/applications/meta/typeahead/PhabricatorApplicationDatasource.php index 176c3554cf..7dddeda53b 100644 --- a/src/applications/meta/typeahead/PhabricatorApplicationDatasource.php +++ b/src/applications/meta/typeahead/PhabricatorApplicationDatasource.php @@ -38,7 +38,9 @@ final class PhabricatorApplicationDatasource ->setDisplayType($application->getShortDescription()) ->setImageuRI($application->getIconURI()) ->setPriorityType('apps') - ->setImageSprite('phabricator-search-icon '.$img); + ->setImageSprite('phabricator-search-icon '.$img) + ->setIcon($application->getIcon()) + ->addAttribute($application->getShortDescription()); } return $this->filterResultsAgainstTokens($results); diff --git a/src/applications/settings/panel/PhabricatorHomePreferencesSettingsPanel.php b/src/applications/settings/panel/PhabricatorHomePreferencesSettingsPanel.php index fafe62ee4e..d12db30f83 100644 --- a/src/applications/settings/panel/PhabricatorHomePreferencesSettingsPanel.php +++ b/src/applications/settings/panel/PhabricatorHomePreferencesSettingsPanel.php @@ -67,7 +67,19 @@ final class PhabricatorHomePreferencesSettingsPanel unset($options['PhabricatorApplicationsApplication']); if ($request->isFormPost()) { - $pin = $request->getStr('pin'); + $pins = $request->getArr('pin'); + $phid = head($pins); + $app = id(new PhabricatorApplicationQuery()) + ->setViewer($viewer) + ->withPHIDs(array($phid)) + ->executeOne(); + if ($app) { + $pin = get_class($app); + } else { + // This likely means the user submitted an empty form + // which will cause nothing to happen. + $pin = ''; + } if (isset($options[$pin]) && !in_array($pin, $pinned)) { $pinned[] = $pin; @@ -78,18 +90,18 @@ final class PhabricatorHomePreferencesSettingsPanel } } - $options_control = id(new AphrontFormSelectControl()) + $options_control = id(new AphrontFormTokenizerControl()) ->setName('pin') ->setLabel(pht('Application')) - ->setOptions($options) - ->setDisabledOptions(array_keys($app_list)); + ->setDatasource(new PhabricatorApplicationDatasource()) + ->setLimit(1); $form = id(new AphrontFormView()) ->setViewer($viewer) ->addHiddenInput('add', 'true') ->appendRemarkupInstructions( pht('Choose an application to pin to your home page.')) - ->appendChild($options_control); + ->appendControl($options_control); return $this->newDialog() ->setWidth(AphrontDialogView::WIDTH_FORM)