mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 05:12:41 +01:00
Show fewer useless transactions when creating objects, especially with EditEngine forms
Summary: Fixes T7661. Ref T9527. When you create a task, especially with an EditEngine form, you currently get more noise than is useful. For example: > alice created this task. > alice changed the edit policy from "All Users" to "Community (Project)". > alice added projects: Feature Request, Differential. > alice added a subscriber: alice. Transaction (1) is a little useful, since it saves us from a weird empty state and shows the object creation time. Transaction (2) is totally useless (and even misleading) because that's the default policy for the form. Transaction (3) isn't //completely// useless but isn't very interesting, and probably not worth the real-estate. Transaction (4) is totally useless. (These transactions are uniquely useless when creating objects -- when editing them later, they're fine.) This adds two new rules to hide transactions: - Hide transactions from object creation if the old value is empty (e.g., set title, set projects, set subscribers). - Hide transactions from object creation if the old value is the same as the form default value (e.g., set policy to default, set priorities to default, set status to default). NOTE: These rules also hide the "created this object" transaction, since it's really one of those transaction types in all cases. I want to keep that around in the long term, but just have it be a separate `TYPE_CREATE` action -- currently, it is this weird, inconsistent action where we pick some required field (like title) and special-case the rendering if the old value is `null`. So fixing that is a bit more involved. For now, I'm just dropping these transactions completely, but intend to restore them later. Test Plan: - Created objects. - Usually saw no extra create transactions. - Saw extra create transactions when making an important change away from form defaults (e.g., overriding form policy). Reviewers: chad Reviewed By: chad Maniphest Tasks: T7661, T9527 Differential Revision: https://secure.phabricator.com/D14810
This commit is contained in:
parent
8a0dfa94d4
commit
6146aefcd4
4 changed files with 75 additions and 6 deletions
|
@ -836,7 +836,17 @@ abstract class PhabricatorEditEngine
|
|||
unset($submit_fields[$key]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Before we read the submitted values, store a copy of what we would
|
||||
// use if the form was empty so we can figure out which transactions are
|
||||
// just setting things to their default values for the current form.
|
||||
$defaults = array();
|
||||
foreach ($submit_fields as $key => $field) {
|
||||
$defaults[$key] = $field->getValueForTransaction();
|
||||
}
|
||||
|
||||
foreach ($submit_fields as $key => $field) {
|
||||
$field->setIsSubmittedForm(true);
|
||||
|
||||
if (!$field->shouldReadValueFromSubmit()) {
|
||||
|
@ -847,14 +857,22 @@ abstract class PhabricatorEditEngine
|
|||
}
|
||||
|
||||
$xactions = array();
|
||||
foreach ($submit_fields as $field) {
|
||||
foreach ($submit_fields as $key => $field) {
|
||||
$field_value = $field->getValueForTransaction();
|
||||
|
||||
$type_xactions = $field->generateTransactions(
|
||||
clone $template,
|
||||
array(
|
||||
'value' => $field->getValueForTransaction(),
|
||||
'value' => $field_value,
|
||||
));
|
||||
|
||||
foreach ($type_xactions as $type_xaction) {
|
||||
$default = $defaults[$key];
|
||||
|
||||
if ($default === $field->getValueForTransaction()) {
|
||||
$type_xaction->setIsDefaultTransaction(true);
|
||||
}
|
||||
|
||||
$xactions[] = $type_xaction;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -755,8 +755,4 @@ abstract class PhabricatorEditField extends Phobject {
|
|||
return $edit_type->generateTransactions($template, $spec);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -823,6 +823,12 @@ abstract class PhabricatorApplicationTransactionEditor
|
|||
throw $ex;
|
||||
}
|
||||
|
||||
foreach ($xactions as $xaction) {
|
||||
if ($this->getIsNewObject()) {
|
||||
$xaction->setIsCreateTransaction(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Now that we've merged, filtered, and combined transactions, check for
|
||||
// required capabilities.
|
||||
foreach ($xactions as $xaction) {
|
||||
|
|
|
@ -142,6 +142,22 @@ abstract class PhabricatorApplicationTransaction
|
|||
return $this->comment;
|
||||
}
|
||||
|
||||
public function setIsCreateTransaction($create) {
|
||||
return $this->setMetadataValue('core.create', $create);
|
||||
}
|
||||
|
||||
public function getIsCreateTransaction() {
|
||||
return (bool)$this->getMetadataValue('core.create', false);
|
||||
}
|
||||
|
||||
public function setIsDefaultTransaction($default) {
|
||||
return $this->setMetadataValue('core.default', $default);
|
||||
}
|
||||
|
||||
public function getIsDefaultTransaction() {
|
||||
return (bool)$this->getMetadataValue('core.default', false);
|
||||
}
|
||||
|
||||
public function attachComment(
|
||||
PhabricatorApplicationTransactionComment $comment) {
|
||||
$this->comment = $comment;
|
||||
|
@ -456,6 +472,39 @@ abstract class PhabricatorApplicationTransaction
|
|||
}
|
||||
|
||||
public function shouldHide() {
|
||||
// Never hide comments.
|
||||
if ($this->hasComment()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Hide creation transactions if the old value is empty. These are
|
||||
// transactions like "alice set the task tile to: ...", which are
|
||||
// essentially never interesting.
|
||||
if ($this->getIsCreateTransaction()) {
|
||||
$old = $this->getOldValue();
|
||||
|
||||
if (is_array($old) && !$old) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!strlen($old)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Hide creation transactions setting values to defaults, even if
|
||||
// the old value is not empty. For example, tasks may have a global
|
||||
// default view policy of "All Users", but a particular form sets the
|
||||
// policy to "Administrators". The transaction corresponding to this
|
||||
// change is not interesting, since it is the default behavior of the
|
||||
// form.
|
||||
|
||||
if ($this->getIsCreateTransaction()) {
|
||||
if ($this->getIsDefaultTransaction()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
switch ($this->getTransactionType()) {
|
||||
case PhabricatorTransactions::TYPE_VIEW_POLICY:
|
||||
case PhabricatorTransactions::TYPE_EDIT_POLICY:
|
||||
|
|
Loading…
Reference in a new issue