controls/script-history-grid.ps1

function New-ScriptHistoryGrid 
{
    param($Script)

    New-UDGrid -Id "ScriptHistoryGrid" -Title "Commit History" -Headers @("SHA", "Author", "Message", "Timestamp", "Compare") -Properties @("SHA", "Author", "Message", "Timestamp", "Compare") -Endpoint {
        $ScriptHistory = Get-UAScriptHistory -Script $Script | Sort-Object -Property 'Timestamp' -Descending
        
        $PreviousCommit = $null
        $ScriptHistory | ForEach-Object {
            
            $Row = [PSCustomObject]@{
                Timestamp = $_.Timestamp 
                Author = $_.Author
                Message = $_.Message
                SHA = $_.CommitId
                Compare = $null
            }

            if ($null -ne $PreviousCommit)
            {
                $Row.Compare = (New-UDButton -Text "Compare with Previous" -Icon not_equal -OnClick {
                    Show-UDModal -Header { New-UDHeading -Text "Comparing: ($($_.CommitId)) -> ($($PreviousCommit.CommitId))" } -Content {
                        New-UDCodeEditor -Language powershell -ReadOnly -Height '500px' -Code $PreviousCommit.Content -Original $_.Content 
                    } -Width '95%'
                })
            }

            $Row

            $PreviousCommit = $_
        } | Out-UDGridData
    }
}