Show AP.flag with dynamic URL in action

After doing something inside a modal dialog and returning to my glance I would like to show the user a success flag and an external URL. AP.flag does allow me to show a flag outside the glance iframe, but I am restricted to a Non-HTML body and cannot define a dynamic URL:

AP.flag.create({
    type: 'success',
    body: 'HTML code not allowed here',
    actions: {
        'custom-detail-link': 'Click me'
    }
});

AP.events.on('flag.action', function(event){
    if (event.actionIdentifier == 'custom-detail-link') {
        window.top.location.href = 'URL' //can only define a static url here
    }
})

On the other hand AJS.flag does support HTML-code inside the body, but the flag is rendered inside the iframe of the glance and it does not really make sense to show it here.

Is there any solution either passing my dynamic URL to the AP.flag action or allowing a AJS.flag to show up in the outer frame of JIRA?

This is a dirty workaround that works:

AP.flag.create({
    type: 'success',
    body: 'Something has been done!',
    close: 'manual',
    actions: {
        ["customId-" + <some unique ID to identify the link later>]: 'Show result on external system'
}
});

And then later I just get the URL from my addon by passing the id hidden in the actionIdentifier.

AP.events.on('flag.action', function(event){
    if (event.actionIdentifier.startsWith("customId-")) {
        let customId= event.actionIdentifier.replace("customId-", "")
        $.ajax({
            url: '/get-url-for-id-from-addon',
            method: 'GET',
            data: {customId: customId},
            success: function (json) {
                if (json.url)
                    window.open(json.url, '_blank')
            }
        })
    }
})

This is a very ugly solution and I hope for a better idea from you guys. :slight_smile:

1 Like

This solution looks nice, however most likely the window.open will be blocked by browser, because it’s happening outside of user gesture(click, touch, keydown etc.). window.open will return null in such situation.
So it would be better to prefetch this result, before flag action happens :+1:

1 Like

Hi @SebastianK81,

I think window.open("https://www.atlassian.com", "_top") will be blocked by the browser, but opening in a new tab with window.open("https://www.atlassian.com", "_blank") may not depending on the browser popup blocking configuration. Regardless, it’s not a very satisfactory solution so I’ve created https://ecosystem.atlassian.net/browse/ACJS-1137 to support the addition of links in flags.

Regards,
Dugald

3 Likes

Hi @dmorrow,
unfortunately, recent Chrome versions block window.open("https://www.atlassian.com", "_blank") by default, and the “blocked” notification is almost impossible to notice (it’s a small icon to the right of the search bar). So we do need ACJS-1137 for JMWE.
Best,
David

2 Likes