From 45096d1e2f3b4c22ad34ff0276d2d369138d1536 Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Thu, 5 Aug 2021 11:08:34 +0200 Subject: [PATCH] Streamline and harden template paramter search widget behavior What this changes: * The moment the user selects anything in the parameter search widget, the input is cleared, no matter what happens next. Even in case of an error. We know the input was bad in this case. Let's get rid of it. * The method makes sure it does not even try to add a duplicate parameter. This should be unreachable, but better be safe than sorry. This is split from I5eeb973. I run into this while playing around with different approaches related to hiding deprecated parameters. Typically there should be no way the parameter search widget offers a duplicate. Still I believe it's a good idea to have this extra safety-net. Bug: T272487 Bug: T288827 Change-Id: I04e76d73b4a3f6467d0ccf3ccff5d2f6b4114bd9 --- .../ve-mw/ui/pages/ve.ui.MWParameterPlaceholderPage.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/ve-mw/ui/pages/ve.ui.MWParameterPlaceholderPage.js b/modules/ve-mw/ui/pages/ve.ui.MWParameterPlaceholderPage.js index ba04b1b6a4..9ab2c69035 100644 --- a/modules/ve-mw/ui/pages/ve.ui.MWParameterPlaceholderPage.js +++ b/modules/ve-mw/ui/pages/ve.ui.MWParameterPlaceholderPage.js @@ -105,16 +105,16 @@ ve.ui.MWParameterPlaceholderPage.prototype.setOutlineItem = function () { }; ve.ui.MWParameterPlaceholderPage.prototype.onParameterChoose = function ( name ) { - if ( !name ) { + this.addParameterSearch.query.setValue( '' ); + + if ( !name || this.template.hasParameter( name ) ) { return; } // Note that every parameter is known after it is added - var knownBefore = this.template.getSpec().isKnownParameterOrAlias( name ), - param = new ve.dm.MWParameterModel( this.template, name ); + var knownBefore = this.template.getSpec().isKnownParameterOrAlias( name ); - this.addParameterSearch.query.setValue( '' ); - this.template.addParameter( param ); + this.template.addParameter( new ve.dm.MWParameterModel( this.template, name ) ); ve.track( 'activity.transclusion', { action: knownBefore ? 'add-known-parameter' : 'add-unknown-parameter'