Skip to content

Commit 4948a21

Browse files
author
epriestley
committedMar 2, 2017
Allow tasks to be searched by subtype
Summary: Ref T12314. Allow tasks to be queried by subtype using a typeahead. Open to a better default icon. I'll probably let you configure them later. Just hide this constraint if there's only one subtype. Test Plan: - Searched for subtypes. - Verified that the control hides if there is only one subtype. {F3492293} Reviewers: chad Reviewed By: chad Maniphest Tasks: T12314 Differential Revision: https://secure.phabricator.com/D17444
1 parent 4a061b1 commit 4948a21

File tree

5 files changed

+97
-0
lines changed

5 files changed

+97
-0
lines changed
 

‎src/__phutil_library_map__.php

+2
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,7 @@
15251525
'ManiphestTaskStatusHeraldAction' => 'applications/maniphest/herald/ManiphestTaskStatusHeraldAction.php',
15261526
'ManiphestTaskStatusHeraldField' => 'applications/maniphest/herald/ManiphestTaskStatusHeraldField.php',
15271527
'ManiphestTaskStatusTestCase' => 'applications/maniphest/constants/__tests__/ManiphestTaskStatusTestCase.php',
1528+
'ManiphestTaskSubtypeDatasource' => 'applications/maniphest/typeahead/ManiphestTaskSubtypeDatasource.php',
15281529
'ManiphestTaskTestCase' => 'applications/maniphest/__tests__/ManiphestTaskTestCase.php',
15291530
'ManiphestTaskTitleHeraldField' => 'applications/maniphest/herald/ManiphestTaskTitleHeraldField.php',
15301531
'ManiphestTransaction' => 'applications/maniphest/storage/ManiphestTransaction.php',
@@ -6424,6 +6425,7 @@
64246425
'ManiphestTaskStatusHeraldAction' => 'HeraldAction',
64256426
'ManiphestTaskStatusHeraldField' => 'ManiphestTaskHeraldField',
64266427
'ManiphestTaskStatusTestCase' => 'PhabricatorTestCase',
6428+
'ManiphestTaskSubtypeDatasource' => 'PhabricatorTypeaheadDatasource',
64276429
'ManiphestTaskTestCase' => 'PhabricatorTestCase',
64286430
'ManiphestTaskTitleHeraldField' => 'ManiphestTaskHeraldField',
64296431
'ManiphestTransaction' => 'PhabricatorApplicationTransaction',

‎src/applications/maniphest/query/ManiphestTaskSearchEngine.php

+18
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public function newQuery() {
4444
}
4545

4646
protected function buildCustomSearchFields() {
47+
// Hide the "Subtypes" constraint from the web UI if the install only
48+
// defines one task subtype, since it isn't of any use in this case.
49+
$subtype_map = id(new ManiphestTask())->newEditEngineSubtypeMap();
50+
$hide_subtypes = (count($subtype_map) == 1);
51+
4752
return array(
4853
id(new PhabricatorOwnersSearchField())
4954
->setLabel(pht('Assigned To'))
@@ -73,6 +78,14 @@ protected function buildCustomSearchFields() {
7378
pht('Search for tasks with given priorities.'))
7479
->setConduitParameterType(new ConduitIntListParameterType())
7580
->setDatasource(new ManiphestTaskPriorityDatasource()),
81+
id(new PhabricatorSearchDatasourceField())
82+
->setLabel(pht('Subtypes'))
83+
->setKey('subtypes')
84+
->setAliases(array('subtype'))
85+
->setDescription(
86+
pht('Search for tasks with given subtypes.'))
87+
->setDatasource(new ManiphestTaskSubtypeDatasource())
88+
->setIsHidden($hide_subtypes),
7689
id(new PhabricatorSearchTextField())
7790
->setLabel(pht('Contains Words'))
7891
->setKey('fulltext'),
@@ -130,6 +143,7 @@ protected function getDefaultFieldOrder() {
130143
'subscriberPHIDs',
131144
'statuses',
132145
'priorities',
146+
'subtypes',
133147
'fulltext',
134148
'hasParents',
135149
'hasSubtasks',
@@ -178,6 +192,10 @@ protected function buildQueryFromParameters(array $map) {
178192
$query->withPriorities($map['priorities']);
179193
}
180194

195+
if ($map['subtypes']) {
196+
$query->withSubtypes($map['subtypes']);
197+
}
198+
181199
if ($map['createdStart']) {
182200
$query->withDateCreatedAfter($map['createdStart']);
183201
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
final class ManiphestTaskSubtypeDatasource
4+
extends PhabricatorTypeaheadDatasource {
5+
6+
public function getBrowseTitle() {
7+
return pht('Browse Subtypes');
8+
}
9+
10+
public function getPlaceholderText() {
11+
return pht('Type a task subtype name...');
12+
}
13+
14+
public function getDatasourceApplicationClass() {
15+
return 'PhabricatorManiphestApplication';
16+
}
17+
18+
public function loadResults() {
19+
$results = $this->buildResults();
20+
return $this->filterResultsAgainstTokens($results);
21+
}
22+
23+
protected function renderSpecialTokens(array $values) {
24+
return $this->renderTokensFromResults($this->buildResults(), $values);
25+
}
26+
27+
private function buildResults() {
28+
$results = array();
29+
30+
$subtype_map = id(new ManiphestTask())->newEditEngineSubtypeMap();
31+
foreach ($subtype_map as $key => $subtype) {
32+
33+
$result = id(new PhabricatorTypeaheadResult())
34+
->setIcon($subtype->getIcon())
35+
->setPHID($key)
36+
->setName($subtype->getName());
37+
38+
$results[$key] = $result;
39+
}
40+
41+
return $results;
42+
}
43+
44+
}

‎src/applications/search/field/PhabricatorSearchField.php

+29
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ abstract class PhabricatorSearchField extends Phobject {
1717
private $aliases = array();
1818
private $errors = array();
1919
private $description;
20+
private $isHidden;
2021

2122

2223
/* -( Configuring Fields )------------------------------------------------- */
@@ -188,6 +189,30 @@ public function getDescription() {
188189
}
189190

190191

192+
/**
193+
* Hide this field from the web UI.
194+
*
195+
* @param bool True to hide the field from the web UI.
196+
* @return this
197+
* @task config
198+
*/
199+
public function setIsHidden($is_hidden) {
200+
$this->isHidden = $is_hidden;
201+
return $this;
202+
}
203+
204+
205+
/**
206+
* Should this field be hidden from the web UI?
207+
*
208+
* @return bool True to hide the field in the web UI.
209+
* @task config
210+
*/
211+
public function getIsHidden() {
212+
return $this->isHidden;
213+
}
214+
215+
191216
/* -( Handling Errors )---------------------------------------------------- */
192217

193218

@@ -273,6 +298,10 @@ protected function newControl() {
273298

274299

275300
protected function renderControl() {
301+
if ($this->getIsHidden()) {
302+
return null;
303+
}
304+
276305
$control = $this->newControl();
277306

278307
if (!$control) {

‎src/applications/transactions/editengine/PhabricatorEditEngineSubtype.php

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public function getName() {
2727
return $this->name;
2828
}
2929

30+
public function getIcon() {
31+
return 'fa-drivers-license-o';
32+
}
33+
3034
public static function validateSubtypeKey($subtype) {
3135
if (strlen($subtype) > 64) {
3236
throw new Exception(

0 commit comments

Comments
 (0)
Failed to load comments.