Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
var collapsible = variant.IsCollapsible;
var expanded = Model.UseChips || variant.DefaultExpanded;
var folded = variant.UseHidden && !Model.UseChips;
// An array variant keeps its "X[]" heading, so its fields read as each item's; a primitive keeps its type, which is
// all its panel has to show.
var showName = !Model.UseChips || variant.PageUrl is { Length: > 0 } || variant.IsArrayVariant || !variant.IsObjectType;
// An array variant keeps its "X[]" heading, so its fields read as each item's. A primitive's chip already says its
// type, so its panel shows nothing more than the description, if any.
var showName = !Model.UseChips || variant.PageUrl is { Length: > 0 } || variant.IsArrayVariant;
var showLabel = showName || variant.DiscriminatorLabel is { Length: > 0 };

<div class="union-variant-item @(variant.ShowProperties ? "has-children" : "") @(collapsible ? (expanded ? "expanded" : "collapsed") : "")" id="@variant.AnchorId" hidden="@(Model.UseChips && i > 0 ? "until-found" : null)">
Expand Down
12 changes: 8 additions & 4 deletions tests/Elastic.ApiExplorer.Tests/UnionOptionsRenderingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task Render_OneObjectAndAPrimitive_ShowChips()
.Contain("data-chip-row")
.And
.Contain("""id="v-1" hidden="until-found">""", "TotalHits or number reads like any other union");
html.Should().Contain(">Variant1</span></code>", "the primitive keeps its type name");
html.Should().NotContain(">Variant1</span></code>", "the primitive's chip already names its type");
}

[Test]
Expand All @@ -42,12 +42,16 @@ public async Task Render_TwoObjects_ShowChips()
}

[Test]
public async Task Render_PrimitiveVariantBehindChips_KeepsItsTypeName()
public async Task Render_PrimitiveVariantBehindChips_LeavesItsPanelWithoutTheTypeName()
{
// Variant2 is an array, which keeps its name anyway; Variant3 is a plain primitive.
// Variant2 is an array, which keeps its heading; Variant3 is a plain primitive.
var html = await Render(4, objects: 3);

html.Should().Contain(">Variant3</span></code>", "a primitive's type is all its panel has to show");
html.Should().NotContain(">Variant3</span></code>", "a primitive's type is on its chip");
html.Should().Contain(
">Variant2</span><span class=\"type-wrapper array-icon\">[]</span></code>",
"an array variant keeps its heading"
);
html.Should().NotContain(">Variant0</span></code>", "an object variant's name is on its chip");
}

Expand Down
Loading