Javascript to update the target group of a review

14 views
Skip to first unread message

michae...@ymail.com

unread,
Jun 10, 2020, 11:30:46 AM6/10/20
to Review Board Development
Hello,

I am working on an extension and have hit a roadblock.

The goal of the extension is to add a 'Pending' button the the Review menu (along side Close, Ship It!, etc). When the 'Pending' button is pressed the target group will change, essentially moving the review into another group, where a select few people can see it.

I have the 'Pending' button showing, with

with override_feature_check(ClassBasedActionsFeature.feature_id, enabled=True):
   BaseReviewRequestActionHook(self, actions=[
     MoveMenuAction([
       PendingAction(),
       DeferredAction(),
     ]),
   ])

PendingAction is

class PendingAction(BaseReviewRequestAction):
   action_id = 'pending-review-request-action'
   label = 'Pending'

I am now working on the Javascript to trigger the target group change.

So far, all I can do, is trigger a popup but the Pending button is pressed.

BWEnhancementsExtension = {};

(function() {
   BWEnhancementsExtension.Extension = RB.Extension.extend({
     initialize: function () {

       var _onMovePendingClicked;

       _super(this).initialize.call(this);

       _onMovePendingClicked = function() {
         if (confirm(gettext('Are you sure?'))) {
           console.log('Do stuff');
         }

         return false
       };

       new RB.ReviewRequestActionHook({
         extension: this,
         callbacks: {
           '#pending-review-request-action': _onMovePendingClicked
         }
       });
     }
   });
})();

I have tried a lot of things but I do not know the most direct way to update the target group.

Thanks,
Michael

michae...@ymail.com

unread,
Jun 11, 2020, 8:00:13 AM6/11/20
to Review Board Development
I have resolved this.

It may not be the correct way to do it, but it's working ...

_onMovePendingClicked = function () {
   const pendingReview = RB.PageManager.getPage().pendingReview;
   const draft = RB.PageManager.getPage().reviewRequest.draft;

   if (confirm(gettext("Set Target Group to [Pending]?"))) {
     draft.ready({
       ready: function () {
         draft.save(
           _.defaults({
             data: {
               target_groups: "Pending",
               public: true,
             },
             success: function success() {
               pendingReview.publish();
             },
           })
         );
       },
     });
   }

   return false;
};

Thanks,
Michael

michae...@ymail.com

unread,
Jun 12, 2020, 6:16:05 AM6/12/20
to Review Board Development
As a means of update, I refactored my _onMovePendingClicked callback.

The previous approach also added an empty comment after changing the target group.

The new approach only changes the target group.

_onMovePendingClicked = function () {
   const reviewRequestEditor = RB.PageManager.getPage().reviewRequestEditorView
   const targetGroups = reviewRequestEditor._fieldViews.target_groups

   reviewRequestEditor.model.setDraftField(
     targetGroups.fieldID,
     "Deferred",
     _.defaults({
       jsonFieldName: targetGroups.jsonFieldName,
       useExtraData: this.useExtraData,
     }, targetGroups.options));

   reviewRequestEditor.model.publishDraft()
};

My only grip now is that my new 'Pending' button, which is added via BaseReviewRequestAction appears to the left of  the 'Close' button. Ideally I would like my button to appear beside 'Ship It!' on the right side.

Thanks,
Michael
 

Christian Hammond

unread,
Jun 14, 2020, 9:26:30 PM6/14/20
to reviewb...@googlegroups.com
Hi Michael,

Glad you got it working. Unfortunately, there's no way currently to specify the position through any formal API. If you don't mind the lack of future-proofing, the order is controlled by reviewboard.reviews.actions._top_level_ids. Entries are in left-to-right order (index 0 being left-most), and the type is a Python collections.deque. You can register and then manipulate the position, if you want. Just note that there's no guarantee it won't break in the future (but we're not changing it for 4.0).

Christian

--

---
You received this message because you are subscribed to the Google Groups "Review Board Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reviewboard-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/reviewboard-dev/f88f589f-aecb-4ffb-a32c-a5f7580a1049n%40googlegroups.com.


--
Christian Hammond
President/CEO of Beanbag
Makers of Review Board

michae...@ymail.com

unread,
Jun 15, 2020, 5:00:40 AM6/15/20
to Review Board Development
Incredible.

Thank you sir!

I was able to move my new menu item to the far right with

moveMenuItem = _top_level_ids.popleft()
_top_level_ids.append(moveMenuItem)

Admittedly, I could have combined this into 1 statement but its good enough :)

Thanks,
Michael
Reply all
Reply to author
Forward
0 new messages