Skip to content

Commit

Permalink
Display parameter names in a structured way
Browse files Browse the repository at this point in the history
Fixes #817
  • Loading branch information
KirillOsenkov committed Sep 18, 2024
1 parent f9b61ee commit 5761346
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 11 deletions.
37 changes: 37 additions & 0 deletions src/StructuredLogViewer/themes/Generic.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,28 @@
</HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>

<HierarchicalDataTemplate DataType="{x:Type l:TaskParameterItem}"
ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal">
<Path x:Name="icon"
Data="{DynamicResource AddItemGeometry}"
VerticalAlignment="Center"
Width="14"
Height="11"
Margin="3,3,6,3"
Stroke="{DynamicResource ItemStroke}"
Fill="{DynamicResource ItemBrush}" />
<TextBlock x:Name="label" Text="Add Item " />
<TextBlock Text="{Binding Name}" />
<TextBlock x:Name="parameterName" Text="{Binding ParameterName}" Foreground="Gray" Margin="16,0,0,0" />
</StackPanel>
<HierarchicalDataTemplate.Triggers>
<DataTrigger Binding="{Binding IsSelected}" Value="False">
<Setter TargetName="label" Property="Foreground" Value="{DynamicResource AddItemStroke}" />
</DataTrigger>
</HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>

<HierarchicalDataTemplate DataType="{x:Type l:RemoveItem}"
ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal">
Expand Down Expand Up @@ -571,11 +593,26 @@
</DataTemplate.Triggers>
</DataTemplate>

<DataTemplate DataType="{x:Type l:TaskParameterProperty}">
<StackPanel Orientation="Horizontal">
<Rectangle x:Name="icon" Style="{StaticResource NodeIcon}" Stroke="{DynamicResource PropertyStroke}" Fill="{DynamicResource PropertyBrush}" />
<TextBlock x:Name="label" Text="{Binding NameAndEquals, Mode=OneTime}" />
<TextBlock Text="{Binding ShortenedValue}" />
<TextBlock x:Name="parameterName" Text="{Binding ParameterName}" Foreground="Gray" Margin="16,0,0,0" />
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsSelected}" Value="False">
<Setter TargetName="label" Property="Foreground" Value="{DynamicResource PropertyStroke}" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>

<HierarchicalDataTemplate DataType="{x:Type l:Parameter}"
ItemsSource="{Binding Children}">
<StackPanel Orientation="Horizontal">
<Rectangle x:Name="icon" Style="{StaticResource NodeIcon}" Stroke="{DynamicResource ParameterStroke}" Fill="{DynamicResource ParameterBrush}" />
<TextBlock x:Name="name" Text="{Binding Name}" />
<TextBlock x:Name="parameterName" Text="{Binding ParameterName}" Foreground="Gray" Margin="16,0,0,0" />
</StackPanel>
<HierarchicalDataTemplate.Triggers>
<DataTrigger Binding="{Binding IsSelected}" Value="False">
Expand Down
47 changes: 36 additions & 11 deletions src/StructuredLogger/Construction/MessageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,9 @@ private void ProcessTaskParameter(TaskParameterEventArgs args)
parent = task.GetOrCreateNodeWithName<Folder>(folderName);
parent.DisableChildrenCache = true;

string itemName = isOutput && parameterName is not null
? $"{propertyName ?? itemType} from parameter {parameterName}"
: propertyName ?? itemType;
string itemName = propertyName ?? itemType;

node = CreateParameterNode(itemName, items, isOutput);
node = CreateParameterNode(itemName, items, isOutput, parameterName);
}
else if (
kind == TaskParameterMessageKind.AddItem ||
Expand Down Expand Up @@ -254,26 +252,53 @@ private void ProcessTaskParameter(TaskParameterEventArgs args)
}
}

private BaseNode CreateParameterNode(string itemName, IEnumerable items, bool isOutput = false)
private BaseNode CreateParameterNode(string itemName, IEnumerable items, bool isOutput = false, string parameterName = null)
{
if (items is IList<ITaskItem> list && list.Count == 1 && list[0] is ITaskItem scalar && scalar.MetadataCount == 0)
{
var property = new Property
BaseNode property;
if (parameterName != null && parameterName != itemName)
{
Name = itemName,
Value = scalar.ItemSpec
};
property = new TaskParameterProperty
{
Name = itemName,
Value = scalar.ItemSpec,
ParameterName = parameterName
};
}
else
{
property = new Property
{
Name = itemName,
Value = scalar.ItemSpec
};
}

return property;
}

TreeNode parent;
if (isOutput)
{
parent = new AddItem { Name = itemName };
if (!string.IsNullOrEmpty(parameterName) && parameterName != itemName)
{
parent = new TaskParameterItem { Name = itemName, ParameterName = parameterName };
}
else
{
parent = new AddItem { Name = itemName };
}
}
else
{
parent = new Parameter { Name = itemName };
// no need to display the same string twice
if (parameterName == itemName)
{
parameterName = null;
}

parent = new Parameter { Name = itemName, ParameterName = parameterName };
parent.DisableChildrenCache = true;
}

Expand Down
5 changes: 5 additions & 0 deletions src/StructuredLogger/ObjectModel/AddItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ public AddItem()

public int? LineNumber { get; set; }
}

public class TaskParameterItem : AddItem
{
public string ParameterName { get; set; }
}
}
2 changes: 2 additions & 0 deletions src/StructuredLogger/ObjectModel/Parameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
public class Parameter : NamedNode
{
public override string TypeName => nameof(Parameter);

public string ParameterName { get; set; }
}
}
5 changes: 5 additions & 0 deletions src/StructuredLogger/ObjectModel/Property.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ public class Property : NameValueNode
{
public override string TypeName => nameof(Property);
}

public class TaskParameterProperty : Property
{
public string ParameterName { get; set; }
}
}

0 comments on commit 5761346

Please sign in to comment.