From 68d05934a796c4add09339d350cc35976de58eb3 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 12 Feb 2016 09:05:05 -0800 Subject: [PATCH] Don't show un-completeable results in people/project autocomplete Summary: Fixes T10285. - If a result (like a milestone) has no primary hashtag, try to fill in a secondary hashtag. - If we can't find any hashtag, don't return the result. This produces these behaviors: - By default, you can't autocomplete milestones. - If you give one a hashtag, you can. We might want to give milestones "special" hashtags eventually (like `#xyz/33`) but this fixes the confusing/broken behavior in the UI and we can wait for a better use case for letting you autocomplete milestones, I think. Also, don't try to cycle hashtags when renaming milestones. This was a little inconsistent before. Test Plan: - Autocompleted normal projects. - Autocompleted milestones with explicit hashtags. - No autocomplete entry for milestones with no special hashtags. - Used normal typeahead to get tag-less milestones to make sure I didn't break anything. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10285 Differential Revision: https://secure.phabricator.com/D15261 --- .../PhabricatorProjectTransactionEditor.php | 9 +++++---- .../PhabricatorProjectDatasource.php | 20 ++++++++++++++++++- .../control/PhabricatorRemarkupControl.php | 6 +++++- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/applications/project/editor/PhabricatorProjectTransactionEditor.php b/src/applications/project/editor/PhabricatorProjectTransactionEditor.php index c9594122d8..b1aab1e417 100644 --- a/src/applications/project/editor/PhabricatorProjectTransactionEditor.php +++ b/src/applications/project/editor/PhabricatorProjectTransactionEditor.php @@ -169,11 +169,12 @@ final class PhabricatorProjectTransactionEditor case PhabricatorProjectTransaction::TYPE_NAME: // First, add the old name as a secondary slug; this is helpful // for renames and generally a good thing to do. - if ($old !== null) { - $this->addSlug($object, $old, false); + if (!$this->getIsMilestone()) { + if ($old !== null) { + $this->addSlug($object, $old, false); + } + $this->addSlug($object, $new, false); } - $this->addSlug($object, $new, false); - return; case PhabricatorProjectTransaction::TYPE_SLUGS: $old = $xaction->getOldValue(); diff --git a/src/applications/project/typeahead/PhabricatorProjectDatasource.php b/src/applications/project/typeahead/PhabricatorProjectDatasource.php index 33fb8df0e9..40d8dbb0e6 100644 --- a/src/applications/project/typeahead/PhabricatorProjectDatasource.php +++ b/src/applications/project/typeahead/PhabricatorProjectDatasource.php @@ -38,6 +38,8 @@ final class PhabricatorProjectDatasource $query->withIsMilestone(false); } + $for_autocomplete = $this->getParameter('autocomplete'); + $projs = $this->executeQuery($query); $projs = mpull($projs, null, 'getPHID'); @@ -58,6 +60,23 @@ final class PhabricatorProjectDatasource if (!isset($has_cols[$proj->getPHID()])) { continue; } + + $slug = $proj->getPrimarySlug(); + if (!strlen($slug)) { + foreach ($proj->getSlugs() as $slug_object) { + $slug = $slug_object->getSlug(); + if (strlen($slug)) { + break; + } + } + } + + // If we're building results for the autocompleter and this project + // doesn't have any usable slugs, don't return it as a result. + if ($for_autocomplete && !strlen($slug)) { + continue; + } + $closed = null; if ($proj->isArchived()) { $closed = pht('Archived'); @@ -78,7 +97,6 @@ final class PhabricatorProjectDatasource ->setPriorityType('proj') ->setClosed($closed); - $slug = $proj->getPrimarySlug(); if (strlen($slug)) { $proj_result->setAutocomplete('#'.$slug); } diff --git a/src/view/form/control/PhabricatorRemarkupControl.php b/src/view/form/control/PhabricatorRemarkupControl.php index 11388d257e..eeec4971da 100644 --- a/src/view/form/control/PhabricatorRemarkupControl.php +++ b/src/view/form/control/PhabricatorRemarkupControl.php @@ -45,7 +45,11 @@ final class PhabricatorRemarkupControl extends AphrontFormTextAreaControl { $root_id = celerity_generate_unique_node_id(); $user_datasource = new PhabricatorPeopleDatasource(); - $proj_datasource = new PhabricatorProjectDatasource(); + $proj_datasource = id(new PhabricatorProjectDatasource()) + ->setParameters( + array( + 'autocomplete' => 1, + )); Javelin::initBehavior( 'phabricator-remarkup-assist',