Product: PowerShell Universal
Version: 5.4.4
So for starters, I am consulting the docs listed here
I am trying to create a dashboard for displaying logs which are aggregated by the workflow they are a part of. The user can select by workflow ID, and then expand the table to view the logs. I want the individual logs table to highlight rows where the “type” property is ‘Warn’ or ‘Error’. Here is my code block below.
According to the docs, I think this should be right. The only difference is that my table is already nested inside of a -OnRowExpand parameter. Any help is appreciated! There is more code than what I posted, but this should be all that is relevant, I think.
Thanks!
# Define table columns
$MainColumns = @(
New-UDTableColumn -Property 'minTimestamp' -Title 'Start Time' -DefaultSortColumn
New-UDTableColumn -Property 'maxTimestamp' -Title 'End Time'
New-UDTableColumn -Property 'elapsedTime' -Title 'Elapsed Time'
New-UDTableColumn -Property 'workflow_name' -Title 'Workflow Name' -Filter -FilterType AutoComplete
New-UDTableColumn -Property 'workflow_run_id' -Title 'Workflow Run ID' -Filter -FilterType AutoComplete
New-UDTableColumn -Property 'logCount' -Title 'Log Count'
New-UDTableColumn -Property 'containsErrors' -Title 'Contains Error' -Filter -FilterType AutoComplete
)
# Draw table
New-UDTable -Data $indexedLogs.Values -Columns $MainColumns -DefaultSortDirection descending -Id 'workflows_table' -ShowSort -Paging -PageSize 100 -OnRowExpand {
$LogsColumns = @(
New-UDTableColumn -Property 'date_time' -Title 'Timestamp' -IncludeInExport -DefaultSortColumn
New-UDTableColumn -Property 'workflow_name' -Title 'Workflow Name' -Hidden -IncludeInExport
New-UDTableColumn -Property 'workflow_run_id' -Title 'Workflow Run ID' -Hidden -IncludeInExport
New-UDTableColumn -Property 'job' -Title 'Job' -IncludeInExport
New-UDTableColumn -Property 'type' -Title 'Type' -IncludeInExport
New-UDTableColumn -Property 'terminating' -Title 'Terminating' -IncludeInExport
New-UDTableColumn -Property 'step' -Title 'Step' -IncludeInExport
New-UDTableColumn -Property 'username' -Title 'Username' -Hidden -IncludeInExport
New-UDTableColumn -Property 'attempt' -Title 'Attempt' -IncludeInExport
New-UDTableColumn -Property 'outcome' -Title 'Outcome' -IncludeInExport
)
New-UDTable -Data $EventData.logs -Columns $LogsColumns -Id 'logs_table' -DefaultSortDirection ascending -ShowSort -Export -OnRowStyle {
if ($_.type -eq 'Warn') {
@{
backgroundColor = 'Yellow'
}
}
}
}
Hi,
I tried this with the following code:
$InnerData = @(
@{Dessert = 'Frozen yoghurt'; Calories = 159; Fat = 6.0; Carbs = 1; Protein = 4.0 }
@{Dessert = 'Ice cream sandwich'; Calories = 159; Fat = 150.0; Carbs = 34; Protein = 4.0 }
@{Dessert = 'Eclair'; Calories = 159; Fat = 100.0; Carbs = 73; Protein = 4.0 }
@{Dessert = 'Cupcake'; Calories = 159; Fat = 30.0; Carbs = 25; Protein = 4.0 }
@{Dessert = 'Gingerbread'; Calories = 159; Fat = 6.0; Carbs = 99; Protein = 4.0 }
)
$Data = @(
@{ Food = $InnerData }
)
$MainColumns = @(
New-UDTableColumn -Property Food -Title "Food"
)
New-UDTable -Data $Data -Id "mainTable" -Columns $MainColumns -OnRowExpand {
$InnerColumns = @(
New-UDTableColumn -Property Dessert -Title "Dessert"
New-UDTableColumn -Property Calories -Title "Calories"
New-UDTableColumn -Property Fat -Title "Fat"
New-UDTableColumn -Property Carbs -Title "Carbs" -DefaultSortColumn
New-UDTableColumn -Property Protein -Title "Protein"
)
New-UDTable -Data $EventData.Food -Id 'innerTable' -Columns $InnerColumns -OnRowStyle {
if ($EventData.Fat -lt 10) { $Color = 'green' }
elseif ($EventData.Fat -ge 10 -and $EventData.Fat -lt 50) { $Color = 'Yellow' }
else { $Color = 'Red' }
@{ backgroundColor = $Color }
}
}
and you need to switch $_ to $EventData in your inner table and it should work
1 Like
Ah, thank you for commenting! I had tried using both $_ and $EventData with no luck, but now I see you’re right. However, in this section below, I noticed that when I set the else condition color to something other than null, all the rows change color. So the $EventData reference is definitely correct, but $EventData.type must be incorrectly referenced. I guess because the individual data points are inside the $EventData.logs array, which is why I thought maybe $_ would be the correct way…
New-UDTable -Data $EventData.logs -Columns $LogsColumns -Id 'logs_table' -DefaultSortDirection ascending -ShowSort -Export -OnRowStyle {
if ($EventData.type -eq 'Error') { $Color = 'Red' }
elseif ($EventData.type -eq 'Warning') { $Color = 'Yellow' }
else { $Color = $null }
backgroundColor = $Color }
}
EDIT:
Ah! Okay so (I wish PSU had a console.log equivalent) I was able to output the value of $EventData to see what $EventData.type is outputting. Sure enough, it is not outputting $EventData as an index of $EventData.logs. Instead, it is still working within the context of the first table’s $EventData value.
For example, if I add the following typography line, it outputs correctly only if I reference an item index. So it is not currently iterating through the array normally… Which is fine, as long as I have a way to code around it. Given this function, I’m not sure what that would be.
# Draw table
New-UDTable -Data $indexedLogs.Values -Columns $MainColumns -DefaultSortDirection descending -Id 'workflows_table' -ShowRefresh -ShowSort -Paging -PageSize 100 -OnRowExpand {
$LogsColumns = @(
New-UDTableColumn -Property 'date_time' -Title 'Timestamp' -IncludeInExport -DefaultSortColumn
New-UDTableColumn -Property 'workflow_name' -Title 'Workflow Name' -Hidden -IncludeInExport
New-UDTableColumn -Property 'workflow_run_id' -Title 'Workflow Run ID' -Hidden -IncludeInExport
New-UDTableColumn -Property 'job' -Title 'Job' -IncludeInExport
New-UDTableColumn -Property 'type' -Title 'Type' -IncludeInExport
New-UDTableColumn -Property 'terminating' -Title 'Terminating' -IncludeInExport
New-UDTableColumn -Property 'step' -Title 'Step' -IncludeInExport
New-UDTableColumn -Property 'username' -Title 'Username' -Hidden -IncludeInExport
New-UDTableColumn -Property 'attempt' -Title 'Attempt' -IncludeInExport
New-UDTableColumn -Property 'outcome' -Title 'Outcome' -IncludeInExport
)
New-UDTable -Data $EventData.logs -Columns $LogsColumns -Id 'logs_table' -DefaultSortDirection ascending -ShowSort -Export -OnRowStyle {
if ($EventData.Type -eq 'Error') { $Color = 'Red' }
elseif ($EventData.Type -eq 'Warn') { $Color = 'Yellow' }
else { $Color = $null }
@{ backgroundColor = $Color }
}
New-UDTypography -Text $EventData.logs[1].type -Variant "h1" -Id "typography1"
}