1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 16:52:41 +01:00

Make DiffusionCommitSearch accept modern (string) constants

Summary:
Depends on D19650. Ref T13197. Allow `SearchCheckboxesField` to have a "deprecated" map of older aliases, then convert them to modern values.

On the API method page, show all the values.

This technically resolves the issue in PHI841, although I still plan to migrate behind this.

Test Plan:
{F5875363}

- Queried audits, fiddled with `?status=1,audited`, etc.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13197

Differential Revision: https://secure.phabricator.com/D19651
This commit is contained in:
epriestley 2018-09-10 12:07:36 -07:00
parent 853a816b3c
commit 8eb8e8e1d8
5 changed files with 73 additions and 20 deletions

View file

@ -94,15 +94,6 @@ final class PhabricatorAuditCommitStatusConstants extends Phobject {
return idx($this->spec, 'closed');
}
public static function getStatusNameMap() {
$map = self::getMap();
return ipull($map, 'name', 'legacy');
}
public static function getStatusName($code) {
return idx(self::getStatusNameMap(), $code, pht('Unknown'));
}
public static function getOpenStatusConstants() {
$constants = array();
foreach (self::getMap() as $map) {
@ -113,16 +104,22 @@ final class PhabricatorAuditCommitStatusConstants extends Phobject {
return $constants;
}
public static function getStatusColor($code) {
public static function newOptions() {
$map = self::getMap();
$map = ipull($map, 'color', 'legacy');
return idx($map, $code);
return ipull($map, 'name');
}
public static function getStatusIcon($code) {
public static function newDeprecatedOptions() {
$map = self::getMap();
$map = ipull($map, 'icon', 'legacy');
return idx($map, $code);
$results = array();
foreach ($map as $key => $spec) {
if (isset($spec['legacy'])) {
$results[$spec['legacy']] = $key;
}
}
return $results;
}
private static function getMap() {

View file

@ -92,7 +92,9 @@ final class PhabricatorCommitSearchEngine
->setLabel(pht('Audit Status'))
->setKey('statuses')
->setAliases(array('status'))
->setOptions(PhabricatorAuditCommitStatusConstants::getStatusNameMap())
->setOptions(PhabricatorAuditCommitStatusConstants::newOptions())
->setDeprecatedOptions(
PhabricatorAuditCommitStatusConstants::newDeprecatedOptions())
->setDescription(pht('Find commits with given audit statuses.')),
id(new PhabricatorSearchDatasourceField())
->setLabel(pht('Repositories'))

View file

@ -4,6 +4,7 @@ final class ConduitConstantDescription extends Phobject {
private $key;
private $value;
private $isDeprecated;
public function setKey($key) {
$this->key = $key;
@ -23,4 +24,13 @@ final class ConduitConstantDescription extends Phobject {
return $this->value;
}
public function setIsDeprecated($is_deprecated) {
$this->isDeprecated = $is_deprecated;
return $this;
}
public function getIsDeprecated() {
return $this->isDeprecated;
}
}

View file

@ -230,9 +230,20 @@ EOTEXT
$constants_rows = array();
foreach ($constants as $constant) {
if ($constant->getIsDeprecated()) {
$icon = id(new PHUIIconView())
->setIcon('fa-exclamation-triangle', 'red');
} else {
$icon = null;
}
$constants_rows[] = array(
$constant->getKey(),
$constant->getValue(),
array(
$icon,
' ',
$constant->getValue(),
),
);
}
@ -244,7 +255,7 @@ EOTEXT
))
->setColumnClasses(
array(
'pre',
'mono',
'wide',
));

View file

@ -4,6 +4,7 @@ final class PhabricatorSearchCheckboxesField
extends PhabricatorSearchField {
private $options;
private $deprecatedOptions = array();
public function setOptions(array $options) {
$this->options = $options;
@ -14,6 +15,15 @@ final class PhabricatorSearchCheckboxesField
return $this->options;
}
public function setDeprecatedOptions(array $deprecated_options) {
$this->deprecatedOptions = $deprecated_options;
return $this;
}
public function getDeprecatedOptions() {
return $this->deprecatedOptions;
}
protected function getDefaultValue() {
return array();
}
@ -23,11 +33,12 @@ final class PhabricatorSearchCheckboxesField
return array();
}
return $value;
return $this->getCanonicalValue($value);
}
protected function getValueFromRequest(AphrontRequest $request, $key) {
return $this->getListFromRequest($request, $key);
$value = $this->getListFromRequest($request, $key);
return $this->getCanonicalValue($value);
}
protected function newControl() {
@ -58,7 +69,29 @@ final class PhabricatorSearchCheckboxesField
->setValue($option);
}
foreach ($this->getDeprecatedOptions() as $key => $value) {
$list[] = id(new ConduitConstantDescription())
->setKey($key)
->setIsDeprecated(true)
->setValue(pht('Deprecated alias for "%s".', $value));
}
return $list;
}
private function getCanonicalValue(array $values) {
// Always map the current normal options to themselves.
$normal_options = array_fuse(array_keys($this->getOptions()));
// Map deprecated values to their new values.
$deprecated_options = $this->getDeprecatedOptions();
$map = $normal_options + $deprecated_options;
foreach ($values as $key => $value) {
$values[$key] = idx($map, $value, $value);
}
return $values;
}
}