Skip to content

Commit

Permalink
Adds a Custom URL action for Jira Query buttons (#11)
Browse files Browse the repository at this point in the history
Adds a new **Open URL** button action that allows a custom URL to be
opened when tapping the Jira button.
  • Loading branch information
mediabounds authored Apr 7, 2024
1 parent 0408bbd commit 7922f6a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 deletions.
12 changes: 11 additions & 1 deletion src/JiraPluginSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ export interface ViewInBrowserAction {
limit: number;
}

export type JQLQueryKeyAction = 'Refresh' | 'ViewFilter' | ViewInBrowserAction;
/**
* An action to open a custom URL.
*/
export interface OpenUrlAction {
/**
* The URL to open when the action is invoked.
*/
url: string;
}

export type JQLQueryKeyAction = 'Refresh' | 'ViewFilter' | ViewInBrowserAction | OpenUrlAction;

/**
* Settings used by the JQL Query action.
Expand Down
20 changes: 14 additions & 6 deletions src/actions/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@ class Query extends BaseJiraAction<CountableResponse<SearchResponse>, JQLQuerySe
this.openURL(`https://${event.settings.domain}/issues/?jql=${encodeURIComponent(event.settings.jql)}`);
break;
default: {
const issues = this.getPollingClient()?.getLastResponse()?.data?.issues ?? [];
const action = event.settings.keyAction;
if ("limit" in action) {
const issues = this.getPollingClient()?.getLastResponse()?.data?.issues ?? [];

issues
.slice(0, event.settings.keyAction.limit ?? 5)
.forEach(issue => {
this.openURL(this.getIssueUrl(issue, event.settings));
});
issues
.slice(0, action.limit ?? 5)
.forEach(issue => {
this.openURL(this.getIssueUrl(issue, event.settings));
});
} else if ("url" in action) {
if (action.url) {
this.openURL(action.url);
}
}

break;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/inspectors/Query.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
<option value="ViewFilter" selected>View JQL filter result</option>
<option value="ViewIssues">Open issues</option>
<option value="Refresh">Check for update</option>
<option value="OpenUrl">Open URL</option>
</select>
<input class="sdpi-item-value" type="number" placeholder="5" min="0" step="1" max="25" id="key-action-limit">
</div>
<div class="sdpi-item">
<div class="sdpi-item-label">URL</div>
<input class="sdpi-item-value" type="url" placeholder="https://www.example.com" id="key-action-url">
</div>
</div>

<pi-authentication id="auth"></pi-authentication>
Expand Down
27 changes: 25 additions & 2 deletions src/inspectors/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class QueryActionPropertyInspector extends PollingActionInspector<JQLQuerySettin
private jql = document.getElementById('jql') as HTMLTextAreaElement;
private keyAction = document.getElementById('key-action') as HTMLSelectElement;
private keyActionLimit = document.getElementById('key-action-limit') as HTMLInputElement;
private keyActionUrl = document.getElementById('key-action-url') as HTMLInputElement;

/**
* {@inheritDoc}
Expand All @@ -25,12 +26,18 @@ class QueryActionPropertyInspector extends PollingActionInspector<JQLQuerySettin

// Action settings.
this.keyActionLimit.hidden = true;
this.keyActionUrl.parentElement.hidden = true;
if (typeof settings.keyAction === 'string') {
this.keyAction.value = settings.keyAction;
} else if (typeof settings.keyAction !== 'undefined') {
} else if ("limit" in settings.keyAction) {
this.keyAction.value = 'ViewIssues';
this.keyActionLimit.value = `${settings.keyAction.limit ?? 5}`;
this.keyActionLimit.hidden = false;
} else if ("url" in settings.keyAction) {
this.keyAction.value = 'OpenUrl';
this.keyActionUrl.value = settings.keyAction.url;
this.keyActionUrl.parentElement.hidden = false;
this.keyActionUrl.placeholder = this.getJiraUrl();
}

this.authentication.value = settings;
Expand Down Expand Up @@ -94,12 +101,28 @@ class QueryActionPropertyInspector extends PollingActionInspector<JQLQuerySettin
return 'ViewFilter';
case 'ViewIssues':
return {
limit: parseInt(this.keyActionLimit.value, 10) ?? 5,
limit: parseInt(this.keyActionLimit.value, 10) || 5,
};
case 'OpenUrl':
return {
url: this.keyActionUrl.value || this.getJiraUrl()
};
case 'Refresh':
return 'Refresh';
}
}

/**
* Gets the URL to the Jira default page.
* @returns The URL to Jira, or null if the Jira connection is not configured.
*/
private getJiraUrl(): string|null {
if (!this.settings.domain) {
return null;
}

return `https://${this.settings.domain}`;
}
}

const inspector = new QueryActionPropertyInspector({ plugin });
Expand Down

0 comments on commit 7922f6a

Please sign in to comment.