mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-08 22:01:03 +01:00
Allow numeric constants to act as aliases for task priorities in the web UI <select />
Summary: Ref T12124. This is a fairly narrow fix for existing saved EditEngine forms with a default priority value. These saved forms have a numeric (or probably "string-numeric") default value, like "50". They lost their meaning after D18111, when "50" no longer appears in the dropdown. Instead, these forms all select the highest available priority. At time of writing, this form was broken on this install, for example: > https://secure.phabricator.com/transactions/editengine/maniphest.task/view/13/ Additionally, `/task/edit/form/123/?priority=...` (for templating forms) stopped working with `priority=50`. This isn't nearly as important, but a larger and more sudden compatiblity break than we need to make. Add support for an "alias map" on `<select />` controls, so if the value comes in with something we don't recognize we'll treat it like some other value. Then alias all the numeric constants -- and other keywords -- to the right constants. This ended up only affecting the `<select />` control in the web UI. Test Plan: - On `stable`, created a form with "Priority: Low". - Before patch: form has "Priority: Unbreak Now!" on `master`. - After patch: form has "Priority: Low" again. - Used `?priority=25`, `?priority=wish`, `?priority=wishlist` to template forms: all forms worked. Reviewers: amckinley, chad Reviewed By: amckinley Maniphest Tasks: T12124 Differential Revision: https://secure.phabricator.com/D18134
This commit is contained in:
parent
cd19ddf111
commit
474d528c3b
4 changed files with 86 additions and 4 deletions
|
@ -43,6 +43,58 @@ final class ManiphestTaskPriority extends ManiphestConstants {
|
|||
return $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the canonical keyword for a given priority constant.
|
||||
*
|
||||
* @return string|null Keyword, or `null` if no keyword is configured.
|
||||
*/
|
||||
public static function getKeywordForTaskPriority($priority) {
|
||||
$map = self::getConfig();
|
||||
|
||||
$spec = idx($map, $priority);
|
||||
if (!$spec) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$keywords = idx($spec, 'keywords');
|
||||
if (!$keywords) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return head($keywords);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a map of supported alternate names for each priority.
|
||||
*
|
||||
* Keys are aliases, like "wish" and "wishlist". Values are canonical
|
||||
* priority keywords, like "wishlist".
|
||||
*
|
||||
* @return map<string, string> Map of aliases to canonical priority keywords.
|
||||
*/
|
||||
public static function getTaskPriorityAliasMap() {
|
||||
$keyword_map = self::getTaskPriorityKeywordsMap();
|
||||
|
||||
$result = array();
|
||||
foreach ($keyword_map as $key => $keywords) {
|
||||
$target = self::getKeywordForTaskPriority($key);
|
||||
if ($target === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// NOTE: Include the raw priority value, like "25", in the list of
|
||||
// aliases. This supports legacy sources like saved EditEngine forms.
|
||||
$result[$key] = $target;
|
||||
|
||||
foreach ($keywords as $keyword) {
|
||||
$result[$keyword] = $target;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the priorities and their related short (one-word) descriptions.
|
||||
|
|
|
@ -77,6 +77,8 @@ final class ManiphestEditEngine
|
|||
$status_map = $this->getTaskStatusMap($object);
|
||||
$priority_map = $this->getTaskPriorityMap($object);
|
||||
|
||||
$alias_map = ManiphestTaskPriority::getTaskPriorityAliasMap();
|
||||
|
||||
if ($object->isClosed()) {
|
||||
$default_status = ManiphestTaskStatus::getDefaultStatus();
|
||||
} else {
|
||||
|
@ -217,6 +219,7 @@ EODOCS
|
|||
->setIsCopyable(true)
|
||||
->setValue($object->getPriorityKeyword())
|
||||
->setOptions($priority_map)
|
||||
->setOptionAliases($alias_map)
|
||||
->setCommentActionLabel(pht('Change Priority')),
|
||||
);
|
||||
|
||||
|
|
|
@ -247,10 +247,13 @@ final class ManiphestTask extends ManiphestDAO
|
|||
|
||||
public function getPriorityKeyword() {
|
||||
$priority = $this->getPriority();
|
||||
$map = ManiphestTaskPriority::getTaskPriorityKeywordsMap();
|
||||
$default = array(ManiphestTaskPriority::UNKNOWN_PRIORITY_KEYWORD);
|
||||
$keywords = idx($map, $priority, $default);
|
||||
return head($keywords);
|
||||
|
||||
$keyword = ManiphestTaskPriority::getKeywordForTaskPriority($priority);
|
||||
if ($keyword !== null) {
|
||||
return $keyword;
|
||||
}
|
||||
|
||||
return ManiphestTaskPriority::UNKNOWN_PRIORITY_KEYWORD;
|
||||
}
|
||||
|
||||
private function comparePriorityTo(ManiphestTask $other) {
|
||||
|
|
|
@ -4,6 +4,7 @@ final class PhabricatorSelectEditField
|
|||
extends PhabricatorEditField {
|
||||
|
||||
private $options;
|
||||
private $optionAliases = array();
|
||||
|
||||
public function setOptions(array $options) {
|
||||
$this->options = $options;
|
||||
|
@ -17,6 +18,29 @@ final class PhabricatorSelectEditField
|
|||
return $this->options;
|
||||
}
|
||||
|
||||
public function setOptionAliases(array $option_aliases) {
|
||||
$this->optionAliases = $option_aliases;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOptionAliases() {
|
||||
return $this->optionAliases;
|
||||
}
|
||||
|
||||
protected function getValueForControl() {
|
||||
$value = parent::getValueForControl();
|
||||
|
||||
$options = $this->getOptions();
|
||||
if (!isset($options[$value])) {
|
||||
$aliases = $this->getOptionAliases();
|
||||
if (isset($aliases[$value])) {
|
||||
$value = $aliases[$value];
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
protected function newControl() {
|
||||
return id(new AphrontFormSelectControl())
|
||||
->setOptions($this->getOptions());
|
||||
|
|
Loading…
Reference in a new issue