Hide unused paramters by default on multipart

Covers the base functionality to hide the parameters. Performance
optimizations could be done in a follow up.

Bug: T300640
Change-Id: Ia99b5da392273f1445e475a0720a656460612dcf
This commit is contained in:
WMDE-Fisch 2022-02-03 13:30:29 +01:00
parent 29f95e78ef
commit b35ea59de5
4 changed files with 46 additions and 9 deletions

View file

@ -21,6 +21,7 @@
*
* @constructor
* @param {Object} [config] Configuration options
* @property {ve.dm.MWTransclusionModel|null} transclusionModel
*/
ve.ui.MWTemplateDialog = function VeUiMWTemplateDialog( config ) {
// Parent constructor
@ -570,6 +571,10 @@ ve.ui.MWTemplateDialog.prototype.getSetupProcess = function ( data ) {
dialog.bookletLayout.outlineSelectWidget.$element
);
dialog.bookletLayout.outlineSelectWidget.toggle( false );
if ( !dialog.transclusionModel.isSingleTemplate() ) {
dialog.pocSidebar.hideAllUnusedParameters();
}
}
dialog.bookletLayout.autoFocus = true;

View file

@ -30,7 +30,7 @@ ve.ui.MWTransclusionOutlineTemplateWidget = function VeUiMWTransclusionOutlineTe
} );
this.initializeParameterList();
this.toggleFilters();
this.toggleFilters( !this.transclusionModel.isSingleTemplate() );
};
/* Inheritance */
@ -177,7 +177,10 @@ ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onParameterAddedToTemplateMo
// All parameters known via the spec already have a checkbox
var item = this.parameterList.findItemFromData( paramName );
if ( !item ) {
if ( item ) {
// Reset the "hide unused" filter for this field, it's going to be used
item.toggle( true );
} else {
item = this.createCheckbox( paramName );
this.parameterList.addItems( [ item ], this.findCanonicalPosition( paramName ) );
@ -247,8 +250,9 @@ ve.ui.MWTransclusionOutlineTemplateWidget.prototype.onParameterWidgetListChanged
/**
* @private
* @param {boolean} [initiallyHideUnused=false]
*/
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.toggleFilters = function () {
ve.ui.MWTransclusionOutlineTemplateWidget.prototype.toggleFilters = function ( initiallyHideUnused ) {
var numParams = this.parameterList && this.parameterList.getItemCount(),
visible = numParams >= this.constructor.static.searchableParameterCount;
if ( this.searchWidget ) {
@ -256,6 +260,9 @@ ve.ui.MWTransclusionOutlineTemplateWidget.prototype.toggleFilters = function ()
this.toggleUnusedWidget.toggle( visible );
} else if ( visible ) {
this.initializeFilters();
if ( initiallyHideUnused === true ) {
this.toggleUnusedWidget.toggleUnusedParameters( false );
}
}
};
@ -338,10 +345,9 @@ ve.ui.MWTransclusionOutlineTemplateWidget.prototype.filterParameters = function
}
} );
this.toggleUnusedWidget.toggle( !query );
this.infoWidget.toggle( nothingFound );
self.emit( 'filterParametersById', visibility );
this.toggleUnusedWidget.toggle( !query );
};
/**

View file

@ -38,18 +38,33 @@ OO.inheritClass( ve.ui.MWTransclusionOutlineToggleUnusedWidget, OO.ui.ButtonWidg
/**
* Handles clicks on the button by mouse or keyboard interaction.
*
* @private
* @fires toggleUnusedFields
*/
ve.ui.MWTransclusionOutlineToggleUnusedWidget.prototype.onClick = function () {
this.showUnusedFields = !this.showUnusedFields;
this.setLabel( ve.msg( this.showUnusedFields ? 'visualeditor-dialog-transclusion-filter-hide-unused' :
'visualeditor-dialog-transclusion-filter-show-all' ) );
this.emit( 'toggleUnusedFields', this.showUnusedFields );
this.toggleUnusedParameters();
};
/**
* @param {boolean} [showUnused]
* @fires toggleUnusedFields
*/
ve.ui.MWTransclusionOutlineToggleUnusedWidget.prototype.toggleUnusedParameters = function ( showUnused ) {
showUnused = showUnused === undefined ? !this.showUnusedFields : showUnused;
if ( showUnused !== this.showUnusedFields ) {
this.showUnusedFields = showUnused;
this.setLabel( ve.msg( this.showUnusedFields ?
'visualeditor-dialog-transclusion-filter-hide-unused' :
'visualeditor-dialog-transclusion-filter-show-all'
) );
this.emit( 'toggleUnusedFields', this.showUnusedFields );
}
};
/**
* Handles toggling the visibility of the button.
*
* @private
* @param {boolean} visible
* @fires toggleUnusedFields
*/

View file

@ -127,6 +127,17 @@ ve.ui.MWTransclusionOutlineWidget.prototype.addPartWidget = function ( part, new
}
};
ve.ui.MWTransclusionOutlineWidget.prototype.hideAllUnusedParameters = function () {
for ( var id in this.partWidgets ) {
var partWidget = this.partWidgets[ id ];
if ( partWidget instanceof ve.ui.MWTransclusionOutlineTemplateWidget &&
partWidget.toggleUnusedWidget
) {
partWidget.toggleUnusedWidget.toggleUnusedParameters( false );
}
}
};
/**
* This is inspired by {@see OO.ui.SelectWidget.selectItem}, but isn't one.
*