Skip to content

Commit

Permalink
cci: fix DiscussionTools causing issues with render
Browse files Browse the repository at this point in the history
  • Loading branch information
ChlodAlejandro committed Jan 18, 2023
1 parent c7b4f5f commit c08f1c0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/session/DeputyRootSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,11 @@ export default class DeputyRootSession {
}
await casePage.addActiveSection( sectionId );

heading.insertAdjacentElement( 'afterend', el.render() );
if ( heading.parentElement.classList.contains( 'mw-heading' ) ) {
heading.parentElement.insertAdjacentElement( 'afterend', el.render() );
} else {
heading.insertAdjacentElement( 'afterend', el.render() );
}
await el.loadData();
mw.hook( 'deputy.load.cci.session' ).fire();

Expand Down
15 changes: 13 additions & 2 deletions src/ui/root/DeputyContributionSurveySection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
for ( let i = 0; i < this.originalList.children.length; i++ ) {
const li = this.originalList.children.item( i );
if ( li.tagName !== 'LI' ) {
return false;
// Skip this element.
continue;
}
const anchor: HTMLElement = li.querySelector( 'a:first-of-type' );
// Avoid enlisting if the anchor can't be found (invalid row).
Expand Down Expand Up @@ -559,7 +560,17 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
this._section = null;
await this.getSection( Object.assign( wikitext, { revid } ) );
await this.prepare();
heading.insertAdjacentElement( 'afterend', this.render() );
if ( heading.parentElement.classList.contains( 'mw-heading' ) ) {
// Intentional recursive call
heading.parentElement.insertAdjacentElement(
'afterend', this.render()
);
} else {
// Intentional recursive call
heading.insertAdjacentElement(
'afterend', this.render()
);
}
// Run this asynchronously.
setTimeout( this.loadData.bind( this ), 0 );
}
Expand Down
11 changes: 9 additions & 2 deletions src/wiki/DeputyCasePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ export default class DeputyCasePage extends DeputyCase {
isContributionSurveyHeading( el: HTMLElement ): el is ContributionSurveyHeading {
// All headings (h1, h2, h3, h4, h5, h6)
// TODO: l10n
const headlineElement = this.parsoid ? el : el.querySelector<HTMLElement>( '.mw-headline' );
return /^H\d$/.test( el.tagName ) &&
const headlineElement = this.parsoid ?
el :
el.querySelector<HTMLElement>( '.mw-headline' );
// Handle DiscussionTools case (.mw-heading)
return ( el.classList.contains( 'mw-heading' ) || /^H\d$/.test( el.tagName ) ) &&
headlineElement != null &&
/(Page|Article|Local file|File)s? \d+ (to|through) \d+$/.test( headlineElement.innerText );
}
Expand Down Expand Up @@ -223,6 +226,10 @@ export default class DeputyCasePage extends DeputyCase {
sectionHeading = sectionHeading.parentElement;
}
}
// When DiscussionTools is being used, the header is wrapped in a div.
if ( sectionHeading.parentElement.classList.contains( 'mw-heading' ) ) {
sectionHeading = sectionHeading.parentElement;
}

const sectionMembers: HTMLElement[] = [];

Expand Down

0 comments on commit c08f1c0

Please sign in to comment.