1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-02 09:58:24 +01:00

In Conduit, let checkbox constraints self-document

Summary:
Ref T13195. Ref PHI851. Currently, checkbox constraints don't tell you what values are supported on the API page.

You can figure this out with "Inspect Element" or by viewing the source code, but just render a nice table instead.

Test Plan: {F5862969}

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13195

Differential Revision: https://secure.phabricator.com/D19641
This commit is contained in:
epriestley 2018-09-05 10:06:47 -07:00
parent a20f0674a9
commit 5a38b75f16
5 changed files with 86 additions and 1 deletions

View file

@ -313,6 +313,7 @@ phutil_register_library_map(array(
'ConduitCallTestCase' => 'applications/conduit/call/__tests__/ConduitCallTestCase.php',
'ConduitColumnsParameterType' => 'applications/conduit/parametertype/ConduitColumnsParameterType.php',
'ConduitConnectConduitAPIMethod' => 'applications/conduit/method/ConduitConnectConduitAPIMethod.php',
'ConduitConstantDescription' => 'applications/conduit/data/ConduitConstantDescription.php',
'ConduitEpochParameterType' => 'applications/conduit/parametertype/ConduitEpochParameterType.php',
'ConduitException' => 'applications/conduit/protocol/exception/ConduitException.php',
'ConduitGetCapabilitiesConduitAPIMethod' => 'applications/conduit/method/ConduitGetCapabilitiesConduitAPIMethod.php',
@ -5628,6 +5629,7 @@ phutil_register_library_map(array(
'ConduitCallTestCase' => 'PhabricatorTestCase',
'ConduitColumnsParameterType' => 'ConduitParameterType',
'ConduitConnectConduitAPIMethod' => 'ConduitAPIMethod',
'ConduitConstantDescription' => 'Phobject',
'ConduitEpochParameterType' => 'ConduitParameterType',
'ConduitException' => 'Exception',
'ConduitGetCapabilitiesConduitAPIMethod' => 'ConduitAPIMethod',

View file

@ -0,0 +1,26 @@
<?php
final class ConduitConstantDescription extends Phobject {
private $key;
private $value;
public function setKey($key) {
$this->key = $key;
return $this;
}
public function getKey() {
return $this->key;
}
public function setValue($value) {
$this->value = $value;
return $this;
}
public function getValue() {
return $this->value;
}
}

View file

@ -190,15 +190,26 @@ EOTEXT
$fields,
array('ids', 'phids')) + $fields;
$constant_lists = array();
$rows = array();
foreach ($fields as $field) {
$key = $field->getConduitKey();
$label = $field->getLabel();
$constants = $field->newConduitConstants();
$type_object = $field->getConduitParameterType();
if ($type_object) {
$type = $type_object->getTypeName();
$description = $field->getDescription();
if ($constants) {
$description = array(
$description,
' ',
phutil_tag('em', array(), pht('(See table below.)')),
);
}
} else {
$type = null;
$description = phutil_tag('em', array(), pht('Not supported.'));
@ -210,6 +221,35 @@ EOTEXT
$type,
$description,
);
if ($constants) {
$constant_lists[] = $this->buildRemarkup(
pht(
'Constants supported by the `%s` constraint:',
'statuses'));
$constants_rows = array();
foreach ($constants as $constant) {
$constants_rows[] = array(
$constant->getKey(),
$constant->getValue(),
);
}
$constants_table = id(new AphrontTableView($constants_rows))
->setHeaders(
array(
pht('Key'),
pht('Value'),
))
->setColumnClasses(
array(
'pre',
'wide',
));
$constant_lists[] = $constants_table;
}
}
$table = id(new AphrontTableView($rows))
@ -233,7 +273,8 @@ EOTEXT
->setCollapsed(true)
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->appendChild($this->buildRemarkup($info))
->appendChild($table);
->appendChild($table)
->appendChild($constant_lists);
}
private function buildOrderBox(

View file

@ -49,4 +49,16 @@ final class PhabricatorSearchCheckboxesField
return new ConduitStringListParameterType();
}
public function newConduitConstants() {
$list = array();
foreach ($this->getOptions() as $key => $option) {
$list[] = id(new ConduitConstantDescription())
->setKey($key)
->setValue($option);
}
return $list;
}
}

View file

@ -382,6 +382,10 @@ abstract class PhabricatorSearchField extends Phobject {
return $this->enableForConduit;
}
public function newConduitConstants() {
return array();
}
/* -( Utility Methods )----------------------------------------------------- */