mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-11 23:31:03 +01:00
Replace the informal "array" subtype map with a more formal "SubtypeMap" object
Summary: Ref T13222. Ref T12588. See PHI683. To make "Create Subtask..." fancier, we need slightly more logic around subtype maps. Upgrade the plain old array into a proper object so it can have relevant methods, notably "get a list of valid child subtypes for some parent subtype". Test Plan: Created and edited tasks, changed task subtypes. Grepped for affected symbols (`newEditEngineSubtypeMap`, `newSubtypeMap`). Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13222, T12588 Differential Revision: https://secure.phabricator.com/D19852
This commit is contained in:
parent
5d54f26dac
commit
f0eefdd0b5
12 changed files with 56 additions and 15 deletions
|
@ -2976,6 +2976,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorEditEngineStaticCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineStaticCommentAction.php',
|
'PhabricatorEditEngineStaticCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineStaticCommentAction.php',
|
||||||
'PhabricatorEditEngineSubtype' => 'applications/transactions/editengine/PhabricatorEditEngineSubtype.php',
|
'PhabricatorEditEngineSubtype' => 'applications/transactions/editengine/PhabricatorEditEngineSubtype.php',
|
||||||
'PhabricatorEditEngineSubtypeInterface' => 'applications/transactions/editengine/PhabricatorEditEngineSubtypeInterface.php',
|
'PhabricatorEditEngineSubtypeInterface' => 'applications/transactions/editengine/PhabricatorEditEngineSubtypeInterface.php',
|
||||||
|
'PhabricatorEditEngineSubtypeMap' => 'applications/transactions/editengine/PhabricatorEditEngineSubtypeMap.php',
|
||||||
'PhabricatorEditEngineSubtypeTestCase' => 'applications/transactions/editengine/__tests__/PhabricatorEditEngineSubtypeTestCase.php',
|
'PhabricatorEditEngineSubtypeTestCase' => 'applications/transactions/editengine/__tests__/PhabricatorEditEngineSubtypeTestCase.php',
|
||||||
'PhabricatorEditEngineTokenizerCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineTokenizerCommentAction.php',
|
'PhabricatorEditEngineTokenizerCommentAction' => 'applications/transactions/commentaction/PhabricatorEditEngineTokenizerCommentAction.php',
|
||||||
'PhabricatorEditField' => 'applications/transactions/editfield/PhabricatorEditField.php',
|
'PhabricatorEditField' => 'applications/transactions/editfield/PhabricatorEditField.php',
|
||||||
|
@ -8729,6 +8730,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorEditEngineSettingsPanel' => 'PhabricatorSettingsPanel',
|
'PhabricatorEditEngineSettingsPanel' => 'PhabricatorSettingsPanel',
|
||||||
'PhabricatorEditEngineStaticCommentAction' => 'PhabricatorEditEngineCommentAction',
|
'PhabricatorEditEngineStaticCommentAction' => 'PhabricatorEditEngineCommentAction',
|
||||||
'PhabricatorEditEngineSubtype' => 'Phobject',
|
'PhabricatorEditEngineSubtype' => 'Phobject',
|
||||||
|
'PhabricatorEditEngineSubtypeMap' => 'Phobject',
|
||||||
'PhabricatorEditEngineSubtypeTestCase' => 'PhabricatorTestCase',
|
'PhabricatorEditEngineSubtypeTestCase' => 'PhabricatorTestCase',
|
||||||
'PhabricatorEditEngineTokenizerCommentAction' => 'PhabricatorEditEngineCommentAction',
|
'PhabricatorEditEngineTokenizerCommentAction' => 'PhabricatorEditEngineCommentAction',
|
||||||
'PhabricatorEditField' => 'Phobject',
|
'PhabricatorEditField' => 'Phobject',
|
||||||
|
|
|
@ -47,7 +47,7 @@ final class ManiphestTaskSearchEngine
|
||||||
// Hide the "Subtypes" constraint from the web UI if the install only
|
// Hide the "Subtypes" constraint from the web UI if the install only
|
||||||
// defines one task subtype, since it isn't of any use in this case.
|
// defines one task subtype, since it isn't of any use in this case.
|
||||||
$subtype_map = id(new ManiphestTask())->newEditEngineSubtypeMap();
|
$subtype_map = id(new ManiphestTask())->newEditEngineSubtypeMap();
|
||||||
$hide_subtypes = (count($subtype_map) == 1);
|
$hide_subtypes = ($subtype_map->getCount() == 1);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
id(new PhabricatorOwnersSearchField())
|
id(new PhabricatorOwnersSearchField())
|
||||||
|
|
|
@ -573,7 +573,7 @@ final class ManiphestTask extends ManiphestDAO
|
||||||
public function newSubtypeObject() {
|
public function newSubtypeObject() {
|
||||||
$subtype_key = $this->getEditEngineSubtype();
|
$subtype_key = $this->getEditEngineSubtype();
|
||||||
$subtype_map = $this->newEditEngineSubtypeMap();
|
$subtype_map = $this->newEditEngineSubtypeMap();
|
||||||
return idx($subtype_map, $subtype_key);
|
return $subtype_map->getSubtype($subtype_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -( PhabricatorFulltextInterface )--------------------------------------- */
|
/* -( PhabricatorFulltextInterface )--------------------------------------- */
|
||||||
|
|
|
@ -214,11 +214,12 @@ final class ManiphestTransaction
|
||||||
public function renderSubtypeName($value) {
|
public function renderSubtypeName($value) {
|
||||||
$object = $this->getObject();
|
$object = $this->getObject();
|
||||||
$map = $object->newEditEngineSubtypeMap();
|
$map = $object->newEditEngineSubtypeMap();
|
||||||
if (!isset($map[$value])) {
|
|
||||||
|
if (!$map->isValidSubtype($value)) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $map[$value]->getName();
|
return $map->getSubtype($value)->getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ final class ManiphestTaskSubtypeDatasource
|
||||||
$results = array();
|
$results = array();
|
||||||
|
|
||||||
$subtype_map = id(new ManiphestTask())->newEditEngineSubtypeMap();
|
$subtype_map = id(new ManiphestTask())->newEditEngineSubtypeMap();
|
||||||
foreach ($subtype_map as $key => $subtype) {
|
foreach ($subtype_map->getSubtypes() as $key => $subtype) {
|
||||||
|
|
||||||
$result = id(new PhabricatorTypeaheadResult())
|
$result = id(new PhabricatorTypeaheadResult())
|
||||||
->setIcon($subtype->getIcon())
|
->setIcon($subtype->getIcon())
|
||||||
|
|
|
@ -56,9 +56,6 @@ final class ManiphestTaskListView extends ManiphestView {
|
||||||
Javelin::initBehavior('maniphest-list-editor');
|
Javelin::initBehavior('maniphest-list-editor');
|
||||||
}
|
}
|
||||||
|
|
||||||
$subtype_map = id(new ManiphestTask())
|
|
||||||
->newEditEngineSubtypeMap();
|
|
||||||
|
|
||||||
foreach ($this->tasks as $task) {
|
foreach ($this->tasks as $task) {
|
||||||
$item = id(new PHUIObjectItemView())
|
$item = id(new PHUIObjectItemView())
|
||||||
->setUser($this->getUser())
|
->setUser($this->getUser())
|
||||||
|
|
|
@ -61,8 +61,7 @@ Choose the object **subtype** that this form should create and edit.
|
||||||
EOTEXT
|
EOTEXT
|
||||||
);
|
);
|
||||||
|
|
||||||
$map = $engine->newSubtypeMap();
|
$map = $engine->newSubtypeMap()->getDisplayMap();
|
||||||
$map = mpull($map, 'getName');
|
|
||||||
|
|
||||||
$form = id(new AphrontFormView())
|
$form = id(new AphrontFormView())
|
||||||
->setUser($viewer)
|
->setUser($viewer)
|
||||||
|
|
|
@ -182,7 +182,7 @@ final class PhabricatorEditEngineSubtype
|
||||||
$map[$key] = $subtype;
|
$map[$key] = $subtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $map;
|
return new PhabricatorEditEngineSubtypeMap($map);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
final class PhabricatorEditEngineSubtypeMap
|
||||||
|
extends Phobject {
|
||||||
|
|
||||||
|
private $subtypes;
|
||||||
|
|
||||||
|
public function __construct(array $subtypes) {
|
||||||
|
assert_instances_of($subtypes, 'PhabricatorEditEngineSubtype');
|
||||||
|
|
||||||
|
$this->subtypes = $subtypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDisplayMap() {
|
||||||
|
return mpull($this->subtypes, 'getName');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCount() {
|
||||||
|
return count($this->subtypes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isValidSubtype($subtype_key) {
|
||||||
|
return isset($this->subtypes[$subtype_key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSubtypes() {
|
||||||
|
return $this->subtypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSubtype($subtype_key) {
|
||||||
|
if (!$this->isValidSubtype($subtype_key)) {
|
||||||
|
throw new Exception(
|
||||||
|
pht(
|
||||||
|
'Subtype key "%s" does not identify a valid subtype.',
|
||||||
|
$subtype_key));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->subtypes[$subtype_key];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -2541,7 +2541,7 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($map[$new])) {
|
if (!$map->isValidSubtype($new)) {
|
||||||
$errors[] = new PhabricatorApplicationTransactionValidationError(
|
$errors[] = new PhabricatorApplicationTransactionValidationError(
|
||||||
$transaction_type,
|
$transaction_type,
|
||||||
pht('Invalid'),
|
pht('Invalid'),
|
||||||
|
|
|
@ -64,7 +64,7 @@ final class PhabricatorEditEngineConfigurationEditor
|
||||||
foreach ($xactions as $xaction) {
|
foreach ($xactions as $xaction) {
|
||||||
$new = $xaction->getNewValue();
|
$new = $xaction->getNewValue();
|
||||||
|
|
||||||
if (isset($map[$new])) {
|
if ($map->isValidSubtype($new)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ final class PhabricatorSubtypeEditEngineExtension
|
||||||
$subtype_type = PhabricatorTransactions::TYPE_SUBTYPE;
|
$subtype_type = PhabricatorTransactions::TYPE_SUBTYPE;
|
||||||
|
|
||||||
$map = $object->newEditEngineSubtypeMap();
|
$map = $object->newEditEngineSubtypeMap();
|
||||||
$options = mpull($map, 'getName');
|
$options = $map->getDisplayMap();
|
||||||
|
|
||||||
$subtype_field = id(new PhabricatorSelectEditField())
|
$subtype_field = id(new PhabricatorSelectEditField())
|
||||||
->setKey(self::EDITKEY)
|
->setKey(self::EDITKEY)
|
||||||
|
@ -45,7 +45,7 @@ final class PhabricatorSubtypeEditEngineExtension
|
||||||
|
|
||||||
// If subtypes are configured, enable changing them from the bulk editor
|
// If subtypes are configured, enable changing them from the bulk editor
|
||||||
// and comment action stack.
|
// and comment action stack.
|
||||||
if (count($map) > 1) {
|
if ($map->getCount() > 1) {
|
||||||
$subtype_field
|
$subtype_field
|
||||||
->setBulkEditLabel(pht('Change subtype to'))
|
->setBulkEditLabel(pht('Change subtype to'))
|
||||||
->setCommentActionLabel(pht('Change Subtype'))
|
->setCommentActionLabel(pht('Change Subtype'))
|
||||||
|
|
Loading…
Reference in a new issue