Load issue tab JS resources on issue refresh if the last active tab was the custom issue tab

I have an issue tab panel that loads data from AJAX calls through its resource.
I am using JIRA.ViewIssueTabs.onTabReady for it to load the data and display.
All looks good so far, but the problem is when page is refreshed and if the last active tab it had was my issue tab, then the AJAX won’t load on issue refresh. I need to toggle between any two tabs to fetch the data again.

I tried to combine it with $(document).ready or other bind events and it doesn’t work.

I also thought of putting the data in the velocity itself so that it always renders. The problem with this is that my triggers are configured in the JS file and they won’t work. As this tab is intended to take input from users and push it through rest end points, how can I make the tab load when issue is refreshed and last active tab was my issue panel tab?

Hi Anupam,

Its hard to say what may actually be going wrong without seeing some sample code.

But could you try to re-bind the necessary events when the refresh event occurs and see if it solves the problem…

Hi @Fario_Consulting
Thanks, here is the JS

AJS.toInit(function () {
    
    JIRA.ViewIssueTabs.onTabReady(function(event) {

        let currentTab = AJS.$("#issue-tabs").find(".active")[0].id;
        if(currentTab == 'my-tab-key'){
            // my event listeners on the elements of my tab
        }

    });


});

My elements are in the velocity file for the issue tab panel. I tried other binds like document ready or new content added but nothing triggers my event listeners when the page is loaded and my tab is default loaded (as it was last active tab when issue was refreshed).

my plugin descriptor has resources that already want this loaded during page load

  <context>jira.view.issue</context>  
  <dependency>jira.webresources:viewissue</dependency>

Not sure what is wrong. As of now I am just having elements in the velocity file which I am filling from my js file with some rest call.

Even if I pass the entire data as velocity params and populate the tab with all data (instead of rest), I will still miss the event listeners as I am expected to take input from users and then when the click those button, persist those details.

The solution that seems to have worked is adding a listener to the pageShow event
window.addEventListener(‘pageshow’, function(event) {
// add the listeners here also
});