Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ Thanks for contributing! 🦋🙌
- [](# "wait-for-attachments") [Wait for the attachments to finish uploading before allowing to post a comment.](https://user-images.githubusercontent.com/46634000/104294547-9b8b0c80-54bf-11eb-93e5-65ae158353b3.gif)
- [](# "delete-review-comments-faster") [Adds a button to delete review comments in one click when editing them.](https://user-images.githubusercontent.com/46634000/115445792-9fdd6900-a216-11eb-9ba3-6dab4d2f9d32.png)
- [](# "avoid-accidental-submissions") [Disables the <kbd>enter</kbd>-to-submit shortcut in some commit/PR/issue title fields to avoid accidental submissions. Use <kbd>ctrl</kbd><kbd>enter</kbd> instead.](https://user-images.githubusercontent.com/723651/115148453-5818df00-a068-11eb-92d4-51ac6e937b8b.gif)
- [](# "comment-on-draft-pr-indicator") [Reminds you you’re commenting on a draft PR by changing the submit button’s label.](https://user-images.githubusercontent.com/723651/123682081-39e31280-d853-11eb-9c86-97be400aca67.jpg)

<!-- Refer to style guide above. Keep this message between sections. -->

Expand Down
37 changes: 37 additions & 0 deletions source/features/comment-on-draft-pr-indicator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';

import features from '.';
import onReplacedElement from '../helpers/on-replaced-element';

function addIndicator(button: HTMLElement): void {
const preposition = button.textContent!.includes('Add') ? ' to ' : ' on ';
button.textContent += preposition + 'draft PR';
}

function init(): void {
const buttons = select.all([
'.review-simple-reply-button', // "Add single comment" button
'.add-comment-label', // "Add review comment" button
'.start-review-label', // "Start a review" button
]);
for (const button of buttons) {
addIndicator(button);
}

if (pageDetect.isPRConversation()) {
// The button is part of a .js-updatable-content partial
void onReplacedElement('#partial-new-comment-form-actions .btn-primary', addIndicator, {runCallbackOnStart: true});
}
}

void features.add(__filebasename, {
include: [
pageDetect.isPRConversation,
pageDetect.isPRFiles,
],
exclude: [
() => !pageDetect.isDraftPR(),
],
init,
});
12 changes: 10 additions & 2 deletions source/helpers/on-replaced-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,26 @@ Tracks the replacement of an element, identified via selector.
@param callback The function to call after it's replaced
*/

export default async function onReplacedElement(selector: string, callback: VoidCallback): Promise<void> {
export default async function onReplacedElement(
selector: string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be changed to an object? Isn't it a boolean trap?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I follow

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you meant to comment on the callNow line since there's no boolean here 😃

Good point, changing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I was on mobile and selected the wrong line.

callback: (element: HTMLElement) => void,
{runCallbackOnStart = false} = {},
): Promise<void> {
let trackedElement = select(selector);
if (!trackedElement) {
throw new Error('The element can’t be found');
}

if (runCallbackOnStart) {
callback(trackedElement);
}

while (trackedElement) {
// eslint-disable-next-line no-await-in-loop
await onElementRemoval(trackedElement);
trackedElement = select(selector);
if (trackedElement) {
callback();
callback(trackedElement);
}
}
}
1 change: 1 addition & 0 deletions source/refined-github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ import './features/delete-review-comments-faster';
import './features/no-useless-split-diff-view';
import './features/list-pr-for-branch';
import './features/cancel-wiki-edit-button';
import './features/comment-on-draft-pr-indicator';
import './features/select-notifications';

// Add global for easier debugging
Expand Down