Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foreach breaks UDMuButton #947

Closed
timd19 opened this issue Jul 6, 2019 · 11 comments
Closed

Foreach breaks UDMuButton #947

timd19 opened this issue Jul 6, 2019 · 11 comments
Labels
bug Something isn't working

Comments

@timd19
Copy link

timd19 commented Jul 6, 2019

I am converting some of my UD buttons to Material buttons and found that for the OnClick events that have foreach loops I get the JSON output of the button on the page instead of the Material UI button.
image

But If I remove the foreach loop from the scriptblock the button loads fine.

image

The button and foreach work as expected when using New-UDButton.

Thanks!

@adamdriscoll adamdriscoll added the bug Something isn't working label Jul 6, 2019
@AlonGvili
Copy link
Contributor

AlonGvili commented Jul 6, 2019

@mylabonline can you give me some code example

Sent from my P20 Pro using FastHub

maybe i don't understand you i just check does 2 simple examples, and they work.

                New-UDMuButton -Text DEMO -Variant flat -Size large -OnClick {
                    0..20 | ForEach-Object {
                        Show-UDToast -Message $_
                    }
                }
                New-UDMuButton -Text DEMO2 -Variant flat -Size large -OnClick {
                    foreach($n in 0..20){
                        Show-UDToast -Message $n
                    }
                }

@timd19
Copy link
Author

timd19 commented Jul 6, 2019

I used your example above in a new page and it did work but only when using a static page (-Content) when using a dynamic page the JSON output is displayed.

Working with static page

New-UDPage -Name "test" -Content {
        New-UDColumn -Endpoint {
            New-UDMuButton -Text DEMO -Variant flat -Size large -OnClick {
                            0..20 | ForEach-Object {
                                Show-UDToast -Message $_
                            }
                        }
                        New-UDMuButton -Text DEMO2 -Variant flat -Size large -OnClick {
                            foreach($n in 0..20){
                                Show-UDToast -Message $n
                            }
                        }
                    }
}

image

Not working with Dynamic Page - But if you change the UDMUButton to a UDButton it works, and if you remove the foreach from the MuButton it also loads.

Im running UD 2.5.2 btw :)

New-UDPage -Url "/test/:dynamicpage" -Endpoint {
    param($dynamicpage)
        New-UDColumn -Endpoint {
            New-UDMuButton -Text DEMO -Variant flat -Size large -OnClick {
                            0..20 | ForEach-Object {
                                Show-UDToast -Message $_
                            }
                        }
                        New-UDMuButton -Text DEMO2 -Variant flat -Size large -OnClick {
                            foreach($n in 0..20){
                                Show-UDToast -Message $n
                            }
                        }
                    }

}

image

@AlonGvili
Copy link
Contributor

AlonGvili commented Jul 6, 2019

I used your example above in a new page and it did work but only when using a static page (-Content) when using a dynamic page the JSON output is displayed.

Working with static page

New-UDPage -Name "test" -Content {
        New-UDColumn -Endpoint {
            New-UDMuButton -Text DEMO -Variant flat -Size large -OnClick {
                            0..20 | ForEach-Object {
                                Show-UDToast -Message $_
                            }
                        }
                        New-UDMuButton -Text DEMO2 -Variant flat -Size large -OnClick {
                            foreach($n in 0..20){
                                Show-UDToast -Message $n
                            }
                        }
                    }
}

image

Not working with Dynamic Page - But if you change the UDMUButton to a UDButton it works, and if you remove the foreach from the MuButton it also loads.

Im running UD 2.5.2 btw :)

New-UDPage -Url "/test/:dynamicpage" -Endpoint {
    param($dynamicpage)
        New-UDColumn -Endpoint {
            New-UDMuButton -Text DEMO -Variant flat -Size large -OnClick {
                            0..20 | ForEach-Object {
                                Show-UDToast -Message $_
                            }
                        }
                        New-UDMuButton -Text DEMO2 -Variant flat -Size large -OnClick {
                            foreach($n in 0..20){
                                Show-UDToast -Message $n
                            }
                        }
                    }

}

image

thanks for the examples will check that out

So i take your example page and it working for me.
i can't reproduce your error , can you give me a copy of you page code with all the things you trying to do ?

Jul 6 2019 10_45 PM

@timd19
Copy link
Author

