[refactor] groupInput takes narrower parameters

Simple parameters hide knowledge and ease testing.

Change-Id: I9a8549199a1de07b437caf274c8d5e842183f570
This commit is contained in:
Adam Wight 2024-08-26 11:02:07 +02:00 committed by Awight
parent 35e8af7d40
commit b69614fc82
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 );