Skip to content

Commit 7efb1ab

Browse files
Merge pull request #225 from alejandro5042/makeFilterFaster
Add button to copy filtered agents to clipboard
2 parents 48b127b + 1e4528d commit 7efb1ab

File tree

1 file changed

+44
-7
lines changed

1 file changed

+44
-7
lines changed

src/azdo-pr-dashboard.user.js

+44-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22

33
// @name More Awesome Azure DevOps (userscript)
4-
// @version 3.5.2
4+
// @version 3.5.3
55
// @author Alejandro Barreto (NI)
66
// @description Makes general improvements to the Azure DevOps experience, particularly around pull requests. Also contains workflow improvements for NI engineers.
77
// @license MIT
@@ -332,13 +332,23 @@
332332
value="${regexFilterString}">
333333
<div id="agentFilterCounter" style="color: var(--text-secondary-color);"/>
334334
<div>
335+
<button
336+
id="copyMatchedAgentsToClipboard"
337+
class="bolt-button bolt-icon-button subtle bolt-focus-treatment"
338+
role="button"
339+
tabindex="0"
340+
type="button"
341+
style="padding: 0px; margin-left: 10px;"
342+
title="Copy Matched Agents to Clipboard">
343+
<span class="left-icon flex-noshrink fabric-icon ms-Icon--Copy medium" style="padding: 5px 10px"/>
344+
</button>
335345
<button
336346
id="agentFilterRefresh"
337347
class="refresh-dashboard-button bolt-button bolt-icon-button subtle bolt-focus-treatment"
338348
role="button"
339349
tabindex="0"
340350
type="button"
341-
style="padding: 0px; margin-left: 10px;">
351+
style="padding: 0px;">
342352
<span class="left-icon flex-noshrink fabric-icon ms-Icon--Refresh medium" style="padding: 5px 10px"/>
343353
</button>
344354
</div>
@@ -352,6 +362,7 @@
352362
document.getElementById('agentFilterInput').addEventListener('input', filterAgentsDebouncer);
353363
document.getElementById('agentFilterInput').addEventListener('keydown', filterAgentsNow);
354364
document.getElementById('agentFilterRefresh').addEventListener('click', filterAgentsNow);
365+
document.getElementById('copyMatchedAgentsToClipboard').addEventListener('click', copyMatchedAgentsToClipboard);
355366
}
356367
filterAgents();
357368
});
@@ -360,6 +371,30 @@
360371
setInterval(filterAgents, 60000);
361372
}
362373

374+
function copyMatchedAgentsToClipboard() {
375+
if (filterAgents.running) return;
376+
377+
let matchString = '';
378+
let total = 0;
379+
const agentRows = document.querySelectorAll('a.bolt-list-row.single-click-activation');
380+
agentRows.forEach(agentRow => {
381+
const agentCells = agentRow.querySelectorAll('div');
382+
const agentName = agentCells[1].innerText;
383+
if ($(agentRow).is(':visible')) {
384+
matchString += `${agentName}.*,`;
385+
total += 1;
386+
}
387+
});
388+
389+
navigator.clipboard.writeText(matchString);
390+
swal.fire({
391+
icon: 'success',
392+
title: `${total} matched agents copied to clipboard!`,
393+
showConfirmButton: false,
394+
timer: 1500,
395+
});
396+
}
397+
363398
function filterAgentsNow(event) {
364399
if (event.key === 'Enter' || event.type === 'click') {
365400
filterAgents.enter = true;
@@ -405,6 +440,7 @@
405440
}
406441
document.getElementById('agentFilterCounter').innerText = 'Filtering...';
407442
document.getElementById('agentFilterInput').readOnly = true;
443+
document.getElementById('copyMatchedAgentsToClipboard').disabled = true;
408444

409445
// Try to push the filter term if possible.
410446
try {
@@ -461,17 +497,17 @@
461497
if (!regexFilter.test(rowValue)) {
462498
agentRow.classList.add('hiddenAgentRow');
463499
} else {
464-
agentCells[1].querySelectorAll('span')[0].classList.add('agent-name-span');
465500
agentRow.classList.remove('hiddenAgentRow');
466-
if (atNI) {
467-
matchedAgents[agentName] = agentCells;
468-
}
501+
matchedAgents[agentName] = agentCells;
469502
}
470503
});
471504
$('.hiddenAgentRow').hide();
472505

473506
for (const [agentName, agentCells] of Object.entries(matchedAgents)) {
474-
addAgentExtraInformation(agentCells, agentName, currentPoolId, poolAgentsInfo);
507+
if (atNI) {
508+
agentCells[1].querySelectorAll('span')[0].classList.add('agent-name-span');
509+
addAgentExtraInformation(agentCells, agentName, currentPoolId, poolAgentsInfo);
510+
}
475511
}
476512
document.getElementById('agentFilterCounter').innerText = `(${Object.keys(matchedAgents).length}/${totalCount})`;
477513
} catch (e) {
@@ -483,6 +519,7 @@
483519

484520
function exitFilterAgents() {
485521
document.getElementById('agentFilterInput').readOnly = false;
522+
document.getElementById('copyMatchedAgentsToClipboard').disabled = false;
486523
filterAgents.running = false;
487524
filterAgents.enter = false;
488525
}

0 commit comments

Comments
 (0)