Skip to content

Commit 97a3a41

Browse files
Павел АхметчановПавел Ахметчанов
authored andcommitted
[#163] print stikers for cloud jira
1 parent 5564f27 commit 97a3a41

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

src/printcards/PrintCards.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default class extends PageModification {
1010
}
1111

1212
waitForLoading() {
13-
return this.waitForElement('#jql');
13+
return Promise.any([this.waitForElement('#jql'), this.waitForElement('[data-testid="jql-editor-input"]')]);
1414
}
1515

1616
apply() {

src/printcards/services/printButton.js

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ export class PrintCardButton {
4848
}
4949

5050
onClick() {
51-
const jql = document.querySelector('#jql').value;
51+
const elm = document.querySelector('#jql');
52+
let jql = '';
53+
54+
if (elm) {
55+
jql = document.querySelector('#jql').value;
56+
} else {
57+
jql = new URL(document.location).searchParams.get('jql');
58+
}
5259

5360
const issueCount = this.getAmountOfIssues();
5461
if ((!jql && !jql.length) || jql === 'ORDER BY updated DESC')
@@ -64,18 +71,37 @@ export class PrintCardButton {
6471
);
6572
}
6673

74+
bindBtb() {
75+
const { printCardsBtnId } = this.identifiers;
76+
this.$printCardBtn = document.querySelector(`#${printCardsBtnId}`);
77+
78+
this.$printCardBtn.addEventListener('click', this.onClick);
79+
this.subscribeToSwitchingSearchMechanism();
80+
}
81+
6782
render() {
6883
const { printCardsBtnId } = this.identifiers;
6984
const isPageAlreadyContainsBtn = this.isExistJqElem(`#${printCardsBtnId}`);
85+
const cloudJiraContainer = document.querySelector('[data-testid="jql-editor-input"]');
7086
const isOptionsContainerExist = this.isExistJqElem('.search-options-container');
7187

7288
if (isPageAlreadyContainsBtn) return;
73-
if (!isOptionsContainerExist) return;
89+
let container;
90+
91+
if (cloudJiraContainer) {
92+
container = document.querySelector('[data-testid="jql-editor-input"]').parentElement.parentElement;
93+
container.insertAdjacentHTML('afterbegin', this.getBtnTemplate());
94+
this.bindBtb();
95+
const sampleBtn = container.querySelector('[role="presentation"]');
96+
this.$printCardBtn.parentElement.classList.remove(styles.printCardBtn_Wrapper);
97+
sampleBtn.classList.forEach(cls => this.$printCardBtn.parentElement.classList.add(cls));
98+
return;
99+
}
74100

75-
document.querySelector('.search-container').insertAdjacentHTML('beforeend', this.getBtnTemplate());
76-
this.$printCardBtn = document.querySelector(`#${printCardsBtnId}`);
101+
if (!isOptionsContainerExist) return;
102+
container = document.querySelector('.search-container');
103+
container.insertAdjacentHTML('beforeend', this.getBtnTemplate());
77104

78-
this.$printCardBtn.addEventListener('click', this.onClick);
79-
this.subscribeToSwitchingSearchMechanism();
105+
this.bindBtb();
80106
}
81107
}

src/routing.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ export const getCurrentRoute = () => {
9999
return params.get('jql') ? Routes.SEARCH : Routes.ISSUE;
100100
}
101101

102-
if (pathname.startsWith('/issues/')) return Routes.SEARCH;
102+
// https://server.atlassian.net/jira/software/c/projects/{KEY}/issues/?jql=...
103+
if (pathname.endsWith('/issues/')) return Routes.SEARCH;
103104

104105
return null;
105106
};

0 commit comments

Comments
 (0)