Merge "[refactor] groupInput takes narrower parameters"

This commit is contained in:
jenkins-bot 2024-08-28 08:09:55 +00:00 committed by Gerrit Code Review
commit 179e12f4ec
4 changed files with 9 additions and 9 deletions

View file

@ -200,7 +200,8 @@ ve.ui.MWReferenceEditPanel.static.getImportRules = function () {
*/
ve.ui.MWReferenceEditPanel.prototype.setInternalList = function ( internalList ) {
this.internalList = internalList;
this.referenceGroupInput.populateMenu( this.internalList );
const docRefs = ve.dm.MWDocumentReferences.static.refsForDoc( internalList.getDocument() );
this.referenceGroupInput.populateMenu( docRefs.getAllGroupNames() );
};
/**

View file

@ -38,18 +38,18 @@ OO.inheritClass( ve.ui.MWReferenceGroupInputWidget, OO.ui.ComboBoxInputWidget );
/**
* Populate the reference group menu
*
* @param {ve.dm.InternalList} internalList Internal list with which to populate the menu
* @param {string[]} groups Group names
*/
ve.ui.MWReferenceGroupInputWidget.prototype.populateMenu = function ( internalList ) {
ve.ui.MWReferenceGroupInputWidget.prototype.populateMenu = function ( groups ) {
const items = [ new OO.ui.MenuOptionWidget( {
data: '',
label: this.emptyGroupName
} ) ];
for ( const groupName in internalList.getNodeGroups() ) {
groups.forEach( ( groupName ) => {
const match = groupName.match( /^mwReference\/(.+)/ );
if ( match ) {
items.push( new OO.ui.MenuOptionWidget( { data: match[ 1 ], label: match[ 1 ] } ) );
}
}
} );
this.menu.clearItems().addItems( items ).toggle( false );
};

View file

@ -168,7 +168,8 @@ ve.ui.MWReferencesListDialog.prototype.getSetupProcess = function ( data ) {
}
this.groupInput.setValue( this.selectedNode.getAttribute( 'refGroup' ) );
this.groupInput.populateMenu( this.getFragment().getDocument().getInternalList() );
const docRefs = ve.dm.MWDocumentReferences.static.refsForDoc( this.getFragment().getDocument() );
this.groupInput.populateMenu( docRefs.getAllGroupNames() );
this.responsiveCheckbox.setSelected( this.selectedNode.getAttribute( 'isResponsive' ) );

View file

@ -11,12 +11,10 @@ QUnit.test( 'Constructor', ( assert ) => {
} );
QUnit.test( 'populateMenu', ( assert ) => {
const doc = ve.dm.citeExample.createExampleDocument( 'references' );
const widget = new ve.ui.MWReferenceGroupInputWidget( {
emptyGroupName: 'empty'
} );
widget.populateMenu( doc.getInternalList() );
widget.populateMenu( [ 'mwReference/', 'mwReference/foo' ] );
assert.strictEqual( widget.getMenu().getItemCount(), 2 );