Skip to content

Commit b464ff8

Browse files
cci: add automatic diff dropdown
1 parent 4675e61 commit b464ff8

File tree

5 files changed

+62
-21
lines changed

5 files changed

+62
-21
lines changed

i18n/settings/en.json

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
"deputy.setting.user.cci.showCvLink.description": "Show a \"cv\" link next to \"cur\" and \"prev\" on revision rows. This link will only appear if this wiki is configured to use Earwig's Copyvio Detector.",
5454
"deputy.setting.user.cci.showUsername.name": "Show username",
5555
"deputy.setting.user.cci.showUsername.description": "Show the username of the user who made the edit on revision rows. This may be redundant for cases which only have one editor.",
56+
"deputy.setting.user.cci.autoShowDiff.name": "Automatically show diffs",
57+
"deputy.setting.user.cci.autoShowDiff.description": "Enabling automatic loading of diffs. Configurable with two additional options to avoid loading too much content.",
58+
"deputy.setting.user.cci.maxRevisionsToAutoShowDiff.name": "Maximum revisions to automatically show diff",
59+
"deputy.setting.user.cci.maxRevisionsToAutoShowDiff.description": "The maximum number of revisions for a given page to automatically show the diff for each revision in the main interface.",
60+
"deputy.setting.user.cci.maxSizeToAutoShowDiff.name": "Maximum size to automatically show diff",
61+
"deputy.setting.user.cci.maxSizeToAutoShowDiff.description": "The maximum size of a diff to be automatically shown, if the diff will be automatically shown (see \"Maximum revisions to automatically show diff\"). Prevents extremely large diffs from opening. Set to -1 to show regardless of size.",
5662
"deputy.setting.user.cci.forceUtc.name": "Force UTC time",
5763
"deputy.setting.user.cci.forceUtc.description": "Forces Deputy to use UTC time whenever displaying dates and times, irregardless of your system's timezone or your MediaWiki time settings.",
5864
"deputy.setting.user.cci.signingBehavior.name": "Row signing behavior",

src/config/UserConfiguration.ts

