Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion source/features/cmd-enter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import delegate, {type DelegateEvent} from 'delegate-it';
import * as pageDetect from 'github-url-detection';
import {$, $optional} from 'select-dom';

import {legacyCommentField} from '../github-helpers/selectors.js';
import features from '../feature-manager.js';

function handleKeyDown(event: DelegateEvent<KeyboardEvent>): void {
Expand All @@ -19,7 +20,7 @@ function handleKeyDown(event: DelegateEvent<KeyboardEvent>): void {
}

function init(signal: AbortSignal): void {
delegate('#new_comment_field', 'keydown', handleKeyDown, {signal});
delegate(legacyCommentField, 'keydown', handleKeyDown, {signal});
}

void features.add(import.meta.url, {
Expand Down
10 changes: 6 additions & 4 deletions source/features/quick-mention.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import ReplyIcon from 'octicons-plain-react/Reply';
import {$, $closest, elementExists} from 'select-dom';
import {insertTextIntoField} from 'text-field-edit';

import features from '../feature-manager.js';
import {getLoggedInUser, isArchivedRepoAsync} from '../github-helpers/index.js';
import {is} from '../helpers/css-selectors.js';
import {legacyCommentField} from '../github-helpers/selectors.js';
import {wrap} from '../helpers/dom-utils.js';
import observe, {waitForElement} from '../helpers/selector-observer.js';
import features from '../feature-manager.js';

const prFieldSelector = 'textarea#new_comment_field';
const issueFieldSelector = '#react-issue-comment-composer textarea';
const fieldSelector = [prFieldSelector, issueFieldSelector] as const;
const fieldSelector = [
legacyCommentField,
'#react-issue-comment-composer textarea',
] as const;

const loggedInUser = getLoggedInUser()!;

Expand Down
86 changes: 82 additions & 4 deletions source/features/unwrap-unnecessary-dropdowns.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import * as pageDetect from 'github-url-detection';
import React from 'dom-chef';
import CopilotIcon from 'octicons-plain-react/Copilot';
import {$, $$optional, $closest} from 'select-dom';
import {setFieldText} from 'text-field-edit';
import * as pageDetect from 'github-url-detection';

import features from '../feature-manager.js';
import {legacyCommentField} from '../github-helpers/selectors.js';
import observe from '../helpers/selector-observer.js';
import features from '../feature-manager.js';

// Replace dropdown while keeping its sizing/positioning classes
function replaceDropdownInPlace(dropdown: Element, form: Element): void {
Expand Down Expand Up @@ -35,21 +39,95 @@ function replaceNotificationsDropdown(): void {
button.textContent = `Group by ${button.textContent.toLowerCase()}`;
}

function init(signal: AbortSignal): void {
function initNotifications(signal: AbortSignal): void {
observe('.js-check-all-container > :first-child', replaceNotificationsDropdown, {signal});
}

function insertCopilotInstruction(): void {
const textarea = $(legacyCommentField);
setFieldText(textarea, '@copilot resolve the merge conflicts in this pull request');
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The native button just erases the history btw

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Too bad if you clicked it out of curiosity after writing a comment

}

function createButtonGroup(): JSX.Element {
const agentButtonId = crypto.randomUUID();
const agentTooltipId = crypto.randomUUID();

return (
<div className="ButtonGroup">
<div>
Comment thread
SunsetTechuila marked this conversation as resolved.
<a
className="Button--secondary Button--medium Button"
href={`${location.pathname}/conflicts`}
type="button"
>
<span className="Button-content">
<span className="Button-label">
Resolve conflicts
</span>
</span>
</a>
Comment on lines +58 to +68
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I will create a createButton helper in a separate PR

</div>
<div>
<button
id={agentButtonId}
className="Button--iconOnly Button--secondary Button--medium Button"
aria-labelledby={agentTooltipId}
type="button"
onClick={insertCopilotInstruction}
>
<CopilotIcon/>
</button>
<tool-tip
id={agentTooltipId}
className="sr-only position-absolute"
for={agentButtonId}
popover="manual"
data-direction="s"
data-type="label"
aria-hidden="true"
role="tooltip"
>
Ask Copilot to resolve conflicts
</tool-tip>
</div>
</div>
);
}

function replaceResolveConflictsDropdown(button: HTMLButtonElement): void {
if (button.textContent.trim() !== 'Resolve conflicts') {
return;
}

const buttonGroup = createButtonGroup();
button.replaceWith(buttonGroup);
}

function initPrConversation(signal: AbortSignal): void {
observe(
'[aria-label="Conflicts"] [class^="MergeBoxSectionHeader-module__wrapper"] button[data-component="Button"]',
replaceResolveConflictsDropdown,
{signal},
);
}

void features.add(import.meta.url, {
include: [
pageDetect.isNotifications,
],
init,
init: initNotifications,
}, {
include: [
pageDetect.isPRConversation,
],
init: initPrConversation,
});

/*

Test URLs:

- https://github.com/notifications
- https://github.com/refined-github/sandbox/pull/82

*/
4 changes: 4 additions & 0 deletions source/github-helpers/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ export const newCommentField = [

export const newCommentField_ = requiresLogin;

export const legacyCommentField = 'textarea#new_comment_field';
// Used on: PR conversations, gists and discussions
export const legacyCommentField_ = requiresLogin;

export const commitHashLinkInLists = [
'[data-testid="commit-row-browse-repo"]', // `isCommitList`
'a[id^="commit-details-"]', // `isPRCommitList`
Expand Down
Loading