ManageIQ / ui-components

Angular UI Components for ManageIQ
Apache License 2.0
16 stars 52 forks source link

dialog-user: fix integer dropdown 0 default_value handling #430

Closed himdel closed 5 years ago

himdel commented 5 years ago

Have a dropdown with integer data_type, have the values set so that one value is 0, select that value as default value. (in dialog editor or the dialog field yaml)

Loading the dialog, default_value: '0' comes from the server, DialogData#setDefaultValue converts it to numeric 0, based on the data type, but when it gets called again, the numeric 0 fails a falsy check, and the first option in the list gets used instead.

Adding a data_type === 'integer', default_value === 0 exception to the falsy check.

(A better but also much larger fix would be to refactor dialog user so that setDefaultValue never gets called twice on the same data.)

Before:

numReq old 0 string
       new 0 number
numOpt old 0 string
       new 0 number
strReq old 0 string
       new 0 string
strOpt old 0 string
       new 0 string
numReq old 0 number
       new 1 number
numOpt old 0 number
       new null object
strReq old 0 string
       new 0 string
strOpt old 0 string
       new 0 string

Now:

numReq old 0 string
       new 0 number
numOpt old 0 string
       new 0 number
strReq old 0 string
       new 0 string
strOpt old 0 string
       new 0 string
numReq old 0 number
       new 0 number
numOpt old 0 number
       new 0 number
strReq old 0 string
       new 0 string
strOpt old 0 string
       new 0 string

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1757888

simaishi commented 4 years ago

Hammer backport details:

$ git log -1
commit 9fae6ca38c0d845d67dcffa2cb712e482b3f9dbc
Author: Martin Povolny <mpovolny@redhat.com>
Date:   Mon Dec 2 14:11:26 2019 +0100

    Merge pull request #430 from himdel/bz1757888

    dialog-user: fix integer dropdown 0 default_value handling
    (cherry picked from commit 0a1de7d6694bb6f49aa6631124b0b193c38f4bcd)

    https://bugzilla.redhat.com/show_bug.cgi?id=1783377
simaishi commented 4 years ago

Ivanchuk backport details:

$ git log -1
Satoes-MacBook-Pro:ui-components simaishi (ivanchuk) $ git logb
commit 2d49420c2fbaf6a291f32095f2c1da3b98aaf6c3
Author: Martin Povolny <mpovolny@redhat.com>
Date:   Mon Dec 2 14:11:26 2019 +0100

    Merge pull request #430 from himdel/bz1757888

    dialog-user: fix integer dropdown 0 default_value handling
    (cherry picked from commit 0a1de7d6694bb6f49aa6631124b0b193c38f4bcd)

    https://bugzilla.redhat.com/show_bug.cgi?id=1783375