-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore PR review buttons on GitHub Enterprise #6635
Changes from 1 commit
3b9ad8c
0971327
1e9c7cb
9c0c9a7
715c212
7ace685
930d7d5
f12b184
ac7d9c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,16 @@ import * as pageDetect from 'github-url-detection'; | |
import {CheckIcon, FileDiffIcon} from '@primer/octicons-react'; | ||
|
||
import features from '../feature-manager.js'; | ||
import observe from '../helpers/selector-observer.js'; | ||
|
||
function addButtons(radios: HTMLInputElement[]): void { | ||
const form = radios[0].form!; | ||
const actionsRow | ||
= select('.form-actions', form) // TODO: Drop after September 2023 | ||
?? form.closest('.SelectMenu')!.querySelector('.form-actions')!; | ||
function replaceCheckboxes(originalSubmitButton: HTMLButtonElement): void { | ||
const form = originalSubmitButton.form!; | ||
const actionsRow = originalSubmitButton.closest('.form-actions')!; | ||
const formAttribute = originalSubmitButton.getAttribute('form')!; | ||
|
||
// Do not use `select.all` because elements can be outside `form` | ||
// `RadioNodeList` is dynamic, so we need to make a copy | ||
const radios = [...form.elements.namedItem('pull_request_review[event]') as RadioNodeList] as HTMLInputElement[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://stackoverflow.com/a/76206952/288906 Good API, terrible types |
||
|
||
// Set the default action for cmd+enter to Comment | ||
if (radios.length > 1) { | ||
|
@@ -41,7 +45,7 @@ function addButtons(radios: HTMLInputElement[]): void { | |
type="submit" | ||
name="pull_request_review[event]" | ||
// The buttons are no longer inside the form itself; this links the form | ||
form={form.contains(actionsRow) ? undefined : form.id} // TODO: Drop condition after September 2023 | ||
form={formAttribute} | ||
value={radio.value} | ||
className={classes.join(' ')} | ||
aria-label={tooltip!} | ||
|
@@ -65,8 +69,7 @@ function addButtons(radios: HTMLInputElement[]): void { | |
radio.closest('.form-checkbox')!.remove(); | ||
} | ||
|
||
// The selector excludes the "Cancel" button | ||
select('[type="submit"]:not([name])', actionsRow)!.remove(); | ||
originalSubmitButton.remove(); | ||
} | ||
|
||
let lastSubmission: number | undefined; | ||
|
@@ -80,22 +83,15 @@ function blockDuplicateSubmissions(event: DelegateEvent): void { | |
lastSubmission = Date.now(); | ||
} | ||
|
||
function init(signal: AbortSignal): false | void { | ||
// Freeze form to avoid duplicate submissions | ||
delegate('[action$="/reviews"]', 'submit', blockDuplicateSubmissions, {signal}); | ||
|
||
// `return false` must always be after delegated events are added | ||
const radios = select.all('input[type="radio"][name="pull_request_review[event]"]'); | ||
if (radios.length === 0) { | ||
return false; | ||
} | ||
|
||
addButtons(radios); | ||
function init(signal: AbortSignal): void { | ||
// The selector excludes the "Cancel" button | ||
observe('#review-changes-modal [type="submit"]:not([name])', replaceCheckboxes, {signal}); | ||
delegate('#review-changes-modal form', 'submit', blockDuplicateSubmissions, {signal}); | ||
} | ||
|
||
void features.add(import.meta.url, { | ||
include: [ | ||
pageDetect.isPR, | ||
pageDetect.isPRFiles, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why this was so broad There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The review option shows on a specific commit of a PR, that no longer works now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, you're talking about this: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed here: added |
||
], | ||
awaitDomReady: true, | ||
init, | ||
|
@@ -109,3 +105,5 @@ https://github.com/refined-github/sandbox/pull/4/files | |
https://github.com/refined-github/sandbox/pull/12/files | ||
|
||
*/ | ||
|
||
console.log(1); | ||
fregante marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By targeting the original submit button, it's easier to extrapolate all the necessary elements without conditions