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 @@ -140,8 +140,23 @@ private static void MergeAppliesToListScalarLine(
dictionary[key] = string.IsNullOrEmpty(val) ? null : val;
}

private ApplicableTo FinalizeApplicableTo(Dictionary<string, object?> dictionary, List<(Severity, string)> diagnostics)
// TODO: remove once SharpYaml ships a release after 3.17.0 (https://github.com/elastic/docs-eng-team/issues/1236).
// SharpYaml 3.17.0 reads `{ self:, ece: ga }` as a key named `self:` (colon kept) when a comma follows the
// empty value. YAML defines it as key `self` with no value, so strip the colon or the key is dropped as unknown.
private static Dictionary<string, object?> NormalizeEmptyValueKeys(Dictionary<string, object?> dictionary)
{
var normalized = new Dictionary<string, object?>(dictionary.Comparer);
foreach (var (key, value) in dictionary)
{
var name = value is null && key.Length > 1 && key.EndsWith(':') ? key[..^1] : key;
normalized[name] = value is Dictionary<string, object?> nested ? NormalizeEmptyValueKeys(nested) : value;
}
return normalized;
}

private ApplicableTo FinalizeApplicableTo(Dictionary<string, object?> rawDictionary, List<(Severity, string)> diagnostics)
{
var dictionary = NormalizeEmptyValueKeys(rawDictionary);
var applicableTo = new ApplicableTo();

var keys = dictionary.Keys.Select(x => x.Replace('_', '-')).ToArray();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
yaml: { self:, ece: ga 4.2 }
json: [{"type":"deployment","sub_type":"self","lifecycle":"ga","version":"all"},{"type":"deployment","sub_type":"ece","lifecycle":"ga","version":"4.2\u002B"}]
text: deployment: self=all, ece=ga 4.2+,

yaml: { ess:, ece: }
json: [{"type":"deployment","sub_type":"ece","lifecycle":"ga","version":"all"},{"type":"deployment","sub_type":"ess","lifecycle":"ga","version":"all"}]
text: deployment: ece=all, ess=all

yaml: { self:, eck: }
json: [{"type":"deployment","sub_type":"self","lifecycle":"ga","version":"all"},{"type":"deployment","sub_type":"eck","lifecycle":"ga","version":"all"}]
text: deployment: self=all, eck=all

yaml: { eck:, self: }
json: [{"type":"deployment","sub_type":"self","lifecycle":"ga","version":"all"},{"type":"deployment","sub_type":"eck","lifecycle":"ga","version":"all"}]
text: deployment: self=all, eck=all

yaml: { self:, ece:, eck: }
json: [{"type":"deployment","sub_type":"self","lifecycle":"ga","version":"all"},{"type":"deployment","sub_type":"ece","lifecycle":"ga","version":"all"},{"type":"deployment","sub_type":"eck","lifecycle":"ga","version":"all"}]
text: deployment: self=all, ece=all, eck=all

yaml: { stack:, serverless: }
json: [{"type":"stack","sub_type":"stack","lifecycle":"ga","version":"all"},{"type":"serverless","sub_type":"elasticsearch","lifecycle":"ga","version":"all"},{"type":"serverless","sub_type":"observability","lifecycle":"ga","version":"all"},{"type":"serverless","sub_type":"security","lifecycle":"ga","version":"all"},{"type":"serverless","sub_type":"vectordb","lifecycle":"ga","version":"all"}]
text: stack: all, serverless: elasticsearch=all, observability=all, security=all, vectordb=all

yaml: { deployment: { self:, ece: ga 4.2 } }
json: [{"type":"deployment","sub_type":"self","lifecycle":"ga","version":"all"},{"type":"deployment","sub_type":"ece","lifecycle":"ga","version":"4.2\u002B"}]
text: deployment: self=all, ece=ga 4.2+,

yaml: { serverless: { elasticsearch:, security: ga } }
json: [{"type":"serverless","sub_type":"elasticsearch","lifecycle":"ga","version":"all"},{"type":"serverless","sub_type":"security","lifecycle":"ga"}]
text: serverless: elasticsearch=all, security=ga,
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div class="applies-switch">
<input class="applies-switch-input" checked="checked" id="applies-switch-item-2-0" name="applies-switch-set-2" type="radio" tabindex="0">
<label class="applies-switch-label" data-sync-id="applies-60843697" data-sync-group="applies-switches" for="applies-switch-item-2-0">
<span class="applies applies-item">
<applies-to-popover badge-key="ECE" badge-version="4.2+" lifecycle-class="ga" lifecycle-name="GA" show-lifecycle-name="false" show-version="true" has-multiple-lifecycles="false" popover-data="" show-popover="false" is-inline="true"></applies-to-popover>
<applies-to-popover badge-key="Self-managed" lifecycle-class="ga" lifecycle-name="GA" show-lifecycle-name="false" show-version="false" has-multiple-lifecycles="false" popover-data="" show-popover="false" is-inline="true"></applies-to-popover>
</span>
</label>
<div class="applies-switch-content" tabindex="0">
<p>Content A</p>
</div>
<input class="applies-switch-input" id="applies-switch-item-2-1" name="applies-switch-set-2" type="radio" tabindex="0">
<label class="applies-switch-label" data-sync-id="applies-B87B3D4D" data-sync-group="applies-switches" for="applies-switch-item-2-1">
<span class="applies applies-item">
<applies-to-popover badge-key="ECH" lifecycle-class="ga" lifecycle-name="GA" show-lifecycle-name="false" show-version="false" has-multiple-lifecycles="false" popover-data="" show-popover="false" is-inline="true"></applies-to-popover>
<applies-to-popover badge-key="ECE" lifecycle-class="ga" lifecycle-name="GA" show-lifecycle-name="false" show-version="false" has-multiple-lifecycles="false" popover-data="" show-popover="false" is-inline="true"></applies-to-popover>
</span>
</label>
<div class="applies-switch-content" tabindex="0">
<p>Content B</p>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,19 @@ public void Read_Sequences_MergeMappingsAndKeyValueLines() =>
"- 'deployment: ga'\n- 'deployment: beta'"
]).Should().MatchSnapshot();

[Test]
public void Read_FlowMappings_KeysWithoutAValue() =>
Table([
"{ self:, ece: ga 4.2 }",
"{ ess:, ece: }",
"{ self:, eck: }",
"{ eck:, self: }",
"{ self:, ece:, eck: }",
"{ stack:, serverless: }",
"{ deployment: { self:, ece: ga 4.2 } }",
"{ serverless: { elasticsearch:, security: ga } }"
]).Should().MatchSnapshot();

[Test]
public void Read_Stack_ValueShapes() =>
Table([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,28 @@ public void ItemIndicesAreZeroBased()
public void RendersHtml() => Html.Should().MatchHtmlSnapshot(DocsHtml.Body());
}

// Reproduces elastic/docs-builder#5007: a key with no value followed by a comma lost its badge in the tab label.
[InheritsTests]
public class ApplicabilitySwitchEmptyValueKeysTests() : DirectiveTest<AppliesSwitchBlock>(
"""
:::::{applies-switch}

::::{applies-item} { self:, ece: ga 4.2 }
Content A
::::

::::{applies-item} { ess:, ece: }
Content B
::::

:::::
"""
)
{
[Test]
public void RendersEveryBadgeInTheTabLabels() => Html.Should().MatchHtmlSnapshot(DocsHtml.Body());
}

[InheritsTests]
public class MultipleApplicabilitySwitchTests() : DirectiveTest<AppliesSwitchBlock>(
"""
Expand Down
Loading