@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.

Herald - tighten up rule display

Summary: we were bad at displaying phid-based values nicely. Now we are good at it.

Test Plan: made a herald rule where if the author was a or b, the task should be assigned to c and have projects x, y, z added to it. this displayed nicely.

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, aran

Differential Revision: https://secure.phabricator.com/D7158

+86 -21
+84 -19
src/applications/herald/adapter/HeraldAdapter.php
··· 710 710 } 711 711 712 712 713 - public function renderRuleAsText(HeraldRule $rule) { 713 + public function renderRuleAsText(HeraldRule $rule, array $handles) { 714 + assert_instances_of($handles, 'PhabricatorObjectHandle'); 715 + 714 716 $out = array(); 715 717 716 718 if ($rule->getMustMatchAll()) { ··· 721 723 722 724 $out[] = null; 723 725 foreach ($rule->getConditions() as $condition) { 724 - $out[] = " ".$this->renderConditionAsText($condition); 726 + $out[] = $this->renderConditionAsText($condition, $handles); 725 727 } 726 728 $out[] = null; 727 729 ··· 733 735 734 736 $out[] = null; 735 737 foreach ($rule->getActions() as $action) { 736 - $out[] = " ".$this->renderActionAsText($action); 738 + $out[] = $this->renderActionAsText($action, $handles); 737 739 } 738 740 739 - return implode("\n", $out); 741 + return phutil_implode_html("\n", $out); 740 742 } 741 743 742 - private function renderConditionAsText(HeraldCondition $condition) { 744 + private function renderConditionAsText( 745 + HeraldCondition $condition, 746 + array $handles) { 743 747 $field_type = $condition->getFieldName(); 744 748 $field_name = idx($this->getFieldNameMap(), $field_type); 745 749 746 750 $condition_type = $condition->getFieldCondition(); 747 751 $condition_name = idx($this->getConditionNameMap(), $condition_type); 748 752 749 - $value = $this->renderConditionValueAsText($condition); 753 + $value = $this->renderConditionValueAsText($condition, $handles); 750 754 751 - return "{$field_name} {$condition_name} {$value}"; 755 + return hsprintf(' %s %s %s', $field_name, $condition_name, $value); 752 756 } 753 757 754 - private function renderActionAsText(HeraldAction $action) { 758 + private function renderActionAsText( 759 + HeraldAction $action, 760 + array $handles) { 755 761 $rule_global = HeraldRuleTypeConfig::RULE_TYPE_GLOBAL; 756 762 757 763 $action_type = $action->getAction(); 758 764 $action_name = idx($this->getActionNameMap($rule_global), $action_type); 759 765 760 - $target = $this->renderActionTargetAsText($action); 766 + $target = $this->renderActionTargetAsText($action, $handles); 761 767 762 - return "{$action_name} {$target}"; 768 + return hsprintf(' %s %s', $action_name, $target); 763 769 } 764 770 765 - private function renderConditionValueAsText(HeraldCondition $condition) { 766 - // TODO: This produces sketchy results for many conditions. 771 + private function renderConditionValueAsText( 772 + HeraldCondition $condition, 773 + array $handles) { 774 + 767 775 $value = $condition->getValue(); 768 - if (is_array($value)) { 769 - $value = implode(', ', $value); 776 + if (!is_array($value)) { 777 + $value = array($value); 770 778 } 779 + foreach ($value as $index => $val) { 780 + $handle = idx($handles, $val); 781 + if ($handle) { 782 + $value[$index] = $handle->renderLink(); 783 + } 784 + } 785 + $value = phutil_implode_html(', ', $value); 771 786 return $value; 772 787 } 773 788 774 - private function renderActionTargetAsText(HeraldAction $action) { 775 - // TODO: This produces sketchy results for Flags and PHIDs. 789 + private function renderActionTargetAsText( 790 + HeraldAction $action, 791 + array $handles) { 792 + 776 793 $target = $action->getTarget(); 777 - if (is_array($target)) { 778 - $target = implode(', ', $target); 794 + if (!is_array($target)) { 795 + $target = array($target); 796 + } 797 + foreach ($target as $index => $val) { 798 + $handle = idx($handles, $val); 799 + if ($handle) { 800 + $target[$index] = $handle->renderLink(); 801 + } 802 + } 803 + $target = phutil_implode_html(', ', $target); 804 + return $target; 805 + } 806 + 807 + /** 808 + * Given a @{class:HeraldRule}, this function extracts all the phids that 809 + * we'll want to load as handles later. 810 + * 811 + * This function performs a somewhat hacky approach to figuring out what 812 + * is and is not a phid - try to get the phid type and if the type is 813 + * *not* unknown assume its a valid phid. 814 + * 815 + * Don't try this at home. Use more strongly typed data at home. 816 + * 817 + * Think of the children. 818 + */ 819 + public static function getHandlePHIDs(HeraldRule $rule) { 820 + $phids = array($rule->getAuthorPHID()); 821 + foreach ($rule->getConditions() as $condition) { 822 + $value = $condition->getValue(); 823 + if (!is_array($value)) { 824 + $value = array($value); 825 + } 826 + foreach ($value as $val) { 827 + if (phid_get_type($val) != 828 + PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN) { 829 + $phids[] = $val; 830 + } 831 + } 779 832 } 780 833 781 - return $target; 834 + foreach ($rule->getActions() as $action) { 835 + $target = $action->getTarget(); 836 + if (!is_array($target)) { 837 + $target = array($target); 838 + } 839 + foreach ($target as $val) { 840 + if (phid_get_type($val) != 841 + PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN) { 842 + $phids[] = $val; 843 + } 844 + } 845 + } 846 + return $phids; 782 847 } 783 848 784 849 }
+2 -2
src/applications/herald/controller/HeraldRuleViewController.php
··· 73 73 private function buildPropertyView(HeraldRule $rule) { 74 74 $viewer = $this->getRequest()->getUser(); 75 75 76 - $this->loadHandles(array($rule->getAuthorPHID())); 76 + $this->loadHandles(HeraldAdapter::getHandlePHIDs($rule)); 77 77 78 78 $view = id(new PhabricatorPropertyListView()) 79 79 ->setUser($viewer) ··· 104 104 array( 105 105 'style' => 'white-space: pre-wrap;', 106 106 ), 107 - $adapter->renderRuleAsText($rule))); 107 + $adapter->renderRuleAsText($rule, $this->getLoadedHandles()))); 108 108 } 109 109 110 110 return $view;