Skip to content

Commit

Permalink
Issue atlassian-labs#305: added check if slack panel is visible to pr…
Browse files Browse the repository at this point in the history
…event unnecessary REST calls
  • Loading branch information
annapieper committed Aug 30, 2023
1 parent 7a46c55 commit 0cd2a75
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<parent>
<groupId>com.atlassian.plugins</groupId>
<artifactId>jira-slack-server-integration</artifactId>
<version>1.1.13</version>
<version>1.1.14</version>
</parent>

<groupId>com.atlassian.jira.plugins</groupId>
<artifactId>jira-slack-server-integration-plugin</artifactId>
<packaging>atlassian-plugin</packaging>
<version>3.0.10-SNAPSHOT</version>
<version>3.0.11-SNAPSHOT</version>

<name>Slack for Jira Data Center</name>
<description>This is the Slack plugin for Jira Data Center</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ require([
jsCookies
) {
var SLACK_ADMIN_BANNER_COOKIE_KEY = "SLACK_ADMIN_BANNER_DISMISS_2";

AJS.toInit(function () {
if (!isSlackConfigurationPage() && loggedInUser.isAdmin() && !isAlreadyDismissed()) {


if (!isSlackConfigurationPage() && loggedInUser.isAdmin() && !isAlreadyDismissed()
&& (isInIssueView() && isSlackPanelVisible())) {
$.ajax({
url: wrmContextPath() + '/slack/configuration/status',
dataType: 'json',
Expand Down Expand Up @@ -46,5 +50,12 @@ require([
function isAlreadyDismissed() {
return jsCookies.get(SLACK_ADMIN_BANNER_COOKIE_KEY) === "true";
}

function isInIssueView() {
return $('#issue-content').length;
}
function isSlackPanelVisible() {
return $("#slack-issue-panel").length;
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,29 @@ require([

function getTemplate() {
var issueKey = Meta.get("issue-key");
if (issueKey) {
var $issuePanel = $("#slack-issue-panel");
var $spinner = $("#slack-issue-panel-spinner");
var $errors = $("#slack-issue-panel-errors");
$spinner.spin();
return $.ajax({
url: wrmContextPath() + "/slack/issuepanel/data/" + issueKey,
cache: false,
dataType: 'json',
type: "GET"
}).done(function (data) {
var template = JIRA.Templates.Slack.Project.IssuePanel.slackPanel(data);
$issuePanel.html(template);

issuePanelView = createIssuePanelView();
issuePanelView.on("ready", evaluateImmediateActions);
}).fail(function () {
$errors.append(formatter.I18n.getText("jira.plugins.slack.viewissue.panel.error.getting.data"));
}).always(function() {
$spinner.spinStop();
});
var $issuePanel = $("#slack-issue-panel");
if (!issueKey || !$issuePanel.length) {
return;
}
var $spinner = $("#slack-issue-panel-spinner");
var $errors = $("#slack-issue-panel-errors");
$spinner.spin();
return $.ajax({
url: wrmContextPath() + "/slack/issuepanel/data/" + issueKey,
cache: false,
dataType: 'json',
type: "GET"
}).done(function (data) {
var template = JIRA.Templates.Slack.Project.IssuePanel.slackPanel(data);
$issuePanel.html(template);

issuePanelView = createIssuePanelView();
issuePanelView.on("ready", evaluateImmediateActions);
}).fail(function () {
$errors.append(formatter.I18n.getText("jira.plugins.slack.viewissue.panel.error.getting.data"));
}).always(function() {
$spinner.spinStop();
});
}

$(function () {
Expand Down
4 changes: 2 additions & 2 deletions jira-slack-server-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<parent>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-slack-server-integration-parent</artifactId>
<version>1.1.13</version>
<version>1.1.14</version>
</parent>

<artifactId>jira-slack-server-integration</artifactId>
<packaging>pom</packaging>
<version>1.1.13</version>
<version>1.1.14</version>
<name>Jira Slack Integration Modules</name>

<modules>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-slack-server-integration-parent</artifactId>
<version>1.1.13</version>
<version>1.1.14</version>
<packaging>pom</packaging>
<name>Atlassian Slack Integration for Server Project</name>

Expand Down
2 changes: 1 addition & 1 deletion slack-server-integration-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-slack-server-integration-parent</artifactId>
<version>1.1.13</version>
<version>1.1.14</version>
</parent>

<artifactId>slack-server-integration-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ require([
var flag = null;

$(function () {
// skip if user is already in configuration view or edit pages
// skip if user is already in configuration view or edit pages or in issue view without active slack integration
if (contains(window.location.pathname, CONFIGURE_PAGE_URL)
|| contains(window.location.pathname, OAUTH_SESSIONS_PAGE_URL)) {
|| contains(window.location.pathname, OAUTH_SESSIONS_PAGE_URL)
|| (isInIssueView() && !isSlackPanelVisible())) {
return;
}

Expand Down Expand Up @@ -64,6 +65,13 @@ require([
});
}

function isInIssueView() {
return $('#issue-content').length;
}
function isSlackPanelVisible() {
return $("#slack-issue-panel").length;
}

function contains(str, substr) {
return str.indexOf(substr) !== -1;
}
Expand Down

0 comments on commit 0cd2a75

Please sign in to comment.