controls/role-grid.ps1

function New-UARoleGrid {

    New-UDGrid -Id 'role-grid' -Title "Roles" -Headers @("Id", "Name", "Description","MemberCount","Actions") -Properties @("Id", "Name", "Description","MemberCount","Actions") -Endpoint {

        $Identities = Get-UAIdentity

        Get-UARole | ForEach-Object {
            $Role = $_
            $MemberCount = ($Identities | Where-Object {$_.Role.Id -eq $Role.Id}).Count
               
            $RoleAssignmentModal = New-UDButton -Icon users -OnClick {
                New-UDRoleAssignmentModal -Role $Role
            }

            $ActionControls = New-UDElement -Tag div -Content {
                New-UDTooltip -Content {$RoleAssignmentModal} -TooltipContent { "Add or Remove Identities to this role" }
            }

            [PSCustomObject]@{
                Id            = $_.Id
                Name          = $_.Name
                Description = $_.Description
                MemberCount = $MemberCount
                Actions       = $ActionControls
            }
        } | Out-UDGridData
    }
}