Skip to content

Commit d9f056e

Browse files
authored
Improve handling empty values in GridValue (#6554)
1 parent bcfa2df commit d9f056e

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

src/Aspire.Dashboard/Components/Controls/GridValue.razor

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,23 @@
1515
else
1616
{
1717
<span class="grid-value" title="@(ToolTip ?? Value)" id="@_cellTextId">
18-
@ContentBeforeValue
19-
@if (EnableHighlighting && !string.IsNullOrEmpty(HighlightText))
18+
@if (ContentBeforeValue == null && ContentAfterValue == null && string.IsNullOrEmpty(Value))
2019
{
21-
<FluentHighlighter HighlightedText="@HighlightText" Text="@Value" />
20+
<span class="empty-data"></span>
2221
}
23-
else if (_formattedValue != null)
22+
else
2423
{
25-
@((MarkupString)_formattedValue)
26-
}
27-
@ContentAfterValue
24+
@ContentBeforeValue
25+
if (EnableHighlighting && !string.IsNullOrEmpty(HighlightText))
26+
{
27+
<FluentHighlighter HighlightedText="@HighlightText" Text="@Value" />
28+
}
29+
else if (_formattedValue != null)
30+
{
31+
@((MarkupString)_formattedValue)
32+
}
33+
@ContentAfterValue
34+
}
2835
</span>
2936
}
3037

@@ -49,18 +56,17 @@
4956
</FluentButton>
5057

5158
<FluentMenu Anchor="@_menuAnchorId" @bind-Open="_isMenuOpen" VerticalThreshold="170" HorizontalPosition="HorizontalPosition.End">
52-
<FluentMenuItem
53-
Id="@_copyId"
54-
AdditionalAttributes="@FluentUIExtensions.GetClipboardCopyAdditionalAttributes(ValueToCopy ?? Value, PreCopyToolTip, PostCopyToolTip, uncapturedCopyAttributes)">
59+
<FluentMenuItem Id="@_copyId"
60+
Disabled="@(ValueToCopy is null && Value is null)"
61+
AdditionalAttributes="@FluentUIExtensions.GetClipboardCopyAdditionalAttributes(ValueToCopy ?? Value, PreCopyToolTip, PostCopyToolTip, uncapturedCopyAttributes)">
5562
<span slot="start">
5663
<FluentIcon Style="vertical-align: text-bottom" Icon="Icons.Regular.Size16.Copy" />
5764
</span>
5865
@PreCopyToolTip
5966
</FluentMenuItem>
6067

61-
<FluentMenuItem
62-
Disabled="@(ValueToVisualize is null && Value is null)"
63-
AdditionalAttributes="@FluentUIExtensions.GetOpenTextVisualizerAdditionalAttributes(ValueToVisualize ?? Value!, !string.IsNullOrEmpty(TextVisualizerTitle) ? TextVisualizerTitle : ValueDescription)">
68+
<FluentMenuItem Disabled="@(ValueToVisualize is null && Value is null)"
69+
AdditionalAttributes="@FluentUIExtensions.GetOpenTextVisualizerAdditionalAttributes(ValueToVisualize ?? Value!, !string.IsNullOrEmpty(TextVisualizerTitle) ? TextVisualizerTitle : ValueDescription)">
6470
<span slot="start">
6571
<FluentIcon Style="vertical-align: text-bottom" Icon="Icons.Regular.Size16.Open" />
6672
</span>

src/Aspire.Dashboard/Components/Controls/PropertyGrid.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<GridValue
2424
ValueDescription="@(ValueColumnTitle ?? Loc[nameof(ControlsStrings.PropertyGridValueColumnHeader)])"
2525
Value="@context.Value"
26-
ContentAfterValue="@ContentAfterValue(context)"
26+
ContentAfterValue="@GetContentAfterValue(context)"
2727
EnableHighlighting="@(!string.IsNullOrEmpty(HighlightText))"
2828
HighlightText="@HighlightText"
2929
EnableMasking="@context.IsValueSensitive"

src/Aspire.Dashboard/Components/Controls/PropertyGrid.razor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ public partial class PropertyGrid<TItem> where TItem : IPropertyGridItem
140140
[Parameter]
141141
public GenerateHeaderOption GenerateHeader { get; set; } = GenerateHeaderOption.Sticky;
142142

143+
// Return null if empty so GridValue knows there is no template.
144+
private RenderFragment? GetContentAfterValue(TItem context) => ContentAfterValue == s_emptyChildContent
145+
? null
146+
: ContentAfterValue(context);
147+
143148
private async Task OnIsValueMaskedChanged(TItem item, bool isValueMasked)
144149
{
145150
item.IsValueMasked = isValueMasked;

0 commit comments

Comments
 (0)