Plugin Development - UI Extension: the button shows up, but nothing happened by clicking

191 views
Skip to first unread message

Yan

unread,
Dec 23, 2021, 5:48:01 AM12/23/21
to Repo and Gerrit Discussion
Hi, 
I have updated my server recently to 3.4.1 and rebuilt plugins according to the document https://gerrit-review.googlesource.com/Documentation/dev-plugins.html#ui_extension
My plugin should add a button to the change view, and then if the user click the button, the topic will then be extended. And by submitting, if the extension is there, some functions will be called. The buttons shows up, but nothing happens by clicking. And if I manually extended the topic, the logical functions can also be triggered by submitting.  Actually, the apply method is never called in my case. 
Any idea?

I also have found many useful examples here https://gerrit.googlesource.com/plugins/examples/
and have tried the restApiPostRevision plugin, but it has the same issue by me. The button shows up, but the apply method is never called. 


Yan

unread,
Jan 5, 2022, 4:28:15 PM1/5/22
to Repo and Gerrit Discussion
Hi, 

I have tried to call the rest api via CURL, which will call the apply() method, but click the button doesn't trigger anything. And I have tried to use JS module exposed as a WebUiPlugin, it doesn't work either. I guess the problem could be the documents and/or examples doesn't support polygerrit-ui. Can anyone help here?

Thanks.
Yan

Nasser Grainawi

unread,
Jan 5, 2022, 4:34:32 PM1/5/22
to Yan, Repo and Gerrit Discussion

On Jan 5, 2022, at 2:28 PM, Yan <biya...@gmail.com> wrote:

Hi, 

I have tried to call the rest api via CURL, which will call the apply() method, but click the button doesn't trigger anything. And I have tried to use JS module exposed as a WebUiPlugin, it doesn't work either. I guess the problem could be the documents and/or examples doesn't support polygerrit-ui. Can anyone help here?


The examples repo does need to be updated for PolyGerrit. Help there would be great :)


Thanks.
Yan

On Thursday, 23 December 2021 at 11:48:01 UTC+1 Yan wrote:
Hi, 
I have updated my server recently to 3.4.1 and rebuilt plugins according to the document https://gerrit-review.googlesource.com/Documentation/dev-plugins.html#ui_extension
My plugin should add a button to the change view, and then if the user click the button, the topic will then be extended. And by submitting, if the extension is there, some functions will be called. The buttons shows up, but nothing happens by clicking. And if I manually extended the topic, the logical functions can also be triggered by submitting.  Actually, the apply method is never called in my case. 
Any idea?

I also have found many useful examples here https://gerrit.googlesource.com/plugins/examples/
and have tried the restApiPostRevision plugin, but it has the same issue by me. The button shows up, but the apply method is never called. 



-- 
-- 
To unsubscribe, email repo-discuss...@googlegroups.com
More info at http://groups.google.com/group/repo-discuss?hl=en

--- 
You received this message because you are subscribed to the Google Groups "Repo and Gerrit Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to repo-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/repo-discuss/474026ce-54fd-4f40-b472-dcfb8c94d6b6n%40googlegroups.com.

David Ostrovsky

unread,
Jan 6, 2022, 11:59:23 AM1/6/22
to Repo and Gerrit Discussion
nas...@codeaurora.org schrieb am Mittwoch, 5. Januar 2022 um 22:34:32 UTC+1:

On Jan 5, 2022, at 2:28 PM, Yan <biya...@gmail.com> wrote:

Hi, 

I have tried to call the rest api via CURL, which will call the apply() method, but click the button doesn't trigger anything. And I have tried to use JS module exposed as a WebUiPlugin, it doesn't work either. I guess the problem could be the documents and/or examples doesn't support polygerrit-ui. Can anyone help here?


The examples repo does need to be updated for PolyGerrit. Help there would be great :)


You could use Zoekt to search in gerrit related projects and plugins: [1].
In chromium-behavior plugin you can see one example of adding a button with handler: [2].

Message has been deleted

Yan

unread,
Jan 6, 2022, 5:57:18 PM1/6/22
to Repo and Gerrit Discussion
On Thursday, 6 January 2022 at 17:59:23 UTC+1 David Ostrovsky wrote:
nas...@codeaurora.org schrieb am Mittwoch, 5. Januar 2022 um 22:34:32 UTC+1:

On Jan 5, 2022, at 2:28 PM, Yan <biya...@gmail.com> wrote:

Hi, 

