Skip to content

Commit 7ba0edb

Browse files
authored
warning-for-disallow-edits - Restore feature (refined-github#7583)
1 parent a7cdf5a commit 7ba0edb

2 files changed

Lines changed: 18 additions & 28 deletions

File tree

‎source/features/warning-for-disallow-edits.css‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,13 @@
44
.rgh-warning-for-disallow-edits {
55
display: none;
66
}
7+
8+
.discussion-sidebar-item:has(input[name='collab_privs']:not(:checked))
9+
+ .rgh-warning-for-disallow-edits {
10+
display: block;
11+
}
12+
13+
.discussion-sidebar-item:has(input[name='collab_privs']:checked)
14+
+ .rgh-warning-for-disallow-edits {
15+
display: none;
16+
}

‎source/features/warning-for-disallow-edits.tsx‎

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,33 @@
11
import './warning-for-disallow-edits.css';
22
import React from 'dom-chef';
33
import {$} from 'select-dom';
4-
import onetime from 'onetime';
54
import * as pageDetect from 'github-url-detection';
6-
import delegate, {DelegateEvent} from 'delegate-it';
75

86
import features from '../feature-manager.js';
97
import attachElement from '../helpers/attach-element.js';
108

11-
const getWarning = onetime(() => (
9+
const getWarning = (): React.JSX.Element => (
1210
<div className="flash flash-error mt-3 rgh-warning-for-disallow-edits">
13-
<strong>Note:</strong> Maintainers may require changes. It’s easier and faster to allow them to make direct changes before merging.
11+
<strong>Note:</strong> Maintainers may require changes. It&apos;s easier and faster to allow them to make direct changes before merging.
1412
</div>
15-
));
13+
);
1614

17-
function update(checkbox: HTMLInputElement): void {
18-
if (checkbox.checked) {
19-
getWarning().remove();
20-
} else {
21-
attachElement(
22-
checkbox.closest(`
23-
.timeline-comment,
24-
.discussion-sidebar-item > .d-inline-flex
25-
`),
26-
{after: getWarning},
27-
);
28-
}
29-
}
30-
31-
function toggleHandler(event: DelegateEvent<Event, HTMLInputElement>): void {
32-
update(event.delegateTarget);
33-
}
34-
35-
function init(signal: AbortSignal): void | false {
15+
function init(): void | false {
3616
const checkbox = $('input[name="collab_privs"]');
3717
if (!checkbox) {
3818
return false;
3919
}
4020

41-
// TODO: Rewrite with :has selector, maybe in https://github.com/refined-github/refined-github/issues/7574
42-
update(checkbox); // The sidebar checkbox may already be un-checked
43-
delegate('input[name="collab_privs"]', 'change', toggleHandler, {signal});
21+
attachElement(
22+
checkbox.closest('.discussion-sidebar-item'),
23+
{after: getWarning},
24+
);
4425
}
4526

4627
void features.add(import.meta.url, {
4728
include: [
4829
pageDetect.isCompare,
4930
pageDetect.isPRConversation,
50-
// No need to exclude `isClosedPR` as the checkbox won't be present
5131
],
5232
awaitDomReady: true,
5333
init,

0 commit comments

Comments
 (0)