Skip to content

Commit

Permalink
cci: gracefully handle pageonly rows
Browse files Browse the repository at this point in the history
  • Loading branch information
ChlodAlejandro committed Feb 11, 2024
1 parent 7db9b8e commit da8d225
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 41 deletions.
4 changes: 4 additions & 0 deletions i18n/core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
"deputy.session.row.checked.talk": "talk",
"deputy.session.row.checked.contribs": "contribs",

"deputy.session.row.pageonly": "This row does not contain any diffs. Please assess the page history manually.",

"deputy.session.revision.assessed": "Mark as assessed",
"deputy.session.revision.diff.toggle": "Toggle comparison (diff) view",
"deputy.session.revision.diff.error": "Failed to load comparison: $1",
Expand Down Expand Up @@ -93,6 +95,8 @@
"deputy.session.page.caseInfo.revision.help": "The requested revision was out of scope for the current Deputy case page. It was likely made by a user who is not a subject of the case page, or has already been removed or assessed by another user. Tools will still be available, but you will not be able to mark this revision as \"assessed\".",
"deputy.session.page.caseInfo.assessed": "Assessed?",
"deputy.session.page.caseInfo.next": "Navigate to the next unassessed revision",
"deputy.session.page.pageonly.title": "No revisions",
"deputy.session.page.pageonly.help": "This row does not contain any revisions with it. Please assess the page history manually before making an assessment.",

"deputy.session.page.analysis": "Analysis",
"deputy.session.page.earwigLatest": "Earwig's Copyvio Detector (latest)",
Expand Down
5 changes: 5 additions & 0 deletions src/DeputyCommunications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ export interface DeputyPageStatusResponseMessage {
* parameter was supplied in the request.
*/
revisionStatus?: boolean;
/**
* - `detailed` refers to a row with both page and revision information.
* - `pageonly` refers to a row with only a page and no revision information.
*/
rowType: 'detailed' | 'pageonly';
/**
* An echo of the requested revision ID. Only enabled if the `revision`
* parameter was supplied in the request.
Expand Down
5 changes: 5 additions & 0 deletions src/css/deputy.css
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@ body.mediawiki.rtl .dp-cs-row-head > :not(:first-child):not(:last-child) {
white-space: nowrap;
}

.dp-pt-section .oo-ui-popupWidget-popup {
/** Avoid preventing line breaks in popups */
white-space: initial;
}

.dp-pt-section + .dp-pt-section {
/* TODO: Recheck RTL compatibility */
margin-left: 16px;
Expand Down
6 changes: 6 additions & 0 deletions src/models/ContributionSurveyRow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ export default class ContributionSurveyRow {
};
}

