Skip to content

Commit f314105

Browse files
cci: allow archived section editing
1 parent c3aeba3 commit f314105

3 files changed

Lines changed: 72 additions & 14 deletions

File tree

i18n/core/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"deputy.session.section.closeCommentsSign": "Include my signature",
2828
"deputy.session.section.closeError": "Some revisions remain unassessed. You must mark these revisions as assessed before archiving this section.",
2929
"deputy.session.section.closeWarn": "You have unsaved changes. Close the section without saving?",
30+
"deputy.session.section.closed": "This section has been archived. You can edit its contents, but you cannot un-archive it.",
3031

3132
"deputy.session.section.stop": "Stop session",
3233
"deputy.session.section.saved": "Section saved",

src/css/deputy.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ p.dp-messageWidget-message {
138138
139139
===============================================================================
140140
*/
141+
142+
.dp-cs-section-archived .dp-cs-row-content {
143+
background-color: rgba(255, 0, 0, 6%);
144+
}
145+
141146
.dp-cs-session-notice {
142147
margin-top: 8px;
143148
position: sticky;
@@ -200,7 +205,7 @@ p.dp-messageWidget-message {
200205
margin-bottom: 0 !important;
201206
}
202207

203-
.dp-cs-row, .dp-cs-extraneous {
208+
.dp-cs-section-archived-warn, .dp-cs-row, .dp-cs-extraneous {
204209
margin-bottom: 8px;
205210
}
206211

src/ui/root/DeputyContributionSurveySection.tsx

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import DeputyMessageWidget from '../shared/DeputyMessageWidget';
2121
import sectionHeadingN from '../../wiki/util/sectionHeadingN';
2222
import changeTag from '../../config/changeTag';
2323
import DeputyExtraneousElement from './DeputyExtraneousElement';
24+
import classMix from '../../util/classMix';
2425

2526
/**
2627
* The contribution survey section UI element. This includes a list of revisions
@@ -161,9 +162,7 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
161162
}
162163

163164
if ( this.closed ) {
164-
if ( this._section.originallyClosed ) {
165-
// TODO: Fix when not broken
166-
} else {
165+
if ( !this._section.originallyClosed ) {
167166
let closingComments = ( this.comments ?? '' ).trim();
168167
if ( this.closingCommentsSign.isSelected() ) {
169168
closingComments += ' ~~~~';
@@ -179,6 +178,8 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
179178
}
180179
final.push( window.deputy.wikiConfig.cci.collapseBottom.get() );
181180
}
181+
// If the section was originally closed, don't allow the archiving
182+
// message to be edited.
182183
}
183184

184185
return final.join( '\n' );
@@ -313,14 +314,32 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
313314
* `false` if not (invalid section, already closed, etc.)
314315
*/
315316
async prepare(): Promise<boolean> {
316-
const listElements =
317+
let targetSectionNodes = this.sectionNodes;
318+
let listElements =
317319
this.sectionNodes.filter(
318320
( el ) => el instanceof HTMLElement && el.tagName === 'UL'
319321
) as HTMLUListElement[];
320322

321323
if ( listElements.length === 0 ) {
322-
// Not a valid section! Might be closed already.
323-
return false;
324+
// No list found ! Is this a valid section?
325+
// Check for a collapsible section.
326+
327+
const collapsible = ( this.sectionNodes.find(
328+
( v: HTMLElement ) =>
329+
v instanceof HTMLElement && v.querySelector( '.mw-collapsible' )
330+
) as HTMLElement | null )?.querySelector( '.mw-collapsible' ) ?? null;
331+
332+
if ( collapsible ) {
333+
// This section has a collapsible. It's possible that it's a closed section.
334+
// From here, use a different `sectionNodes` (specifically targeting all nodes
335+
// inside that collapsible), and then locate all ULs inside that collapsible.
336+
targetSectionNodes = Array.from( collapsible.childNodes );
337+
listElements = Array.from( collapsible.querySelectorAll( 'ul' ) );
338+
} else {
339+
// No collapsible found. Give up.
340+
console.warn( 'Could not find valid ULs in CCI section.', targetSectionNodes );
341+
return false;
342+
}
324343
}
325344

326345
const rowElements: Record<string, HTMLLIElement> = {};
@@ -398,7 +417,7 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
398417
// Another node exists next
399418
lastNode != null &&
400419
// The node is part of this section
401-
this.sectionNodes.includes( lastNode ) &&
420+
targetSectionNodes.includes( lastNode ) &&
402421
(
403422
// The node is not an element
404423
!( lastNode instanceof HTMLElement ) ||
@@ -409,6 +428,7 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
409428
extraneousNodes.push( lastNode );
410429
lastNode = lastNode.nextSibling;
411430
}
431+
412432
rowElement = extraneousNodes;
413433
} else {
414434
rowElement = line;
@@ -421,7 +441,12 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
421441
} else if ( Array.isArray( rowElement ) ) {
422442
// Array of Nodes
423443
this.wikitextLines.push( line );
424-
this.rowElements.push( DeputyExtraneousElement( rowElement ) );
444+
445+
if ( rowElement.length !== 0 ) {
446+
// Only append the row element if it has contents.
447+
// Otherwise, there will be a blank blue box.
448+
this.rowElements.push( DeputyExtraneousElement( rowElement ) );
449+
}
425450
} else if ( typeof rowElement === 'string' ) {
426451
this.wikitextLines.push( rowElement );
427452
}
@@ -566,9 +591,13 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
566591
* @inheritDoc
567592
*/
568593
render(): HTMLElement {
569-
this.closingCheckbox = new OO.ui.CheckboxInputWidget();
594+
this.closingCheckbox = new OO.ui.CheckboxInputWidget( {
595+
selected: this._section.originallyClosed,
596+
disabled: this._section.originallyClosed
597+
} );
570598
this.closingComments = new OO.ui.TextInputWidget( {
571599
placeholder: mw.msg( 'deputy.session.section.closeComments' ),
600+
value: this._section.closingComments,
572601
disabled: true
573602
} );
574603
this.closingCommentsSign = new OO.ui.CheckboxInputWidget( {
@@ -727,9 +756,14 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
727756
{ unwrapWidget( closingCommentsSignField ) }
728757
</div>;
729758

730-
this.toggleClosingElements( false );
731-
this.closingCheckbox.on( 'change', ( v: boolean ) => {
759+
const updateClosingFields = ( v: boolean ) => {
732760
this.closed = v;
761+
762+
if ( this._section.originallyClosed ) {
763+
// This section was originally closed. Hide everything.
764+
v = false;
765+
}
766+
733767
closingFields.style.display = v ? '' : 'none';
734768
this.toggleClosingElements( v );
735769

@@ -745,12 +779,30 @@ export default class DeputyContributionSurveySection implements DeputyUIElement
745779
row.removeEventListener( 'update', updateClosingWarning );
746780
} );
747781
}
748-
} );
782+
};
783+
this.closingCheckbox.on( 'change', updateClosingFields );
784+
updateClosingFields( this.closed );
749785
this.closingComments.on( 'change', ( v: string ) => {
750786
this.comments = v;
751787
} );
752788

753-
return this.container = <div class="deputy dp-cs-section">
789+
// Actual element
790+
791+
return this.container = <div class={ classMix(
792+
'deputy',
793+
'dp-cs-section',
794+
this._section.originallyClosed && 'dp-cs-section-archived'
795+
) }>
796+
{
797+
this._section.originallyClosed && <div class="dp-cs-section-archived-warn">
798+
{
799+
unwrapWidget( new OO.ui.MessageWidget( {
800+
type: 'warning',
801+
label: mw.msg( 'deputy.session.section.closed' )
802+
} ) )
803+
}
804+
</div>
805+
}
754806
<div>
755807
{ this.rowElements.map( ( row ) =>
756808
row instanceof HTMLElement ? row : row.render()

0 commit comments

Comments
 (0)