Refresh Jira Gadget AJAX while Viewing Configuration Screen

Having trouble finding a solution to this specific issue and I'm really hoping for a resolution.

I am currently working on developing a Jira gadget where I have a configuration screen with two fields. The first one is a quickfind project picker that allows you to type and find projects, then click on the desired one.

The second field is for Components. Here, you can select the component of the project you want to filter by. However, as components vary for each project, the Component field is populated through an AJAX call specified in the gadget's "args" section within the "config" part.

The only setback is that this AJAX call is triggered only upon the initial loading of the gadget, before a project is selected. Therefore, the result always shows "Select A Project".

I am looking for a way to rerun this AJAX call when the selected project is changed.

Is this scenario achievable? Or are there alternative solutions available? I have attempted using timers to detect changes, but encountered issues, particularly regarding accessing/altering the Component dropdown field which resulted in the gadget failing to load.

Update: Below you'll find the Javascript code for the gadget. As visible, I have implemented a refreshComponents() method in Javascript, capable of retrieving the Components based on a project ID. However, I'm struggling to associate this with the correct event. Also, I seem unable to directly modify any components on the page using jQuery or standard JS.

<div id="chart_div" style="overflow: auto;"></div>

        <script type="text/javascript">
        
                // JavaScript code goes here
                
        </script>

Answer №1

If you want to dynamicize your component field, consider turning it into a Callback Builder.

Within the callback function, make sure to execute these steps:

  1. Retrieve options using an AJAX call
  2. Render the dropdown menu
  3. Add an event listener to update the list when required

Your updated component field could resemble the following code snippet, assuming jQuery usage for simplicity.

{
    userpref: "component",
    label: "Component",
    id: "component_field_id"
    description: "Choose your preferred issue type",
    type: "callbackBuilder",
    callback: function(parentDiv){

        function renderOptions(options){
            // Replace elements in parentDiv based on options param
            // Utilize gadget.getPref('component') to mark the correct option as selected
        }

        function getOptions(){
            $.ajax({
                 url: "__ATLASSIAN_BASE_URL__/rest/severity-gadget/1.0/severity-issues/getComponents.json",
                 data: {
                     projectId: $("#filter_projectOrFilterId_id").val() 
                 }
            }).done(renderOptions);
        }

        // Fetch and display options upon gadget load
        getOptions();

        // Fetch and display options upon triggering an event
        $(parentDiv).on("update-options", getOptions);
    }
}

In addition, ensure to trigger an event when the project selection field value changes. Outside of the gadget definition in your JS code, include similar scripting (and confirm the CSS selector for the project/filter selector):

$(document).on("change", "#filter_projectOrFilterId_id", function(){
    $("#component_field_id").trigger("update-options");
});

This approach could help achieve your desired functionality, although testing may be necessary.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to generate a fresh set of data from a search parameter?

I have received data from an API call that needs to be filtered. I am utilizing Redux instead of local state for this task. Below are the actions I have defined: import ActionTypes from '../constants/ActionTypes'; export const passengersDataAc ...

Stop the animation when the mouse is moved

Below is the code I am working with: $(source) .on('mouseenter', start) .on('mouseleave', stop) .on('mousemove', zoom.move); Within this code, I have attached several mouse event listeners. When the 'mouseenter' ev ...

Node.js express version 4.13.3 is experiencing an issue where the serveStatic method is not properly serving mp3 or

I am currently utilizing Express 4.13.3 along with the serve-static npm module to serve static assets successfully, except for files with mp3 or ogg extensions. Despite reviewing the documentation, I have not come across any information indicating that thi ...

Issue with ThemeManager in Material UI & React: Constructor is not valid

Currently, I am integrating Material UI into a small React application, but I suspect that the tutorial I am following is outdated and relies on an older version of Material UI. The error _materialUi2.default.Styles.ThemeManager is not a constructor keeps ...

Error: Attempted to export 'e', however it was not defined in the module (located at vite.js?v=d59cec13:236:3) - occurring in the three.js/vite combination

After dabbling in javascript, I decided to explore three.js and found it quite intriguing. However, after hours of setting everything up, I encountered a roadblock. When I attempted to create geometry and render it, the code stopped working. Upon investiga ...