/**
* - `detailed` refers to a row with both page and revision information.
* - `pageonly` refers to a row with only a page and no revision information.
*/
type: 'detailed' | 'pageonly';
/**
* The case page of this row.
*/
Expand Down Expand Up @@ -259,6 +264,7 @@ export default class ContributionSurveyRow {
constructor( casePage: DeputyCasePage, wikitext: string ) {
this.data = new ContributionSurveyRowParser( wikitext ).parse();

this.type = this.data.type;
this.casePage = casePage;
this.wikitext = wikitext;
this.title = new mw.Title( this.data.page );
Expand Down
32 changes: 28 additions & 4 deletions src/ui/page/DeputyPageToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface DeputyPageToolbarOptions extends Omit<DeputyPageStatusResponseM
export default class DeputyPageToolbar implements DeputyUIElement {

options: DeputyPageToolbarOptions;
row: { casePage: DeputyCase, title: mw.Title };
row: { casePage: DeputyCase, title: mw.Title, type: 'detailed' | 'pageonly' };

element: HTMLElement;
revisionCheckbox: OO.ui.CheckboxInputWidget;
Expand Down Expand Up @@ -92,7 +92,8 @@ export default class DeputyPageToolbar implements DeputyUIElement {
this.options.caseId,
normalizeTitle( this.options.caseTitle )
),
title: normalizeTitle( this.options.title )
title: normalizeTitle( this.options.title ),
type: this.options.rowType
};
}

Expand Down Expand Up @@ -252,6 +253,27 @@ export default class DeputyPageToolbar implements DeputyUIElement {
* @return The OOUI ButtonWidget element.
*/
renderRevisionNavigationButtons(): JSX.Element {
if ( this.row.type === 'pageonly' ) {
return <div class="dp-pt-section">
{ unwrapWidget(
new OO.ui.PopupButtonWidget( {
icon: 'info',
framed: false,
label: mw.msg( 'deputy.session.page.pageonly.title' ),
popup: {
head: true,
icon: 'infoFilled',
label: mw.msg( 'deputy.session.page.pageonly.title' ),
$content: $( <p>{
mw.msg( 'deputy.session.page.pageonly.help' )
}</p> as HTMLElement ),
padded: true
}
} )
) }
</div>;
}

const getButtonClickHandler = ( button: OO.ui.ButtonWidget, reverse: boolean ) => {
return async () => {
this.setDisabled( true );
Expand Down Expand Up @@ -374,7 +396,8 @@ export default class DeputyPageToolbar implements DeputyUIElement {
{ this.renderStatusDropdown() }
{ this.renderCaseInfo() }
{ this.renderRevisionInfo() }
{ this.revisionNavigationSection = this.renderRevisionNavigationButtons() as HTMLElement }
{ this.revisionNavigationSection =
this.renderRevisionNavigationButtons() as HTMLElement }
{ this.renderMenus() }
</div> as HTMLElement;
}
Expand Down Expand Up @@ -426,7 +449,8 @@ export default class DeputyPageToolbar implements DeputyUIElement {
// Re-render button.
swapElements(
this.revisionNavigationSection,
this.revisionNavigationSection = this.renderRevisionNavigationButtons() as HTMLElement
this.revisionNavigationSection =
this.renderRevisionNavigationButtons() as HTMLElement
);
}
}
Expand Down
78 changes: 44 additions & 34 deletions src/ui/root/DeputyContributionSurveyRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ export default class DeputyContributionSurveyRow extends EventTarget implements
'originally-unfinished row. Assuming unfinished and moving on...'
);
}
const finished = this.wasFinished ?? false;

// "* "
let result = this.row.data.bullet;
Expand Down Expand Up @@ -325,17 +324,14 @@ export default class DeputyContributionSurveyRow extends EventTarget implements
result += ' ~~~~';
};

if ( finished ) {
if ( this.statusModified ) {
// Modified. Use user data.
useUserData();
} else {
// No changes. Just append original closure comments.
result += this.row.comment;
}
} else {
if ( this.statusModified ) {
// Modified. Use user data.
useUserData();
} else if ( this.wasFinished ?? false ) {
// No changes. Just append original closure comments.
result += this.row.comment;
}
// Otherwise, leave this row unchanged.
}

return result;
Expand Down Expand Up @@ -505,9 +501,12 @@ export default class DeputyContributionSurveyRow extends EventTarget implements
}

if ( this.revisions && this.statusDropdown ) {
this.statusDropdown.setOptionDisabled(
ContributionSurveyRowStatus.Unfinished, this.completed, true
);
if ( this.row.type !== 'pageonly' ) {
// Only disable this option if the row isn't already finished.
this.statusDropdown.setOptionDisabled(
ContributionSurveyRowStatus.Unfinished, this.completed, true
);
}

const unfinishedWithStatus = this.statusModified && !this.completed;
if ( this.unfinishedMessageBox ) {
Expand Down Expand Up @@ -626,27 +625,34 @@ export default class DeputyContributionSurveyRow extends EventTarget implements
this.renderCommentsTextInput( this.row.comment )
) );

