From ce16e4a4cb2f0c73614ba8b18adf52cab1cfb69a Mon Sep 17 00:00:00 2001 From: Adam Wight Date: Wed, 21 Aug 2024 16:57:50 +0200 Subject: [PATCH] Show error message in ref edit dialog for orphaned subref Bug: T372871 Change-Id: I2b5c99f699ac4113f90b0b22913f1b7119d1d8ce --- modules/ve-cite/ve.ui.MWReferenceEditPanel.js | 17 ++++++++++------- .../ve-cite/ve.ui.MWReferenceEditPanel.test.js | 5 +++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/modules/ve-cite/ve.ui.MWReferenceEditPanel.js b/modules/ve-cite/ve.ui.MWReferenceEditPanel.js index db7288e90..8f8e507c1 100644 --- a/modules/ve-cite/ve.ui.MWReferenceEditPanel.js +++ b/modules/ve-cite/ve.ui.MWReferenceEditPanel.js @@ -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( $( '

' ) .text( mw.msg( 'cite-ve-dialog-reference-editing-extends' ) ) - .append( $parentRefPreview ) + .append( mainRefId === -1 ? + $( '

' ) + .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 ); }; /** diff --git a/tests/qunit/ve-cite/ve.ui.MWReferenceEditPanel.test.js b/tests/qunit/ve-cite/ve.ui.MWReferenceEditPanel.test.js index 606ff3261..2291c3a66 100644 --- a/tests/qunit/ve-cite/ve.ui.MWReferenceEditPanel.test.js +++ b/tests/qunit/ve-cite/ve.ui.MWReferenceEditPanel.test.js @@ -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 ); } );