Obtain unique identifiers for the purpose of sorting the items

While utilizing Nuxt.js, I am fetching random images from URLs structured like this: http://www.randomimage.com?ID=myId To display 2 pictures, I use the following methods: getRandomArbitrary(min, max) { return this.numb = Math.floor(Math.random() * ...

Tips for adjusting the button color in Material UI by utilizing the ":active" pseudo-class

In the project I am currently working on, I am incorporating Material UI. One of the tasks I need to complete is changing the active state of a button. I have implemented both hover and active states from Material UI in my code: const useStyles = makeStyle ...

Is there a way to access the filtered or organized rows in the Quasar Q-Table?

I have encountered a roadblock in my project. Despite installing Quasar version 2.0.0, I realized that it lacks a property to access the filtered or sorted rows. Previous versions of q-table had a computedRows property which was missing in the latest ver ...

JavaScript JQuery alert popup fails to display

I have been attempting to create an alert pop-up using JQuery that will display when a user clicks on submit without filling out the form. However, when I test my code by leaving the form empty and clicking 'submit', the page just refreshes with ...

The jqGrid is not showing the AJAX JSON data as expected

Currently, I am exploring jqgrid and trying to figure out how to display data in another jqgrid when clicking on a specific colmodel. The retrieved data from the server goes through a function and reaches the grid, but no information is displayed without a ...

What is the way to access the "bio" property of a "User" object using JavaScript?

How can I retrieve the "bio" value from the "User" object? Refer to the image below for clarification: View the object here After running this code using the discordjs-selfbot-v13 npm package, I received the following object: See the code here. I attemp ...

Several jQuery ajax requests seem to be failing due to errors in previous calls

I am experiencing an issue with my website's login form that utilizes ajax to send the login information to php. After successfully logging in, users have the ability to log out and then return to the login page again. However, I am facing a problem w ...

Storing the blob received from an AJAX call into Azure Blob Storage may result in a corrupted image

When I send a PDF to my vendor's API, they return a .png file as a blob (note: see update 2 regarding the data type being returned). I want to store this in Azure Blob Storage. However, when using the code below, the uploaded file becomes corrupted. ...

Using JSONP with $.ajax triggers security alert in IE8

I have a secure website and I'm running LifeRay on Tomcat. Currently, I am using the following URL: Additionally, I am using the below code to retrieve and process the data: jQuery.ajax({ url: URL, dataType: 'jsonp', async: fal ...

Leverage the power of personalized SCSS styles in combination with Bootstrap-Vue, Webpack, and

I have been working on an application using VueJS with Bootstrap-Vue and I encountered a challenge while trying to import a SCSS file to customize the Bootstrap variables and add some custom styles. Here are the steps I have taken so far: Installed node ...

The autocomplete feature triggers the closure of the bootstrap dropdown when selecting

I have developed a basic material auto complete feature. Using Angular 5 and a bootstrap 4 dropdown to showcase a form. The issue I am facing is that when I place the autocomplete inside the dropdown and choose an item from it, the entire dropdown closes ...

What is the best way to execute multiple controller functions for a single route?

I have a specific route set up for users to submit loan applications. What I want to achieve is to call different controller functions based on the amount of the loan that the user is applying for. app.use('/submitLoanRequest50kMore', mw1, mw2, ...

What are the methods for choosing various boxes using the UP/DOWN/RIGHT/LEFT arrow keys?

This code snippet displays a 3x3 matrix where boxes can be hovered over and selected. The goal is to navigate around with keys and select boxes using ENTER. Can anyone provide guidance on how to achieve this functionality? <link rel="stylesheet" href ...

The non-disappearing nature of -webkit-appearance

I have been attempting to eliminate the -webkit-appearance:none; property using jQuery, but all my efforts have been unsuccessful. Here are the methods I have tried: jQuery(document).ready(function(){ jQuery("select").removeAttr('style'); j ...

"Encountered an issue with ng-annotate during processing

I'm attempting to utilize ng-annotate on my Angular application, but it seems to be not working at all. Here is the configuration part: (function () { 'use strict'; angular.module('app') .config(/*@ngInject*/ ro ...