const maxSize = window.deputy.config.cci.maxSizeToAutoShowDiff.get();
for ( const revision of diffs.values() ) {
const revisionUIEl = new DeputyContributionSurveyRevision(
revision, this, {
expanded: window.deputy.config.cci.autoShowDiff.get() &&
diffs.size < window.deputy.config.cci.maxRevisionsToAutoShowDiff.get() &&
( maxSize === -1 || Math.abs( revision.diffsize ) < maxSize )
}
);
if ( this.row.type === 'pageonly' ) {
revisionList.appendChild( <div class="dp-cs-row-pageonly">
<i>{ mw.msg( 'deputy.session.row.pageonly' ) }</i>
</div> );
} else {
const cciConfig = window.deputy.config.cci;
const maxSize = cciConfig.maxSizeToAutoShowDiff.get();
for ( const revision of diffs.values() ) {
const revisionUIEl = new DeputyContributionSurveyRevision(
revision, this, {
expanded: cciConfig.autoShowDiff.get() &&
diffs.size < cciConfig.maxRevisionsToAutoShowDiff.get() &&
( maxSize === -1 || Math.abs( revision.diffsize ) < maxSize )
}
);

revisionUIEl.addEventListener(
'update',
() => {
// Recheck options first to avoid "Unfinished" being selected when done.
this.onUpdate();
}
);
revisionUIEl.addEventListener(
'update',
() => {
// Recheck options first to avoid "Unfinished" being selected when done.
this.onUpdate();
}
);

await revisionUIEl.prepare();
revisionList.appendChild( revisionUIEl.render() );
this.revisions.push( revisionUIEl );
await revisionUIEl.prepare();
revisionList.appendChild( revisionUIEl.render() );
this.revisions.push( revisionUIEl );
}
}

return revisionList;
Expand Down Expand Up @@ -793,10 +799,13 @@ export default class DeputyContributionSurveyRow extends EventTarget implements
status: possibleStatus,
requireAcknowledge: false
} );
if ( ( diffs && diffs.size === 0 ) || this.wasFinished ) {
if (
this.row.type !== 'pageonly' &&
( ( diffs && diffs.size === 0 ) || this.wasFinished )
) {
// If there are no diffs found or `this.wasFinished` is set (both meaning there are
// no diffs and this is an already-assessed row), then the "Unfinished" option will
// be disabled.
// be disabled. This does not apply for page-only rows, which never have diffs.
this.statusDropdown.setOptionDisabled( ContributionSurveyRowStatus.Unfinished, true );
}
this.statusDropdown.addEventListener( 'change', ( event ) => {
Expand Down Expand Up @@ -1005,6 +1014,7 @@ export default class DeputyContributionSurveyRow extends EventTarget implements
title: this.row.title.getPrefixedText(),
status: this.status,
enabledStatuses: this.statusDropdown.getEnabledOptions(),
rowType: this.row.type,
revisionStatus: rev ? rev.completed : undefined,
revision: event.data.revision,
nextRevision: this.revisions?.find(
Expand Down
14 changes: 11 additions & 3 deletions src/ui/shared/DeputyCCIStatusDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export default class DeputyCCIStatusDropdown extends EventTarget {
*/
row: {
casePage: DeputyCase,
title: mw.Title
title: mw.Title,
type: 'detailed' | 'pageonly'
};
/**
* The OOUI DropdownWidget element. This does <b>not</b> use DropdownInputWidget
Expand Down Expand Up @@ -101,10 +102,12 @@ export default class DeputyCCIStatusDropdown extends EventTarget {
* @param row.casePage The DeputyCase for this dropdown
* @param row.title The title of the row (page) that this dropdown accesses
* @param options Additional construction options, usually used by the root session.
* @param row.type
*/
constructor( row: {
casePage: DeputyCase,
title: mw.Title
title: mw.Title,
type: 'detailed' | 'pageonly'
}, options: DeputyCCIStatusDropdownProps = {} ) {
super();
this.row = row;
Expand Down Expand Up @@ -375,7 +378,7 @@ export default class DeputyCCIStatusDropdown extends EventTarget {
* is as follows:
*
* For
* - Unfinished: WithoutViolations
* - Unfinished: WithoutViolations, unless it's `pageonly`, on which it'll be kept as is.
* - Unknown: Unfinished
* - WithViolations: _usually not disabled, kept as is_
* - WithoutViolations: _usually not disabled, kept as is_
Expand All @@ -386,6 +389,11 @@ export default class DeputyCCIStatusDropdown extends EventTarget {
*/
selectNextBestValue( status: ContributionSurveyRowStatus ) {
if ( status === ContributionSurveyRowStatus.Unfinished ) {
if ( this.row.type === 'pageonly' ) {
// Leave it alone.
return;
}

this.status = ContributionSurveyRowStatus.WithoutViolations;
} else if ( status === ContributionSurveyRowStatus.Unknown ) {
this.status = ContributionSurveyRowStatus.Unfinished;
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/ContributionSurveyRowParserTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,25 @@ describe( 'ContributionSurveyRowParser line parsing tests', () => {
} );
} );

test( 'file link', () => {
const parser = new ContributionSurveyRowParser(
'* [[:File:Example.png]]'
);
expect( parser.parse() ).toEqual( {
type: 'pageonly',
bullet: '* ',
creation: false,
page: ':File:Example.png',
extras: null,
diffs: null,
comments: null,
revids: [ ],
revidText: {},
diffTemplate: '[[Special:Diff/$1|($2)]]',
diffsTemplate: '$1'
} );
} );

test( 'edge: pre-colon, no comment, no diffs', () => {
const parser = new ContributionSurveyRowParser(
'*[[:Example]]: (1 edit)'
Expand Down

0 comments on commit da8d225

Please sign in to comment.