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

Update Herald rule creation workflow to use more modern UI elements

Summary: Ref T13480. Creating a rule in Herald currently uses the older radio-button flow. Update it to the "clickable menu" flow to simplify it a little bit.

Test Plan: Created new personal, object, and global rules. Hit the object rule error conditions.

Maniphest Tasks: T13480

Differential Revision: https://secure.phabricator.com/D20956
This commit is contained in:
epriestley 2020-01-29 11:33:31 -08:00
parent 4904d7711e
commit 6d4c6924d6
5 changed files with 315 additions and 246 deletions

View file

@ -9,7 +9,7 @@ return array(
'names' => array( 'names' => array(
'conpherence.pkg.css' => '3c8a0668', 'conpherence.pkg.css' => '3c8a0668',
'conpherence.pkg.js' => '020aebcf', 'conpherence.pkg.js' => '020aebcf',
'core.pkg.css' => '6d9a0ba6', 'core.pkg.css' => '5edb4679',
'core.pkg.js' => '705aec2c', 'core.pkg.js' => '705aec2c',
'differential.pkg.css' => '607c84be', 'differential.pkg.css' => '607c84be',
'differential.pkg.js' => '1b97518d', 'differential.pkg.js' => '1b97518d',
@ -165,7 +165,7 @@ return array(
'rsrc/css/phui/phui-left-right.css' => '68513c34', 'rsrc/css/phui/phui-left-right.css' => '68513c34',
'rsrc/css/phui/phui-lightbox.css' => '4ebf22da', 'rsrc/css/phui/phui-lightbox.css' => '4ebf22da',
'rsrc/css/phui/phui-list.css' => 'b05144dd', 'rsrc/css/phui/phui-list.css' => 'b05144dd',
'rsrc/css/phui/phui-object-box.css' => 'f434b6be', 'rsrc/css/phui/phui-object-box.css' => 'b8d7eea0',
'rsrc/css/phui/phui-pager.css' => 'd022c7ad', 'rsrc/css/phui/phui-pager.css' => 'd022c7ad',
'rsrc/css/phui/phui-pinboard-view.css' => '1f08f5d8', 'rsrc/css/phui/phui-pinboard-view.css' => '1f08f5d8',
'rsrc/css/phui/phui-policy-section-view.css' => '139fdc64', 'rsrc/css/phui/phui-policy-section-view.css' => '139fdc64',
@ -855,7 +855,7 @@ return array(
'phui-left-right-css' => '68513c34', 'phui-left-right-css' => '68513c34',
'phui-lightbox-css' => '4ebf22da', 'phui-lightbox-css' => '4ebf22da',
'phui-list-view-css' => 'b05144dd', 'phui-list-view-css' => 'b05144dd',
'phui-object-box-css' => 'f434b6be', 'phui-object-box-css' => 'b8d7eea0',
'phui-oi-big-ui-css' => 'fa74cc35', 'phui-oi-big-ui-css' => 'fa74cc35',
'phui-oi-color-css' => 'b517bfa0', 'phui-oi-color-css' => 'b517bfa0',
'phui-oi-drag-ui-css' => 'da15d3dc', 'phui-oi-drag-ui-css' => 'da15d3dc',

View file

@ -243,6 +243,12 @@ abstract class HeraldAdapter extends Phobject {
abstract public function getAdapterApplicationClass(); abstract public function getAdapterApplicationClass();
abstract public function getObject(); abstract public function getObject();
public function getAdapterContentIcon() {
$application_class = $this->getAdapterApplicationClass();
$application = newv($application_class, array());
return $application->getIcon();
}
/** /**
* Return a new characteristic object for this adapter. * Return a new characteristic object for this adapter.
* *

View file

@ -3,314 +3,351 @@
final class HeraldNewController extends HeraldController { final class HeraldNewController extends HeraldController {
public function handleRequest(AphrontRequest $request) { public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer(); $viewer = $this->getViewer();
$content_type_map = HeraldAdapter::getEnabledAdapterMap($viewer); $adapter_type_map = HeraldAdapter::getEnabledAdapterMap($viewer);
$rule_type_map = HeraldRuleTypeConfig::getRuleTypeMap(); $adapter_type = $request->getStr('adapter');
$errors = array(); if (!isset($adapter_type_map[$adapter_type])) {
$title = pht('Create Herald Rule');
$content = $this->newAdapterMenu($title);
} else {
$adapter = HeraldAdapter::getAdapterForContentType($adapter_type);
$e_type = null; $rule_type_map = HeraldRuleTypeConfig::getRuleTypeMap();
$e_rule = null; $rule_type = $request->getStr('type');
$e_object = null;
$step = $request->getInt('step'); if (!isset($rule_type_map[$rule_type])) {
if ($request->isFormPost()) { $title = pht(
$content_type = $request->getStr('content_type'); 'Create Herald Rule: %s',
if (empty($content_type_map[$content_type])) { $adapter->getAdapterContentName());
$errors[] = pht('You must choose a content type for this rule.');
$e_type = pht('Required');
$step = 0;
}
if (!$errors && $step > 1) { $content = $this->newTypeMenu($adapter, $title);
$rule_type = $request->getStr('rule_type'); } else {
if (empty($rule_type_map[$rule_type])) { if ($rule_type !== HeraldRuleTypeConfig::RULE_TYPE_OBJECT) {
$errors[] = pht('You must choose a rule type for this rule.'); $target_phid = null;
$e_rule = pht('Required'); $target_okay = true;
$step = 1; } else {
} $object_name = $request->getStr('objectName');
} $target_okay = false;
if (!$errors && $step >= 2) { $errors = array();
$target_phid = null; $e_object = null;
$object_name = $request->getStr('objectName');
$done = false; if ($request->isFormPost()) {
if ($rule_type != HeraldRuleTypeConfig::RULE_TYPE_OBJECT) { if (strlen($object_name)) {
$done = true; $target_object = id(new PhabricatorObjectQuery())
} else if (strlen($object_name)) { ->setViewer($viewer)
$target_object = id(new PhabricatorObjectQuery()) ->withNames(array($object_name))
->setViewer($viewer) ->executeOne();
->withNames(array($object_name)) if ($target_object) {
->executeOne(); $can_edit = PhabricatorPolicyFilter::hasCapability(
if ($target_object) { $viewer,
$can_edit = PhabricatorPolicyFilter::hasCapability( $target_object,
$viewer, PhabricatorPolicyCapability::CAN_EDIT);
$target_object, if (!$can_edit) {
PhabricatorPolicyCapability::CAN_EDIT); $errors[] = pht(
if (!$can_edit) { 'You can not create a rule for that object, because you '.
$errors[] = pht( 'do not have permission to edit it. You can only create '.
'You can not create a rule for that object, because you do '. 'rules for objects you can edit.');
'not have permission to edit it. You can only create rules '. $e_object = pht('Not Editable');
'for objects you can edit.'); } else {
$e_object = pht('Not Editable'); if (!$adapter->canTriggerOnObject($target_object)) {
$step = 2; $errors[] = pht(
} else { 'This object is not of an allowed type for the rule. '.
$adapter = HeraldAdapter::getAdapterForContentType($content_type); 'Rules can only trigger on certain objects.');
if (!$adapter->canTriggerOnObject($target_object)) { $e_object = pht('Invalid');
$errors[] = pht( } else {
'This object is not of an allowed type for the rule. '. $target_phid = $target_object->getPHID();
'Rules can only trigger on certain objects.'); }
$e_object = pht('Invalid'); }
$step = 2;
} else { } else {
$target_phid = $target_object->getPHID(); $errors[] = pht('No object exists by that name.');
$done = true; $e_object = pht('Invalid');
} }
} else {
$errors[] = pht(
'You must choose an object to associate this rule with.');
$e_object = pht('Required');
} }
} else {
$errors[] = pht('No object exists by that name.'); $target_okay = !$errors;
$e_object = pht('Invalid');
$step = 2;
} }
} else if ($step > 2) {
$errors[] = pht(
'You must choose an object to associate this rule with.');
$e_object = pht('Required');
$step = 2;
} }
if (!$errors && $done) { if (!$target_okay) {
$title = pht('Choose Object');
$content = $this->newTargetForm(
$adapter,
$rule_type,
$object_name,
$errors,
$e_object,
$title);
} else {
$params = array( $params = array(
'content_type' => $content_type, 'content_type' => $adapter_type,
'rule_type' => $rule_type, 'rule_type' => $rule_type,
'targetPHID' => $target_phid, 'targetPHID' => $target_phid,
); );
$uri = new PhutilURI('edit/', $params); $edit_uri = $this->getApplicationURI('edit/');
$uri = $this->getApplicationURI($uri); $edit_uri = new PhutilURI($edit_uri, $params);
return id(new AphrontRedirectResponse())->setURI($uri);
return id(new AphrontRedirectResponse())
->setURI($edit_uri);
} }
} }
} }
$content_type = $request->getStr('content_type');
$rule_type = $request->getStr('rule_type');
$form = id(new AphrontFormView())
->setUser($viewer)
->setAction($this->getApplicationURI('new/'));
switch ($step) {
case 0:
default:
$content_types = $this->renderContentTypeControl(
$content_type_map,
$e_type);
$form
->addHiddenInput('step', 1)
->appendChild($content_types);
$cancel_text = null;
$cancel_uri = $this->getApplicationURI();
$title = pht('Create Herald Rule');
break;
case 1:
$rule_types = $this->renderRuleTypeControl(
$rule_type_map,
$e_rule);
$form
->addHiddenInput('content_type', $content_type)
->addHiddenInput('step', 2)
->appendChild($rule_types);
$params = array(
'content_type' => $content_type,
'step' => '0',
);
$cancel_text = pht('Back');
$cancel_uri = new PhutilURI('new/', $params);
$cancel_uri = $this->getApplicationURI($cancel_uri);
$title = pht('Create Herald Rule: %s',
idx($content_type_map, $content_type));
break;
case 2:
$adapter = HeraldAdapter::getAdapterForContentType($content_type);
$form
->addHiddenInput('content_type', $content_type)
->addHiddenInput('rule_type', $rule_type)
->addHiddenInput('step', 3)
->appendChild(
id(new AphrontFormStaticControl())
->setLabel(pht('Rule for'))
->setValue(
phutil_tag(
'strong',
array(),
idx($content_type_map, $content_type))))
->appendChild(
id(new AphrontFormStaticControl())
->setLabel(pht('Rule Type'))
->setValue(
phutil_tag(
'strong',
array(),
idx($rule_type_map, $rule_type))))
->appendRemarkupInstructions(
pht(
'Choose the object this rule will act on (for example, enter '.
'`rX` to act on the `rX` repository, or `#project` to act on '.
'a project).'))
->appendRemarkupInstructions(
$adapter->explainValidTriggerObjects())
->appendChild(
id(new AphrontFormTextControl())
->setName('objectName')
->setError($e_object)
->setValue($request->getStr('objectName'))
->setLabel(pht('Object')));
$params = array(
'content_type' => $content_type,
'rule_type' => $rule_type,
'step' => 1,
);
$cancel_text = pht('Back');
$cancel_uri = new PhutilURI('new/', $params);
$cancel_uri = $this->getApplicationURI($cancel_uri);
$title = pht('Create Herald Rule: %s',
idx($content_type_map, $content_type));
break;
}
$form
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Continue'))
->addCancelButton($cancel_uri, $cancel_text));
$form_box = id(new PHUIObjectBoxView())
->setHeaderText($title)
->setFormErrors($errors)
->setBackground(PHUIObjectBoxView::WHITE_CONFIG)
->setForm($form);
$crumbs = $this $crumbs = $this
->buildApplicationCrumbs() ->buildApplicationCrumbs()
->addTextCrumb(pht('Create Rule')) ->addTextCrumb(pht('Create Rule'))
->setBorder(true); ->setBorder(true);
$view = id(new PHUITwoColumnView()) $view = id(new PHUITwoColumnView())
->setFooter($form_box); ->setFooter($content);
return $this->newPage() return $this->newPage()
->setTitle($title) ->setTitle($title)
->setCrumbs($crumbs) ->setCrumbs($crumbs)
->appendChild( ->appendChild($view);
array(
$view,
));
} }
private function renderContentTypeControl(array $content_type_map, $e_type) { private function newAdapterMenu($title) {
$request = $this->getRequest(); $viewer = $this->getViewer();
$radio = id(new AphrontFormRadioButtonControl()) $types = HeraldAdapter::getEnabledAdapterMap($viewer);
->setLabel(pht('New Rule for'))
->setName('content_type')
->setValue($request->getStr('content_type'))
->setError($e_type);
foreach ($content_type_map as $value => $name) { foreach ($types as $key => $type) {
$adapter = HeraldAdapter::getAdapterForContentType($value); $types[$key] = HeraldAdapter::getAdapterForContentType($key);
$radio->addButton(
$value,
$name,
phutil_escape_html_newlines($adapter->getAdapterContentDescription()));
} }
return $radio; $types = msort($types, 'getAdapterContentName');
$base_uri = $this->getApplicationURI('create/');
$menu = id(new PHUIObjectItemListView())
->setViewer($viewer)
->setBig(true);
foreach ($types as $key => $adapter) {
$adapter_uri = id(new PhutilURI($base_uri))
->replaceQueryParam('adapter', $key);
$description = $adapter->getAdapterContentDescription();
$description = phutil_escape_html_newlines($description);
$item = id(new PHUIObjectItemView())
->setHeader($adapter->getAdapterContentName())
->setImageIcon($adapter->getAdapterContentIcon())
->addAttribute($description)
->setHref($adapter_uri)
->setClickable(true);
$menu->addItem($item);
}
$box = id(new PHUIObjectBoxView())
->setHeaderText($title)
->setBackground(PHUIObjectBoxView::WHITE_CONFIG)
->setObjectList($menu);
return id(new PHUILauncherView())
->appendChild($box);
} }
private function newTypeMenu(HeraldAdapter $adapter, $title) {
$viewer = $this->getViewer();
private function renderRuleTypeControl(array $rule_type_map, $e_rule) { $global_capability = HeraldManageGlobalRulesCapability::CAPABILITY;
$request = $this->getRequest(); $can_global = $this->hasApplicationCapability($global_capability);
// Reorder array to put less powerful rules first. if ($can_global) {
$rule_type_map = array_select_keys( $global_note = pht(
$rule_type_map, 'You have permission to create and manage global rules.');
array( } else {
HeraldRuleTypeConfig::RULE_TYPE_PERSONAL, $global_note = pht(
HeraldRuleTypeConfig::RULE_TYPE_OBJECT, 'You do not have permission to create or manage global rules.');
HeraldRuleTypeConfig::RULE_TYPE_GLOBAL, }
)) + $rule_type_map; $global_note = phutil_tag('em', array(), $global_note);
list($can_global, $global_link) = $this->explainApplicationCapability( $specs = array(
HeraldManageGlobalRulesCapability::CAPABILITY, HeraldRuleTypeConfig::RULE_TYPE_PERSONAL => array(
pht('You have permission to create and manage global rules.'), 'name' => pht('Personal Rule'),
pht('You do not have permission to create or manage global rules.')); 'icon' => 'fa-user',
'help' => pht(
$captions = array(
HeraldRuleTypeConfig::RULE_TYPE_PERSONAL =>
pht(
'Personal rules notify you about events. You own them, but they can '. 'Personal rules notify you about events. You own them, but they can '.
'only affect you. Personal rules only trigger for objects you have '. 'only affect you. Personal rules only trigger for objects you have '.
'permission to see.'), 'permission to see.'),
HeraldRuleTypeConfig::RULE_TYPE_OBJECT => 'enabled' => true,
pht( ),
HeraldRuleTypeConfig::RULE_TYPE_OBJECT => array(
'name' => pht('Object Rule'),
'icon' => 'fa-cube',
'help' => pht(
'Object rules notify anyone about events. They are bound to an '. 'Object rules notify anyone about events. They are bound to an '.
'object (like a repository) and can only act on that object. You '. 'object (like a repository) and can only act on that object. You '.
'must be able to edit an object to create object rules for it. '. 'must be able to edit an object to create object rules for it. '.
'Other users who can edit the object can edit its rules.'), 'Other users who can edit the object can edit its rules.'),
HeraldRuleTypeConfig::RULE_TYPE_GLOBAL => 'enabled' => true,
array( ),
HeraldRuleTypeConfig::RULE_TYPE_GLOBAL => array(
'name' => pht('Global Rule'),
'icon' => 'fa-globe',
'help' => array(
pht( pht(
'Global rules notify anyone about events. Global rules can '. 'Global rules notify anyone about events. Global rules can '.
'bypass access control policies and act on any object.'), 'bypass access control policies and act on any object.'),
$global_link, $global_note,
), ),
'enabled' => $can_global,
),
); );
$radio = id(new AphrontFormRadioButtonControl()) $adapter_type = $adapter->getAdapterContentType();
->setLabel(pht('Rule Type'))
->setName('rule_type')
->setValue($request->getStr('rule_type'))
->setError($e_rule);
$adapter = HeraldAdapter::getAdapterForContentType( $base_uri = new PhutilURI($this->getApplicationURI('create/'));
$request->getStr('content_type'));
foreach ($rule_type_map as $value => $name) { $adapter_uri = id(clone $base_uri)
$caption = idx($captions, $value); ->replaceQueryParam('adapter', $adapter_type);
$disabled = ($value == HeraldRuleTypeConfig::RULE_TYPE_GLOBAL) &&
(!$can_global);
if (!$adapter->supportsRuleType($value)) { $menu = id(new PHUIObjectItemListView())
$disabled = true; ->setUser($viewer)
$caption = array( ->setBig(true);
$caption,
"\n\n", foreach ($specs as $rule_type => $spec) {
phutil_tag( $type_uri = id(clone $adapter_uri)
->replaceQueryParam('type', $rule_type);
$name = $spec['name'];
$icon = $spec['icon'];
$description = $spec['help'];
$description = (array)$description;
$enabled = $spec['enabled'];
if ($enabled) {
$enabled = $adapter->supportsRuleType($rule_type);
if (!$enabled) {
$description[] = phutil_tag(
'em', 'em',
array(), array(),
pht( pht(
'This rule type is not supported by the selected content type.')), 'This rule type is not supported by the selected '.
); 'content type.'));
}
} }
$radio->addButton( $description = phutil_implode_html(
$value, array(
$name, phutil_tag('br'),
phutil_escape_html_newlines($caption), phutil_tag('br'),
$disabled ? 'disabled' : null, ),
$disabled); $description);
$item = id(new PHUIObjectItemView())
->setHeader($name)
->setImageIcon($icon)
->addAttribute($description);
if ($enabled) {
$item
->setHref($type_uri)
->setClickable(true);
} else {
$item->setDisabled(true);
}
$menu->addItem($item);
} }
return $radio; $box = id(new PHUIObjectBoxView())
->setHeaderText($title)
->setBackground(PHUIObjectBoxView::WHITE_CONFIG)
->setObjectList($menu);
$box->newTailButton()
->setText(pht('Back to Content Types'))
->setIcon('fa-chevron-left')
->setHref($base_uri);
return id(new PHUILauncherView())
->appendChild($box);
}
private function newTargetForm(
HeraldAdapter $adapter,
$rule_type,
$object_name,
$errors,
$e_object,
$title) {
$viewer = $this->getViewer();
$content_type = $adapter->getAdapterContentType();
$rule_type_map = HeraldRuleTypeConfig::getRuleTypeMap();
$params = array(
'adapter' => $content_type,
'type' => $rule_type,
);
$form = id(new AphrontFormView())
->setViewer($viewer)
->appendChild(
id(new AphrontFormStaticControl())
->setLabel(pht('Rule for'))
->setValue(
phutil_tag(
'strong',
array(),
$adapter->getAdapterContentName())))
->appendChild(
id(new AphrontFormStaticControl())
->setLabel(pht('Rule Type'))
->setValue(
phutil_tag(
'strong',
array(),
idx($rule_type_map, $rule_type))))
->appendRemarkupInstructions(
pht(
'Choose the object this rule will act on (for example, enter '.
'`rX` to act on the `rX` repository, or `#project` to act on '.
'a project).'))
->appendRemarkupInstructions(
$adapter->explainValidTriggerObjects())
->appendChild(
id(new AphrontFormTextControl())
->setName('objectName')
->setError($e_object)
->setValue($object_name)
->setLabel(pht('Object')));
foreach ($params as $key => $value) {
$form->addHiddenInput($key, $value);
}
$cancel_params = $params;
unset($cancel_params['type']);
$cancel_uri = $this->getApplicationURI('new/');
$cancel_uri = new PhutilURI($cancel_uri, $params);
$form->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Continue'))
->addCancelButton($cancel_uri, pht('Back')));
$form_box = id(new PHUIObjectBoxView())
->setHeaderText($title)
->setFormErrors($errors)
->setBackground(PHUIObjectBoxView::WHITE_CONFIG)
->setForm($form);
return $form_box;
} }
} }

View file

@ -27,6 +27,7 @@ final class PHUIObjectBoxView extends AphrontTagView {
private $showHideOpen; private $showHideOpen;
private $propertyLists = array(); private $propertyLists = array();
private $tailButtons = array();
const COLOR_RED = 'red'; const COLOR_RED = 'red';
const COLOR_BLUE = 'blue'; const COLOR_BLUE = 'blue';
@ -153,6 +154,16 @@ final class PHUIObjectBoxView extends AphrontTagView {
return $this; return $this;
} }
public function newTailButton() {
$button = id(new PHUIButtonView())
->setTag('a')
->setColor(PHUIButtonView::GREY);
$this->tailButtons[] = $button;
return $button;
}
protected function getTagAttributes() { protected function getTagAttributes() {
$classes = array(); $classes = array();
$classes[] = 'phui-box'; $classes[] = 'phui-box';
@ -329,6 +340,15 @@ final class PHUIObjectBoxView extends AphrontTagView {
$content[] = $this->objectList; $content[] = $this->objectList;
} }
if ($this->tailButtons) {
$content[] = phutil_tag(
'div',
array(
'class' => 'phui-object-box-tail-buttons',
),
$this->tailButtons);
}
return $content; return $content;
} }
} }

View file

@ -62,6 +62,12 @@ div.phui-object-box.phui-object-box-flush {
font-size: {$normalfontsize}; font-size: {$normalfontsize};
} }
.phui-object-box-tail-buttons {
padding: 8px;
background: {$lightgreybackground};
border-top: 1px solid {$lightgreyborder};
}
/* - Object Box Colors ------------------------------------------------------ */ /* - Object Box Colors ------------------------------------------------------ */
.phui-box-border.phui-object-box-green { .phui-box-border.phui-object-box-green {