Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to do non-blocking calls for ClientWebPanel's in Stash?

Michael T. April 24, 2015

Hi,

I have a Stash plug-in that calls several REST services to collect various data for showing in a ClientWebPanel in Stash. Unfortunately, these calls can sometimes take a significant amount of time which results in the whole page (i.e., pull request page) not being loaded until the context provider function finishes:

 

function doSomeRestCallsToCollectContextForClientWebPanel(context) {
   var result = null;
   $.ajax(..., async: false,
   success: function (json) {
      result = // ...
   });
   return result;
}
<client-context-provider>doSomeRestCallsToCollectContextForClientWebPanel</client-context-provider>

 

Am I right that there is no way to provide the context for client web panel's asynchronous so that the page can be rendered in the meantime?

 

Thanks,

Michael

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Adam
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 26, 2015

Unfortunately, there is no built-in way to provide async data to your panel. I've created a JIRA for adding support for this: https://jira.atlassian.com/browse/STASH-7330

The best workaround in the meantime is not to use sync AJAX requests, but instead to render a "loading" template initially, then replace it with a new template manually when your data is available. See https://answers.atlassian.com/questions/14812632 for the same answer using other words, if that helps. :/

Cheers,
Adam

Michael T. April 26, 2015

Hi Adam, thanks for your answer, that makes perfectly sense.

0 votes
GabrielleJ
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 24, 2015

By default, the ajax function is set to asynchronous.

I can suggest 2 things. You can try setting it explicitly in the ajax function, add the params "async : true", or use another javascript/jquery (like .get https://api.jquery.com/jquery.get/).

Michael T. April 24, 2015

Well yes, certainly. But the problem here is that I need to return the results which are then passed to my Soy template where it is rendered. And I cannot return a promise or something like that here. I have to yield the results from this function, hence I have to wait (synchronously). Or am I wrong?

TAGS
AUG Leaders

Atlassian Community Events