Merge "Show error message in ref edit dialog for orphaned subref"

This commit is contained in:
jenkins-bot 2024-08-23 08:02:54 +00:00 committed by Gerrit Code Review
commit 1bbae40ca5
2 changed files with 13 additions and 9 deletions

View file

@ -261,18 +261,21 @@ ve.ui.MWReferenceEditPanel.prototype.updateReuseWarningFromRef = function ( ref
* @param {ve.dm.MWReferenceModel} ref
*/
ve.ui.MWReferenceEditPanel.prototype.updateExtendsWarningFromRef = function ( ref ) {
const mainRefId = this.internalList.keys.indexOf( ref.extendsRef );
if ( mainRefId !== -1 ) {
const itemNode = this.internalList.getItemNode( mainRefId );
const $parentRefPreview = new ve.ui.MWPreviewElement( itemNode, { useView: true } ).$element;
if ( ref.extendsRef ) {
const mainRefId = this.internalList.keys.indexOf( ref.extendsRef );
this.extendsWarning.setLabel(
$( '<p>' )
.text( mw.msg( 'cite-ve-dialog-reference-editing-extends' ) )
.append( $parentRefPreview )
.append( mainRefId === -1 ?
$( '<div>' )
.addClass( 've-ui-mwReferenceContextItem-muted' )
.text( ve.msg( 'cite-ve-dialog-reference-missing-parent-ref' ) ) :
new ve.ui.MWPreviewElement( this.internalList.getItemNode( mainRefId ), { useView: true } ).$element )
);
this.extendsWarning.toggle( true );
} else {
this.extendsWarning.toggle( false );
}
this.extendsWarning.toggle( mainRefId !== -1 );
};
/**

View file

@ -46,12 +46,13 @@ QUnit.test( 'sub refs', ( assert ) => {
assert.false( editPanel.reuseWarning.isVisible() );
assert.true( editPanel.extendsWarning.isVisible() );
assert.true( !!editPanel.extendsWarning.getLabel().text().indexOf( 'Bar' ) );
assert.true( editPanel.extendsWarning.getLabel().text().indexOf( 'Bar' ) !== -1 );
// test sub ref with missing main ref
ref.extendsRef = 'literal/notexist';
editPanel.setReferenceForEditing( ref );
assert.false( editPanel.reuseWarning.isVisible() );
assert.false( editPanel.extendsWarning.isVisible() );
assert.true( editPanel.extendsWarning.isVisible() );
assert.true( editPanel.extendsWarning.getLabel().text().indexOf( 'cite-ve-dialog-reference-missing-parent-ref' ) !== -1 );
} );