timd19 commented Jul 7, 2019

@AlonGvili I found the issue - I pulled apart my entire UD and found that on the main dashboard.ps1 I am pulling in all the pages dynamically using this

 $Pages = Get-ChildItem (Join-Path $PSScriptRoot 'pages') -Recurse -File | ForEach-Object {
        & $_.FullName
     } 

But now if I take out that line of code and specify the pages individually, the MUButton works as expected in the above example, but all my dynamic content like $Session:Variables and loaders no longer work..... 👎

$Pages = @()
$Pages += . (Join-Path $PSScriptRoot "pages\user-settings.ps1")

Looks like if I want to use the new Material Buttons I will need to redesign my entire UD

@AlonGvili
Copy link
Contributor

AlonGvili commented Jul 7, 2019

$Pages = Get-ChildItem (Join-Path $PSScriptRoot 'pages') -Recurse -File | ForEach-Object {
& $_.FullName
}

try to change the & to . ,
i think maybe the scope and the session state is the problem, & sign will create new scope and session state, . sign will not create new scope and import to the same session state

 $Pages = Get-ChildItem (Join-Path $PSScriptRoot 'pages') -Recurse -File | ForEach-Object {
        . $_.FullName
     } 

we try very hard that if you using the new materialUI components you do not need to change your dashboard code.

try the above code and let me know

@timd19
Copy link
Author

timd19 commented Jul 8, 2019

@AlonGvili When changing the & to a . makes no difference. Its something with the foreach loop - see below reproduce steps. I have also put this into an Azure Web app so you can see the output (broken)- https://udtestsiteazure252.azurewebsites.net/test/test

I created a brand new UD with this test page as the only page and I'm getting the same results.

dashboard.ps1

Get-UDDashboard | Stop-UDDashboard
$Pages = Get-ChildItem (Join-Path $PSScriptRoot 'pages') -Recurse -File | ForEach-Object {
        . $_.FullName
     } 


$Dashboard = New-UDDashboard -Pages $Pages
Start-UDDashboard -AllowHttpForLogin -Dashboard $Dashboard -Wait

pages/test.ps1

New-UDPage -Url "/test/:dynamicpage" -Endpoint {
param($dynamicpage)
New-UDColumn -Endpoint {
    New-UDMuButton -Text DEMO -Variant flat -Size large -OnClick {
                    0..20 | ForEach-Object {
                        Show-UDToast -Message $_
                    }
                }
                New-UDMuButton -Text DEMO2 -Variant flat -Size large -OnClick {
                    foreach($n in 0..20){
                        Show-UDToast -Message $n
                    }
                }
            }
}

image

But if I change the $Pages variable to this it works

Get-UDDashboard | Stop-UDDashboard
$Pages = . (Join-Path $PSScriptRoot 'pages/test.ps1')


$Dashboard = New-UDDashboard -Pages $Pages
Start-UDDashboard -AllowHttpForLogin -Dashboard $Dashboard -Wait

or this

Get-UDDashboard | Stop-UDDashboard
$Pages = & (Join-Path $PSScriptRoot 'pages/test.ps1')


$Dashboard = New-UDDashboard -Pages $Pages
Start-UDDashboard -AllowHttpForLogin -Dashboard $Dashboard -Wait

image

@AlonGvili
Copy link
Contributor

I will take a look at this tonight

@AlonGvili
Copy link
Contributor

try this, I tested it and its working

$pages = foreach($page in (Get-ChildItem -Path  (Join-Path $PSScriptRoot 'pages') -Recurse )){
     . $Page.fullname
}

@timd19
Copy link
Author

timd19 commented Jul 9, 2019

@AlonGvili that did the trick!

image

For educational purposes, why does this work and not the other? All I gather is the placement of the foreach...?

thanks for all your help!! much appreciated.

@AlonGvili
Copy link
Contributor

@AlonGvili that did the trick!

image

For educational purposes, why does this work and not the other? All I gather is the placement of the foreach...?

thanks for all your help!! much appreciated.

No problem, it was fun to fix, and for your question, I'm still thinking it a scope issue but I'm not 100% sure.

i need to Dig deeper into this issue

@AlonGvili
Copy link
Contributor

If it working for you , please close this issue. thanks.

@timd19 timd19 closed this as completed Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants