controls/secretmanager-grid.ps1

function New-UDSecretManagerGrid
{
    New-UDGrid -Id "SecretsGrid" -Title "Secret Managers" -Headers @("Id", "Name", "Description","Variable","RequiredPowerShellVersion","Actions") -Properties @("Id", "Name", "Description", "Variable","RequiredPowerShellVersion","Actions") -Endpoint {

        $VariablesWithSecrets = Get-UAVariable | Where-Object {$_.SecretManager}
        
        Get-UASecretManager  | ForEach-Object {
            $SecretManager = $_
            $RelatedVariable = ($VariablesWithSecrets | Where-Object{$_.SecretManager.Id -eq $_.Id})
            
            $EditSecretManagerButton = New-UDButton -Text "" -Icon edit -OnClick {
                New-UDEditSecretManagerModal -SecretManager $SecretManager
            }

            $RemoveSecretManagerButton = New-UDButton -Text "" -Icon ban -OnClick {
                New-UDRemoveSecretManagerModal -SecretManager $SecretManager
            }

            if ($null -eq $Session:AuthorizationPolicies -or ($Session:UserRole -eq 'Administrator' -or $Session:UserRole -eq 'Operator'))
            {
                $ActionButtons =  New-UDElement -Tag div -Content{
                    New-UDTooltip -Content{$EditSecretManagerButton} -TooltipContent {"Edit Secret Manager"}
                    " "
                    New-UDTooltip -Content{$RemoveSecretManagerButton} -TooltipContent {"Delete Secret Manager"}
                }
            }
            else {
                $ActionButtons = "N/A"
            }

            if($null -eq $RelatedVariable)
            {
                $RelatedVariableCell = "N/A"
            }
            else
            {
                $RelatedVariableCell = ($RelatedVariable.Name +  " : " + $RelatedVariable.Id)
            }
            
            [PSCustomObject]@{
                Id = $_.Id
                Name = $_.Name
                Description = $_.Description
                Variable = $RelatedVariableCell
                RequiredPowerShellVersion = $_.RequiredPowerShellVersion
                Actions = $ActionButtons
            }
        } | Out-UDGridData
    } -AutoRefresh
}