From 11b927189bab258a226e251c1bd87504feee51f4 Mon Sep 17 00:00:00 2001
From: Federico Brigante <github@bfred.it>
Date: Thu, 17 Jan 2019 19:57:53 +0700
Subject: Drop Babel in favor of esm and TypeScript (#1726)

To get some meaningful errors during feature development, I thought it'd be useful to use TypeScript on `features.js` only, hoping to keep it contained to that file.

@sindresorhus suggested we just extend it the whole extension and maybe that can be done incrementally, without having to necessarily use types on everything.
---
 source/features/batch-open-issues.tsx | 72 +++++++++++++++++++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 source/features/batch-open-issues.tsx

(limited to 'source/features/batch-open-issues.tsx')

diff --git a/source/features/batch-open-issues.tsx b/source/features/batch-open-issues.tsx
new file mode 100644
index 00000000..2a2feef4
--- /dev/null
+++ b/source/features/batch-open-issues.tsx
@@ -0,0 +1,72 @@
+/* eslint-disable no-alert */
+import {React} from 'dom-chef/react';
+import select from 'select-dom';
+import features from '../libs/features';
+
+const confirmationRequiredCount = 10;
+
+function getUrlFromItem(checkbox) {
+	return checkbox.closest('.js-issue-row').querySelector('.js-navigation-open').href;
+}
+
+function openIssues() {
+	const issues = select.all([
+		'#js-issues-toolbar.triage-mode + div [name="issues[]"]:checked', // Get checked checkboxes
+		'#js-issues-toolbar:not(.triage-mode) + div .js-issue-row' // Or all items
+	].join(','));
+
+	if (
+		issues.length >= confirmationRequiredCount &&
+		!confirm(`This will open ${issues.length} new tabs. Continue?`)
+	) {
+		return;
+	}
+
+	browser.runtime.sendMessage({
+		urls: issues.map(getUrlFromItem),
+		action: 'openAllInTabs'
+	});
+}
+
+function init() {
+	if (select.all('.js-issue-row').length < 2) {
+		return false;
+	}
+
+	const filtersBar = select('.table-list-header .table-list-header-toggle:not(.states)');
+	if (filtersBar) {
+		filtersBar.prepend(
+			<button
+				type="button"
+				onClick={openIssues}
+				class="float-left btn-link rgh-open-all-selected"
+			>
+				Open All
+			</button>
+		);
+	}
+
+	const triageFiltersBar = select('.table-list-triage .table-list-header-toggle');
+	if (triageFiltersBar) {
+		triageFiltersBar.prepend(
+			<button
+				type="button"
+				onClick={openIssues}
+				class="float-left btn-link rgh-open-all-selected"
+			>
+				Open in new tabs
+			</button>
+		);
+	}
+}
+
+features.add({
+	id: 'batch-open-issues',
+	include: [
+		features.isGlobalIssueSearch,
+		features.isGlobalPRSearch,
+		features.isIssueList
+	],
+	load: features.onAjaxedPages,
+	init
+});
-- 
cgit v1.2.3

