Merge "Hide parameter search when there are only 3 params"

This commit is contained in:
jenkins-bot 2022-01-21 14:18:41 +00:00 committed by Gerrit Code Review
commit c37d6f86e8
2 changed files with 21 additions and 16 deletions

View file

@ -4,7 +4,7 @@ QUnit.test( 'Constructor', ( assert ) => {
const transclusion = new ve.dm.MWTransclusionModel(),
template = ve.dm.MWTemplateModel.newFromData( transclusion, {
target: { wt: 'Example' },
params: { a: {} }
params: { 1: {}, 2: {}, 3: {}, 4: {} }
} ),
widget = new ve.ui.MWTransclusionOutlineTemplateWidget( template );
@ -71,13 +71,18 @@ QUnit.test( 'filterParameters() when it cannot find anything', ( assert ) => {
const transclusion = new ve.dm.MWTransclusionModel(),
template = ve.dm.MWTemplateModel.newFromData( transclusion, {
target: { wt: '' },
params: { a: {} }
params: { 1: {}, 2: {}, 3: {}, 4: {} }
} ),
widget = new ve.ui.MWTransclusionOutlineTemplateWidget( template );
let eventsFired = 0;
widget.connect( this, {
filterParametersById: ( visibility ) => {
assert.deepEqual( visibility, { 'part_0/a': false } );
assert.deepEqual( visibility, {
'part_0/1': false,
'part_0/2': false,
'part_0/3': false,
'part_0/4': false
} );
eventsFired++;
}
} );

View file

@ -30,7 +30,7 @@ ve.ui.MWTransclusionOutlineTemplateWidget = function VeUiMWTransclusionOutlineTe
} );
this.initializeParameterSelectWidget();
this.initializeStickyFilters();
this.toggleFilters( this.parameters && this.parameters.getItemCount() );
};
/* Inheritance */
@ -164,7 +164,6 @@ ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onParameterAddedToTemplateMo
}
this.initializeParameterSelectWidget();
this.initializeStickyFilters();
// All parameters known via the spec already have a checkbox
var item = this.parameters.findItemFromData( paramName );
@ -172,6 +171,8 @@ ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onParameterAddedToTemplateMo
item = this.createCheckbox( paramName );
this.parameters.addItems( [ item ], this.findCanonicalPosition( paramName ) );
this.toggleFilters( this.parameters.getItemCount() );
// Make sure an active filter is applied to the new checkbox as well
var filter = this.searchWidget && this.searchWidget.getValue();
if ( filter ) {
@ -239,18 +240,19 @@ ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onParameterWidgetListChanged
* @param {number} numberOfParameters
*/
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.toggleFilters = function ( numberOfParameters ) {
this.searchWidget.toggle( numberOfParameters );
this.toggleUnusedWidget.toggle( numberOfParameters );
var visible = numberOfParameters > 3;
if ( this.searchWidget ) {
this.searchWidget.toggle( visible );
this.toggleUnusedWidget.toggle( visible );
} else if ( visible ) {
this.initializeFilters();
}
};
/**
* @private
*/
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.initializeStickyFilters = function () {
if ( this.$stickyFilters || !this.parameters || !this.parameters.getItemCount() ) {
return;
}
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.initializeFilters = function () {
this.searchWidget = new OO.ui.SearchInputWidget( {
title: ve.msg( 'visualeditor-dialog-transclusion-filter-title', this.templateModel.getSpec().getLabel() ),
placeholder: ve.msg( 'visualeditor-dialog-transclusion-filter-placeholder' ),
@ -270,7 +272,7 @@ ve.ui.MWTransclusionOutlineTemplateWidget.prototype.initializeStickyFilters = fu
classes: [ 've-ui-mwTransclusionOutlineTemplateWidget-no-match' ]
} ).toggle( false );
this.$stickyFilters = $( '<div>' )
var $stickyHeader = $( '<div>' )
.addClass( 've-ui-mwTransclusionOutlineTemplateWidget-sticky' )
.append(
this.header.$element,
@ -279,11 +281,9 @@ ve.ui.MWTransclusionOutlineTemplateWidget.prototype.initializeStickyFilters = fu
);
this.$element.prepend(
this.$stickyFilters,
$stickyHeader,
this.infoWidget.$element
);
this.toggleFilters( this.parameters.getItemCount() );
};
/**