Merge "Hide main ref warning on orphan refs"

This commit is contained in:
jenkins-bot 2024-08-12 13:34:09 +00:00 committed by Gerrit Code Review
commit d847caf5b8
2 changed files with 28 additions and 5 deletions

View file

@ -233,10 +233,9 @@ ve.ui.MWReferenceEditPanel.prototype.updateReuseWarningFromRef = function ( ref
* @param {ve.dm.MWReferenceModel} ref * @param {ve.dm.MWReferenceModel} ref
*/ */
ve.ui.MWReferenceEditPanel.prototype.updateExtendsWarningFromRef = function ( ref ) { ve.ui.MWReferenceEditPanel.prototype.updateExtendsWarningFromRef = function ( ref ) {
if ( ref.extendsRef ) { const mainRefId = this.internalList.keys.indexOf( ref.extendsRef );
const itemNode = this.internalList.getItemNode( if ( mainRefId !== -1 ) {
this.internalList.keys.indexOf( ref.extendsRef ) const itemNode = this.internalList.getItemNode( mainRefId );
);
const $parentRefPreview = new ve.ui.MWPreviewElement( itemNode, { useView: true } ).$element; const $parentRefPreview = new ve.ui.MWPreviewElement( itemNode, { useView: true } ).$element;
this.extendsWarning.setLabel( this.extendsWarning.setLabel(
$( '<p>' ) $( '<p>' )
@ -245,7 +244,7 @@ ve.ui.MWReferenceEditPanel.prototype.updateExtendsWarningFromRef = function ( re
); );
} }
this.extendsWarning.toggle( !!ref.extendsRef ); this.extendsWarning.toggle( mainRefId !== -1 );
}; };
/** /**

View file

@ -24,3 +24,27 @@ QUnit.test( 'setReferenceForEditing', ( assert ) => {
assert.false( editPanel.reuseWarning.isVisible() ); assert.false( editPanel.reuseWarning.isVisible() );
assert.false( editPanel.extendsWarning.isVisible() ); assert.false( editPanel.extendsWarning.isVisible() );
} ); } );
QUnit.test( 'sub refs', ( assert ) => {
ve.init.target.surface = { commandRegistry: { registry: {} } };
const editPanel = new ve.ui.MWReferenceEditPanel();
const doc = ve.dm.citeExample.createExampleDocument( 'references' );
const ref = new ve.dm.MWReferenceModel( doc );
editPanel.setInternalList( doc.getInternalList() );
// does exist in the example document
ref.extendsRef = 'literal/bar';
editPanel.setReferenceForEditing( ref );
assert.false( editPanel.reuseWarning.isVisible() );
assert.true( editPanel.extendsWarning.isVisible() );
assert.true( !!editPanel.extendsWarning.getLabel().text().indexOf( 'Bar' ) );
// test sub ref with missing main ref
ref.extendsRef = 'literal/notexist';
editPanel.setReferenceForEditing( ref );
assert.false( editPanel.reuseWarning.isVisible() );
assert.false( editPanel.extendsWarning.isVisible() );
} );