| 10 | import observe from '../helpers/selector-observer.js'; |
| 11 | |
| 12 | function addQuickButtons(contextMenuIcon: HTMLElement): void { |
| 13 | const contextMenuDetails = closestElement('details', contextMenuIcon); |
| 14 | |
| 15 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments -- Wrong |
| 16 | const menuItem = $optional<HTMLElement>([ |
| 17 | 'form[action$="/cancel"]', |
| 18 | 'li:has(> button[data-show-dialog-id^="delete-workflow-run"])', |
| 19 | ], contextMenuDetails)?.cloneNode(true); |
| 20 | |
| 21 | if (!menuItem) { |
| 22 | // No access to this repo |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | const button = $('button', menuItem); |
| 27 | button.ariaLabel = button.textContent.trim(); |
| 28 | button.replaceChildren(menuItem.tagName === 'FORM' ? <SquareCircleIcon /> : <TrashIcon />); |
| 29 | button.classList = 'timeline-comment-action color-fg-muted btn-link rgh-actions-run-removal p-1'; |
| 30 | $('summary', contextMenuDetails).classList.add('p-1'); |
| 31 | const rightControlsContainer = contextMenuDetails.parentElement!; |
| 32 | // Prepending so that the cloned dialog opens instead of the one inside the menu, as it is hidden when the menu is closed |
| 33 | rightControlsContainer.classList.add('d-flex', 'flex-column-reverse', 'mt-n2', 'mb-n2'); |
| 34 | rightControlsContainer.prepend(menuItem); |
| 35 | } |
| 36 | |
| 37 | function init(signal: AbortSignal): void { |
| 38 | observe('#partial-actions-workflow-runs .Box-row details .octicon-kebab-horizontal', addQuickButtons, {signal}); |