Skip to content

Commit c08f1c0

Browse files
cci: fix DiscussionTools causing issues with render
1 parent c7b4f5f commit c08f1c0

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

src/session/DeputyRootSession.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,11 @@ export default class DeputyRootSession {
569569
}
570570
await casePage.addActiveSection( sectionId );
571571

572-
heading.insertAdjacentElement( 'afterend', el.render() );
572+
if ( heading.parentElement.classList.contains( 'mw-heading' ) ) {
573+
heading.parentElement.insertAdjacentElement( 'afterend', el.render() );
574+
} else {
575+
heading.insertAdjacentElement( 'afterend', el.render() );
576+
}
573577
await el.loadData();
574578
mw.hook( 'deputy.load.cci.session' ).fire();
575579

src/ui/root/DeputyContributionSurveySection.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
300300
for ( let i = 0; i < this.originalList.children.length; i++ ) {
301301
const li = this.originalList.children.item( i );
302302
if ( li.tagName !== 'LI' ) {
303-
return false;
303+
// Skip this element.
304+
continue;
304305
}
305306
const anchor: HTMLElement = li.querySelector( 'a:first-of-type' );
306307
// Avoid enlisting if the anchor can't be found (invalid row).
@@ -559,7 +560,17 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
559560
this._section = null;
560561
await this.getSection( Object.assign( wikitext, { revid } ) );
561562
await this.prepare();
562-
heading.insertAdjacentElement( 'afterend', this.render() );
563+
if ( heading.parentElement.classList.contains( 'mw-heading' ) ) {
564+
// Intentional recursive call
565+
heading.parentElement.insertAdjacentElement(
566+
'afterend', this.render()
567+
);
568+
} else {
569+
// Intentional recursive call
570+
heading.insertAdjacentElement(
571+
'afterend', this.render()
572+
);
573+
}
563574
// Run this asynchronously.
564575
setTimeout( this.loadData.bind( this ), 0 );
565576
}

src/wiki/DeputyCasePage.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,11 @@ export default class DeputyCasePage extends DeputyCase {
139139
isContributionSurveyHeading( el: HTMLElement ): el is ContributionSurveyHeading {
140140
// All headings (h1, h2, h3, h4, h5, h6)
141141
// TODO: l10n
142-
const headlineElement = this.parsoid ? el : el.querySelector<HTMLElement>( '.mw-headline' );
143-
return /^H\d$/.test( el.tagName ) &&
142+
const headlineElement = this.parsoid ?
143+
el :
144+
el.querySelector<HTMLElement>( '.mw-headline' );
145+
// Handle DiscussionTools case (.mw-heading)
146+
return ( el.classList.contains( 'mw-heading' ) || /^H\d$/.test( el.tagName ) ) &&
144147
headlineElement != null &&
145148
/(Page|Article|Local file|File)s? \d+ (to|through) \d+$/.test( headlineElement.innerText );
146149
}
@@ -223,6 +226,10 @@ export default class DeputyCasePage extends DeputyCase {
223226
sectionHeading = sectionHeading.parentElement;
224227
}
225228
}
229+
// When DiscussionTools is being used, the header is wrapped in a div.
230+
if ( sectionHeading.parentElement.classList.contains( 'mw-heading' ) ) {
231+
sectionHeading = sectionHeading.parentElement;
232+
}
226233

227234
const sectionMembers: HTMLElement[] = [];
228235

0 commit comments

Comments
 (0)