Open a file from dashboard

Hi @Jori ,
Hope you’re doing fine.
I somehow managed to work on this and got the below code but it is not fully working.
When I click edit button, I can see the drop down menu for “Region” and “Timezone” but no data is displayed unfortunately.
What is wrong with the code ?
Any help would be appreciated.

image

$AppToken = ''

#CSV file path
$Page:CSVPath = "path\test.csv"

# Define arrays for Timezone and Region
$Timezones = @("Timezone1", "Timezone2", "Timezone3")
$Regions = @("AMER", "EMEA", "APAC")

#Table where user enter information and save in a csv file
$Columns = @(
    New-UDTableColumn -Property 'fake' -Title 'Actions' -Render {

# Edit button click handler
New-UDButton -Icon (New-UDIcon -Icon Edit -Size lg) -OnClick {
    $Page:EditRow = $EventData
    $selectedTimezone = $Page:EditRow.Timezone  
    $selectedRegion = $Page:EditRow.Region     
    Show-UDModal -Content {
        New-UDForm -Children  {
            foreach ($Property in $Page:EditRow | Get-Member -MemberType NoteProperty) {
                $PropertyName = $Property.Name
                $PropertyValue = $Page:Editrow.$PropertyName

if ($PropertyName -eq "Timezone") {
    New-UDSelect -Id 'select' -Label $PropertyName -DefaultValue  $selectedTimezone {
        foreach ($Timezone in $Timezones) {
            New-UDSelectOption -Name $Timezone -Value $Timezone
        }
    }
} elseif ($PropertyName -eq "Region") {
    New-UDSelect -Id "select" -Label $PropertyName -DefaultValue $selectedRegion {
        foreach ($reg in $Regions) {
            New-UDSelectOption -Name $reg -Value $reg
        }
    }
} else {
    New-UDTextbox -Id $PropertyName -Label $PropertyName -Value $PropertyValue
}

            }
        } -OnSubmit {
            $Data = Import-Csv $Page:CSVPath
            $Row = $Data | Where-Object { $_ -match $Page:EditRow }
            $EventData | Get-Member -MemberType NoteProperty | ForEach-Object {
                $PropertyName = $_.Name
                $PropertyValue = $EventData.$PropertyName

                if ($PropertyName -eq "Timezone") {
                    $PropertyValue = ($EventData."${PropertyName}Dropdown" | Out-String).Trim()
                } elseif ($PropertyName -eq "Region") {
                    $PropertyValue = ($EventData."${PropertyName}Dropdown" | Out-String).Trim()
                }

                $Row.$PropertyName = $PropertyValue
            }
            $Data | Export-Csv $Page:CSVPath
            Sync-UDElement -Id 'idracTable' -Broadcast
            Hide-UDModal
        }
    }
}

        New-UDButton -Icon (New-UDIcon -Icon TrashCan -Size lg) -color error -OnClick {
            $Page:EditRow = $EventData
            Show-UDModal -Content {
                New-UDAlert -Severity warning -Text "YOU ARE ABOUT TO REMOVE THIS ROW."
                New-UDCheckBox -Label 'CONFIRM' -OnChange {
                    If ($Body -eq $true) {
                        $Page:ConfirmDelete = $true
                        Sync-UDElement -Id 'idracConfirmDelete'
                    }
                    elseif ($Body -eq $false) {
                        $Page:ConfirmDelete = $false
                        Sync-UDElement -Id 'idracConfirmDelete'
                    }
                }
                New-UDDynamic -Id 'idracConfirmDelete' -Content {
                    If ($Page:ConfirmDelete -eq $true) {
                        New-UDButton -Icon (New-UDIcon -Icon TrashCan -Size lg) -color error -OnClick {
                            $Data = Import-Csv $Page:CSVPath
                            $Data | Where-Object { $_ -notmatch $Page:EditRow } | Export-CSV $Page:CSVPath
                            $Page:ConfirmDelete = $false
                            Sync-UDElement -Id 'idracTable' -Broadcast
                            Hide-UDModal
                        }
                    }
                    If ($Page:ConfirmDelete -ne $true) {
                        New-UDButton -Icon (New-UDIcon -Icon TrashCan -Size lg) -color error -Disabled
                    }
                }
            }
        }
    }
    New-UDTableColumn -Property 'IdracIP'
    New-UDTableColumn -Property 'Timezone'
    New-UDTableColumn -Property 'Region'
)

New-UDTable -Id 'idracTable' -Columns $Columns -LoadData {
    $Data = Import-Csv $Page:CSVPath

    foreach ($Filter in $EventData.Filters) {
        $Data = $Data | Where-Object -Property $Filter.Id -Match -Value $Filter.Value
    }

    $TotalCount = $Data.Count 

    if (-not [string]::IsNullOrEmpty($EventData.OrderBy)) {
        $Descending = $EventData.OrderDirection -ne 'asc'
        $Data = $Data | Sort-Object -Property $EventData.orderBy -Descending:$Descending
    }
    
    $Data = $Data | Select-Object -First $EventData.PageSize -Skip ($EventData.Page * $EventData.PageSize)

    $Data | Out-UDTableData -Page $EventData.Page -TotalCount $TotalCount -Properties $EventData.Properties
} -ShowPagination -PageSize 10