I have tried to call the rest api via CURL, which will call the apply() method, but click the button doesn't trigger anything. And I have tried to use JS module exposed as a WebUiPlugin, it doesn't work either. I guess the problem could be the documents and/or examples doesn't support polygerrit-ui. Can anyone help here?


The examples repo does need to be updated for PolyGerrit. Help there would be great :)


You could use Zoekt to search in gerrit related projects and plugins: [1].
In chromium-behavior plugin you can see one example of adding a button with handler: [2].


The example is really great! 

Yan

unread,
Jan 6, 2022, 6:00:16 PM1/6/22
to Repo and Gerrit Discussion
Hi, 

Thanks for the reply. I was able to write a small js file to add a button. But it seems complicated, if I need to convert all  the logical staff into js. 
And my plugin has also implementation using EventListener, so it will be nice if I can keep use the old style, means extending from "UiAction<RevisionResource>, RestModifyView<RevisionResource, Input>". Actually just like the example example-restApiPostRevision and in document dev-plugins.html#ui_extension.

Any idea why the apply can only be called by REST call but not by clicking the button? 

Actually, I have also tried something awkward, I copied the PostPrivate.java from gerrit to my plugin, and register it correspondingly. But I faced the same issue, which means I can set the change private using CURL but not the button. I do think, there should be a "easy" solution for me instead of converting things to TypeScript.

Thanks again :P

Yan

On Wednesday, 5 January 2022 at 22:34:32 UTC+1 nas...@codeaurora.org wrote:

On Jan 5, 2022, at 2:28 PM, Yan <biya...@gmail.com> wrote:

Hi, 

I have tried to call the rest api via CURL, which will call the apply() method, but click the button doesn't trigger anything. And I have tried to use JS module exposed as a WebUiPlugin, it doesn't work either. I guess the problem could be the documents and/or examples doesn't support polygerrit-ui. Can anyone help here?


The examples repo does need to be updated for PolyGerrit. Help there would be great :)

I'd like to help out, after resolving my problem. :P

Yan

unread,
Jan 6, 2022, 6:07:37 PM1/6/22
to Repo and Gerrit Discussion
I decided to post my small demo here, in case somebody look into this conversation by google.

Gerrit.install(plugin => {
plugin.on("showchange", params => {
const changeActions = plugin.changeActions();
MyKey = changeActions.add("revision", "HelloWorld");
changeActions.setEnabled(MyKey, true);
changeActions.setTitle(MyKey, "I want to say Hello World!")
changeActions.addTapListener(MyKey, () => {
if (confirm("Hello World?")) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
}
 console.log(txt);
});
})
})

Martin Waitz

unread,
Feb 22, 2022, 1:44:02 PM2/22/22
to Repo and Gerrit Discussion
Hi,

Yan schrieb am Freitag, 7. Januar 2022 um 00:07:37 UTC+1:

Gerrit.install(plugin => {
plugin.on("showchange", params => {
const changeActions = plugin.changeActions();
MyKey = changeActions.add("revision", "HelloWorld");

})
})

When I try to register a new action in my plugin in this way, then I sometimes get multiple copies of my button.
E.g. changing patchsets triggers the event and polygerrit happily creates two more buttons.
Am I supposed to check for the existence of the button before calling `changeActions.add()`?
Shouldn't these calls be idempotent, so that calling them again don't change anything?

-- Martin 
Message has been deleted

Yan

unread,
Feb 22, 2022, 2:45:29 PM2/22/22
to Repo and Gerrit Discussion
Yes, you can check using the key and then remove it. I have done something like the following section in my code:

if (MyKey !== null) {
changeActions.remove(MyKey);
}
Actually, I need information from the "change" view, because the button changes its label and function conditionally. If you have a static button, it  maybe possible to achieve it more efficient. But I haven't look into that.

Yan

Ben Rohlfs

unread,
Feb 23, 2022, 1:40:09 AM2/23/22
to martin...@gmail.com, Repo and Gerrit Discussion, Yan

--
--
To unsubscribe, email repo-discuss...@googlegroups.com
More info at http://groups.google.com/group/repo-discuss?hl=en

---
You received this message because you are subscribed to the Google Groups "Repo and Gerrit Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to repo-discuss...@googlegroups.com.

hunter Chen

unread,
May 16, 2022, 10:47:32 AM5/16/22
to Repo and Gerrit Discussion
Hi guys, 
I ran into same problem, has the issue been solved?

Yan

unread,
May 18, 2022, 3:36:18 AM5/18/22
to Repo and Gerrit Discussion
I have converted my plugin to JavaScript style and it works fine.
Reply all
Reply to author
Forward
0 new messages