+28
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,34 @@ export default class UserConfiguration extends ConfigurationBase {
9292
type: 'checkbox'
9393
}
9494
} ),
95+
autoShowDiff: new Setting<boolean, boolean>( {
96+
defaultValue: false,
97+
displayOptions: {
98+
type: 'checkbox'
99+
}
100+
} ),
101+
maxRevisionsToAutoShowDiff: new Setting<number, number>( {
102+
defaultValue: 2,
103+
displayOptions: {
104+
type: 'number',
105+
// Force any due to self-reference
106+
disabled: ( config: any ) => !config.cci.autoShowDiff.get(),
107+
extraOptions: {
108+
min: 1
109+
}
110+
}
111+
} ),
112+
maxSizeToAutoShowDiff: new Setting<number, number>( {
113+
defaultValue: 500,
114+
displayOptions: {
115+
type: 'number',
116+
// Force any due to self-reference
117+
disabled: ( config: any ) => !config.cci.autoShowDiff.get(),
118+
extraOptions: {
119+
min: -1
120+
}
121+
}
122+
} ),
95123
forceUtc: new Setting<boolean, boolean>( {
96124
defaultValue: false,
97125
displayOptions: {

src/css/deputy.css

+5-2
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,15 @@ body.mediawiki.rtl .dp-cs-row-head > :not(:first-child):not(:last-child) {
320320
}
321321

322322
.dp-cs-rev-diff {
323-
margin: 4px 0;
324-
padding: 8px 14px;
325323
background-color: white;
326324
position: relative;
327325
}
328326

327+
.dp-cs-rev-diff--loaded {
328+
margin: 4px 0;
329+
padding: 8px 14px;
330+
}
331+
329332
.dp-cs-rev-diff--hidden {
330333
display: none;
331334
}

src/ui/root/DeputyContributionSurveyRevision.tsx

+15-18
Original file line numberDiff line numberDiff line change
@@ -223,25 +223,19 @@ export default class DeputyContributionSurveyRevision
223223
value: this.autoExpanded
224224
} );
225225

226-
const handleDiffToggle = ( active: boolean ) => {
227-
if ( !this.element ) {
228-
// Not yet mounted.
229-
return;
230-
}
231-
232-
let willLoad = true;
226+
this.diff = <div class="dp-cs-rev-diff"/> as HTMLElement;
233227

234-
if ( this.diff == null ) {
235-
this.diff = <div class="dp-cs-rev-diff"/> as HTMLElement;
236-
this.element.appendChild( this.diff );
237-
} else if ( active && this.diff.classList.contains( 'dp-cs-rev-diff--errored' ) ) {
228+
let loaded = false;
229+
const handleDiffToggle = ( active: boolean ) => {
230+
this.diffToggle.setIndicator( active ? 'up' : 'down' );
231+
if ( active && this.diff.classList.contains( 'dp-cs-rev-diff--errored' ) ) {
232+
// Remake diff panel
238233
this.diff = swapElements( this.diff, <div class="dp-cs-rev-diff"/> as HTMLElement );
239-
} else {
234+
} else if ( loaded ) {
240235
this.diff.classList.toggle( 'dp-cs-rev-diff--hidden', !active );
241-
willLoad = false;
242236
}
243237

244-
if ( active && willLoad ) {
238+
if ( active && !loaded ) {
245239
// Going active, clear the element out
246240
Array.from( this.diff.children ).forEach(
247241
( child ) => this.diff.removeChild( child )
@@ -299,14 +293,18 @@ export default class DeputyContributionSurveyRevision
299293
}
300294
} );
301295

296+
this.diff.classList.toggle( 'dp-cs-rev-diff--loaded', true );
297+
this.diff.classList.toggle( 'dp-cs-rev-diff--errored', false );
302298
this.diff.appendChild( diffTable );
299+
loaded = true;
303300
}, ( _error, errorData ) => {
304-
// Clear element out again
301+
// Clear element out again
305302
Array.from( this.diff.children ).map(
306303
( child ) => this.diff.removeChild( child )
307304
);
308305

309-
this.diff.classList.add( 'dp-cs-rev-diff--errored' );
306+
this.diff.classList.toggle( 'dp-cs-rev-diff--loaded', true );
307+
this.diff.classList.toggle( 'dp-cs-rev-diff--errored', true );
310308
this.diff.appendChild( unwrapWidget( DeputyMessageWidget( {
311309
type: 'error',
312310
message: mw.msg(
@@ -321,7 +319,6 @@ export default class DeputyContributionSurveyRevision
321319
};
322320

323321
this.diffToggle.on( 'change', ( checked: boolean ) => {
324-
this.diffToggle.setIndicator( checked ? 'up' : 'down' );
325322
handleDiffToggle( checked );
326323
} );
327324

@@ -406,7 +403,7 @@ export default class DeputyContributionSurveyRevision
406403
( this.revision as any ).missing ?
407404
this.renderMissingRevisionInfo() :
408405
this.renderRevisionInfo()
409-
)}
406+
)}{this.diff}
410407
</div> as HTMLElement;
411408
}
412409

src/ui/root/DeputyContributionSurveyRow.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,15 @@ export default class DeputyContributionSurveyRow extends EventTarget implements
626626
this.renderCommentsTextInput( this.row.comment )
627627
) );
628628

629+
const maxSize = window.deputy.config.cci.maxSizeToAutoShowDiff.get();
629630
for ( const revision of diffs.values() ) {
630-
const revisionUIEl = new DeputyContributionSurveyRevision( revision, this );
631+
const revisionUIEl = new DeputyContributionSurveyRevision(
632+
revision, this, {
633+
expanded: window.deputy.config.cci.autoShowDiff.get() &&
634+
diffs.size < window.deputy.config.cci.maxRevisionsToAutoShowDiff.get() &&
635+
( maxSize === -1 || Math.abs( revision.diffsize ) < maxSize )
636+
}
637+
);
631638

632639
revisionUIEl.addEventListener(
633640
'update',

0 commit comments

Comments
 (0)