PSU - Dynamic App Navigation

Product: PowerShell Universal
Version: 5.0.7

Hello,

I’m not sure if what I’m looking for is possible, but I’m trying to set up an app with multiple pages that (obviously) have different content per page. I’m setting it up like the following:

$Navigation = [System.Collections.ArrayList]@(
    New-UDListItem -Label "Home" -Icon (New-UDIcon -Icon Home) -OnClick {
        Invoke-UDRedirect -Url "/home"
    }
)

$CurrentUserRoles = (Get-PSUIdentity -Name $User).Roles

if ($CurrentUserRoles -contains "Administrator") {
    $AdminLink = New-UDListItem -Label "Admin" -Icon (New-UDIcon -Icon User) -OnClick {
            Invoke-UDRedirect -Url "/admin"
        }
    [void]($Navigation.Add($AdminLink))
}

$Pages = [System.Collections.ArrayList]@(
    Get-UDPage -Name "Home"
    Get-UDPage -Name "Admin"
)

New-UDApp -Title "New App" -Pages $Pages -Navigation $Navigation

I’d like to, as described in the code above, dynamically add a different route to a page based on the user’s access (similar to access-based enumeration on Windows server fileshare). However, while the $UserRoles variable is being resolved, the navigation bar is preloaded and only shows the Home link.

In something like React.js I know how I would approach this, but I can’t seem to find a way to update the parameters on a UDApp instance to rerender the navigation component.

Any help is appreciated!
:wavy_dash:ZG

Yeah, I’m stupid –

This works. Sorry!

1 Like