Skip to content

Commit 4c50d7b

Browse files
authored
Fix version dropdown notice (#1381)
If there is a mapping, but was fully migrated to docs v3, say so
1 parent 469c825 commit 4c50d7b

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

src/Elastic.Documentation/Legacy/ILegacyUrlMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public record LegacyPageMapping(string RawUrl, string Version, bool Exists)
1111

1212
public interface ILegacyUrlMapper
1313
{
14-
IReadOnlyCollection<LegacyPageMapping> MapLegacyUrl(IReadOnlyCollection<string>? mappedPages);
14+
IReadOnlyCollection<LegacyPageMapping>? MapLegacyUrl(IReadOnlyCollection<string>? mappedPages);
1515
}
1616

1717
public record NoopLegacyUrlMapper : ILegacyUrlMapper

src/Elastic.Markdown/Slices/HtmlWriter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ private async Task<string> RenderLayout(MarkdownFile markdown, MarkdownDocument
110110
Features = DocumentationSet.Configuration.Features,
111111
StaticFileContentHashProvider = StaticFileContentHashProvider,
112112
ReportIssueUrl = reportUrl,
113-
CurrentVersion = legacyPages.Count > 0 ? legacyPages.ElementAt(0).Version : "9.0+",
114-
LegacyPages = legacyPages.Skip(1).ToArray(),
115-
VersionDropdownItems = VersionDrownDownItemViewModel.FromLegacyPageMappings(legacyPages.Skip(1).ToArray()),
113+
CurrentVersion = legacyPages?.Count > 0 ? legacyPages.ElementAt(0).Version : "9.0+",
114+
LegacyPages = legacyPages?.Skip(1).ToArray(),
115+
VersionDropdownItems = VersionDrownDownItemViewModel.FromLegacyPageMappings(legacyPages?.Skip(1).ToArray()),
116116
Products = allProducts
117117
});
118118
return await slice.RenderAsync(cancellationToken: ctx);

src/Elastic.Markdown/Slices/IndexViewModel.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public class IndexViewModel
3333
public required INavigationItem[] Parents { get; init; }
3434

3535
public required string NavigationHtml { get; init; }
36-
public required string? CurrentVersion { get; init; }
37-
public required LegacyPageMapping[] LegacyPages { get; init; }
38-
public required VersionDrownDownItemViewModel[] VersionDropdownItems { get; init; }
36+
public required string CurrentVersion { get; init; }
37+
public required LegacyPageMapping[]? LegacyPages { get; init; }
38+
public required VersionDrownDownItemViewModel[]? VersionDropdownItems { get; init; }
3939
public required string? UrlPathPrefix { get; init; }
4040
public required string? GithubEditUrl { get; init; }
4141
public required string? ReportIssueUrl { get; init; }
@@ -63,8 +63,12 @@ public class VersionDrownDownItemViewModel
6363
public required VersionDrownDownItemViewModel[]? Children { get; init; }
6464

6565
// This logic currently only handles one level of children. Although the model supports multiple levels, it is not currently used.
66-
public static VersionDrownDownItemViewModel[] FromLegacyPageMappings(LegacyPageMapping[] legacyPageMappings)
66+
public static VersionDrownDownItemViewModel[]? FromLegacyPageMappings(LegacyPageMapping[]? legacyPageMappings)
6767
{
68+
if (legacyPageMappings is null)
69+
{
70+
return null;
71+
}
6872
var groupedVersions = GroupByMajorVersion(legacyPageMappings);
6973
return groupedVersions.Select(m =>
7074
{

src/Elastic.Markdown/Slices/Layout/_TableOfContents.cshtml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
}
4848
</a>
4949
</li>
50-
@foreach (var legacyPage in Model.LegacyPages)
50+
@foreach (var legacyPage in Model.LegacyPages ?? [])
5151
{
5252
<li class="block">
5353
@if (legacyPage.Exists)
@@ -68,13 +68,20 @@
6868

6969
</li>
7070
}
71-
@if (Model.LegacyPages.Length == 0)
71+
@if (Model.LegacyPages is null) // This means there is no mapping because the page is new in v3
7272
{
7373
<li class="block border-t-1 border-grey-20">
7474
<div class="py-1 px-4 text-sm">
7575
There is no previous version of this page.
7676
</div>
7777
</li>
78+
} else if (Model.LegacyPages.Length == 0) // This means there is a legacy page mapping with 0 entries, which means the page was fully migrated and is also redirecting to the new system.
79+
{
80+
<li class="block border-t-1 border-grey-20">
81+
<div class="py-1 px-4 text-sm">
82+
This page was fully migrated to the current version.
83+
</div>
84+
</li>
7885
}
7986
</ul>
8087
</div>

src/Elastic.Markdown/Slices/MarkdownLayoutViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class MarkdownLayoutViewModel : GlobalLayoutViewModel
1818

1919
public required string? CurrentVersion { get; init; }
2020

21-
public required LegacyPageMapping[] LegacyPages { get; init; }
21+
public required LegacyPageMapping[]? LegacyPages { get; init; }
2222

2323
public required IReadOnlyCollection<PageTocItem> PageTocItems { get; init; }
2424

0 commit comments

Comments
 (0)