ironmansoftware / powershell-universal

Issue tracker for PowerShell Universal
https://powershelluniversal.com
35 stars 3 forks source link

UDStepper: -DisablePrevious gets reset when you proceed and then go back #2019

Closed donlent closed 1 year ago

donlent commented 1 year ago

Steps to Reproduce

Here's a fully functional code that demonstrates the issue. I think that when a step gets disabled, because of a Validation Condition met, then the stepper should "remember" that and not allow to jump into a step that you don't want...

New-UDDashboard -Title 'PowerShell Universal' -DefaultTheme Dark -DisableThemeToggle -Pages @(

    New-UDPage -Icon (New-UDIcon -Icon 'MailBulk') -Name 'TestStepper'  -Content {

        New-UDStepper -Id "stepper" -Steps {
            New-UDStep -OnLoad {
                New-UDElement -Tag 'h3' -Content { "Normal Step" }

            } -Label "Step 1"

            New-UDStep -OnLoad {

                New-UDElement -Tag 'h3' -Content { "This Step will jump to Step 4..." }

            } -Label "Step 2"

            New-UDStep -OnLoad {

                New-UDElement -Tag 'h3' -Content { "You should never see this step... :-)" }

            } -Label "Step 3"

            New-UDStep -OnLoad {

                New-UDElement -Tag 'h3' -Content { "At first jump the BACK Button will be disabled... But when you click next and goto Step 5...." }

            } -Label "Step 4"

            New-UDStep -OnLoad {

                New-UDElement -Tag 'h3' -Content { "...and press BACK again, the previously disabled BACK button is active again... " }

            } -Label "Step 5"

        } -OnFinish {

            New-UDIcon -Icon 'ThumbsUp' -Beat -Size 10x

            New-UDElement -Id "finalMessage" -Tag 'h1' -Content { 

            } 

        } -OnValidateStep {

            $bodyJSON = $Body | ConvertFrom-Json

            if ($EventData.currentStep -eq 1) {
                New-UDValidationResult -Valid -ActiveStep 3 -DisablePrevious
            }
            else {
                New-UDValidationResult -Valid

            } 

        }
    } 
)

Expected behavior

The DisablePrevious condition should be remembered

Actual behavior

The DisablePrevious is only valid for the "current" step and not when you return into a step by pressing BACK from another Step...

Environment data

3.7.9

Visuals

No response

donlent commented 1 year ago

@adamdriscoll as always thanks a lot for taking care of that in the next milestone. :-D Additional Information which hopefully could help resolving this issue in a more clean way: I think remembering only the -DisablePrevious setting is maybe not enough. You should also remember the "OriginatingStep". Let's say somebody will just jump from step 1 to 4 but does not disable the previous button... when you click back you should be transported back to the originating step and not to via step 3 and 2... and this even if you continue to step 5, 6, ... whenever you go back and reach step 4 again, from that moment when he hits the back button he should always jump to step 1...

adamdriscoll commented 1 year ago

@donlent I'm still looking into this, but this has to be my favorite example for a bug ever haha. Thanks. It makes it much easier.

donlent commented 1 year ago

Hey @adamdriscoll 🀣 really, you probably don't even know how much I do appreciate your work and efforts that you put in your already so great product (I really mean it! ;-) ) So thanks a lot!!! πŸ™Really looking forward to the (hopefully πŸ˜…) solution to that.

Ps. If you ever step-by in Switzerland PLEASE let me know so that we can arrange something and at least invite you for a lunch or so... πŸ€—

mattselle commented 1 year ago

First awesome repro steps thank you. We ended up adding -DisablePrevious to the New-UDStep since the onvalidatestep logic only is looking at the next step and not back. Having the switch on the step itself will help you lock the step down and not have to have login in validation for it. This is currently in the 3.8 branch

donlent commented 1 year ago

Hey @mattselle Thanks to you mate! Really appreciate your efforts that you put on this one and I'm certainly happy with your solution. πŸ‘ŒπŸ˜Š At least it won't break the logic anymore now... The second suggestion was just to make it even more "flawless" if you want but it's certainly not necessary... πŸ˜‰

Ps. My invitation for a lunch is obviusly also valid for you! πŸ€— THANKS!!!

donlent commented 1 year ago

Hi @mattselle I finally had the possibility to test this new feature in 3.8. Thanks a lot. This actually works but it implicitly limits me if I have other steps that would require the ability to go back. Means, that if I disable the step itself, no matter which step I used orinally, once I reach the one that has this property set, it won't allow me to go back.

So I'm asking you for a little improvement if possible. Could you please add the possibility to use Set-UDElement on a Step as well? This seems to not be possible right now.. But what I would like to do is this:

I'd like to perform the following inside of the OnValidateStep:

Set-UDElement -Id 'myStep' -Properties @{
                    DisablePrevious = $true
                }

If I can do that after having checked that the CurrentStep is xyz, then I'm fine... Like that the "DisablePrevious" only gets applied when a particular Validation condition is met.

Does this make sense? :-)

Would really be awesome!

Thanks a lot for your efforts!!

Best regards, Don

donlent commented 1 year ago

Dear @adamdriscoll, @mattselle Do you prefer that I open a new issue for this? Maybe it's easier for you to keep track instead of reopening closed issues? Thanks in advance!

mattselle commented 1 year ago

Let's open a new one for the Set-UDElement