@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+75 -6
+20 -2
src/applications/transactions/editengine/PhabricatorEditEngine.php
··· 836 836 unset($submit_fields[$key]); 837 837 continue; 838 838 } 839 + } 839 840 841 + // Before we read the submitted values, store a copy of what we would 842 + // use if the form was empty so we can figure out which transactions are 843 + // just setting things to their default values for the current form. 844 + $defaults = array(); 845 + foreach ($submit_fields as $key => $field) { 846 + $defaults[$key] = $field->getValueForTransaction(); 847 + } 848 + 849 + foreach ($submit_fields as $key => $field) { 840 850 $field->setIsSubmittedForm(true); 841 851 842 852 if (!$field->shouldReadValueFromSubmit()) { ··· 847 857 } 848 858 849 859 $xactions = array(); 850 - foreach ($submit_fields as $field) { 860 + foreach ($submit_fields as $key => $field) { 861 + $field_value = $field->getValueForTransaction(); 862 + 851 863 $type_xactions = $field->generateTransactions( 852 864 clone $template, 853 865 array( 854 - 'value' => $field->getValueForTransaction(), 866 + 'value' => $field_value, 855 867 )); 856 868 857 869 foreach ($type_xactions as $type_xaction) { 870 + $default = $defaults[$key]; 871 + 872 + if ($default === $field->getValueForTransaction()) { 873 + $type_xaction->setIsDefaultTransaction(true); 874 + } 875 + 858 876 $xactions[] = $type_xaction; 859 877 } 860 878 }
-4
src/applications/transactions/editfield/PhabricatorEditField.php
··· 755 755 return $edit_type->generateTransactions($template, $spec); 756 756 } 757 757 758 - 759 - 760 - 761 - 762 758 }
+6
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 823 823 throw $ex; 824 824 } 825 825 826 + foreach ($xactions as $xaction) { 827 + if ($this->getIsNewObject()) { 828 + $xaction->setIsCreateTransaction(true); 829 + } 830 + } 831 + 826 832 // Now that we've merged, filtered, and combined transactions, check for 827 833 // required capabilities. 828 834 foreach ($xactions as $xaction) {
+49
src/applications/transactions/storage/PhabricatorApplicationTransaction.php
··· 142 142 return $this->comment; 143 143 } 144 144 145 + public function setIsCreateTransaction($create) { 146 + return $this->setMetadataValue('core.create', $create); 147 + } 148 + 149 + public function getIsCreateTransaction() { 150 + return (bool)$this->getMetadataValue('core.create', false); 151 + } 152 + 153 + public function setIsDefaultTransaction($default) { 154 + return $this->setMetadataValue('core.default', $default); 155 + } 156 + 157 + public function getIsDefaultTransaction() { 158 + return (bool)$this->getMetadataValue('core.default', false); 159 + } 160 + 145 161 public function attachComment( 146 162 PhabricatorApplicationTransactionComment $comment) { 147 163 $this->comment = $comment; ··· 456 472 } 457 473 458 474 public function shouldHide() { 475 + // Never hide comments. 476 + if ($this->hasComment()) { 477 + return false; 478 + } 479 + 480 + // Hide creation transactions if the old value is empty. These are 481 + // transactions like "alice set the task tile to: ...", which are 482 + // essentially never interesting. 483 + if ($this->getIsCreateTransaction()) { 484 + $old = $this->getOldValue(); 485 + 486 + if (is_array($old) && !$old) { 487 + return true; 488 + } 489 + 490 + if (!strlen($old)) { 491 + return true; 492 + } 493 + } 494 + 495 + // Hide creation transactions setting values to defaults, even if 496 + // the old value is not empty. For example, tasks may have a global 497 + // default view policy of "All Users", but a particular form sets the 498 + // policy to "Administrators". The transaction corresponding to this 499 + // change is not interesting, since it is the default behavior of the 500 + // form. 501 + 502 + if ($this->getIsCreateTransaction()) { 503 + if ($this->getIsDefaultTransaction()) { 504 + return true; 505 + } 506 + } 507 + 459 508 switch ($this->getTransactionType()) { 460 509 case PhabricatorTransactions::TYPE_VIEW_POLICY: 461 510 case PhabricatorTransactions::TYPE_EDIT_POLICY: