Skip to content

Commit a0d3562

Browse files
authored
New version dropdown: Disable non-existing items and pass current version to react component (#1384)
* New version dropdown: Disable non-existing items and pass current version to react component * Run prettier
1 parent ca15193 commit a0d3562

File tree

8 files changed

+22
-8
lines changed

8 files changed

+22
-8
lines changed

src/Elastic.ApiExplorer/Endpoints/EndpointView.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
NavigationHtml = Model.NavigationHtml,
1414
UrlPathPrefix = null,
1515
VersionDropdown = null,
16+
CurrentVersion = null,
1617
AllowIndexing = false,
1718
CanonicalBaseUrl = null,
1819
GoogleTagManager = new GoogleTagManagerConfiguration(),

src/Elastic.ApiExplorer/Landing/LandingView.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
NavigationHtml = Model.NavigationHtml,
1414
UrlPathPrefix = null,
1515
VersionDropdown = null,
16+
CurrentVersion = "9.0+",
1617
AllowIndexing = false,
1718
CanonicalBaseUrl = null,
1819
GoogleTagManager = new GoogleTagManagerConfiguration(),

src/Elastic.ApiExplorer/Operations/OperationView.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
NavigationHtml = Model.NavigationHtml,
1414
UrlPathPrefix = null,
1515
VersionDropdown = null,
16+
CurrentVersion = null,
1617
AllowIndexing = false,
1718
CanonicalBaseUrl = null,
1819
GoogleTagManager = new GoogleTagManagerConfiguration(),

src/Elastic.Documentation.Site/Assets/web-components/VersionDropdown.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ appendIconComponentCache({
4545
type VersionDropdownItem = {
4646
name: string
4747
href?: string
48+
disabled: boolean
4849
children?: VersionDropdownItem[]
4950
}
5051

5152
type VersionDropdownProps = {
53+
currentVersion: string
5254
items: VersionDropdownItem[]
5355
}
5456

55-
const VersionDropdown = ({ items }: VersionDropdownProps) => {
57+
const VersionDropdown = ({ currentVersion, items }: VersionDropdownProps) => {
5658
const [isPopoverOpen, setPopover] = useState(false)
5759

5860
const contextMenuPopoverId = useGeneratedHtmlId({
@@ -74,6 +76,7 @@ const VersionDropdown = ({ items }: VersionDropdownProps) => {
7476
return {
7577
name: item.name,
7678
href: item.href,
79+
disabled: item.disabled,
7780
}
7881
})
7982
}
@@ -90,6 +93,7 @@ const VersionDropdown = ({ items }: VersionDropdownProps) => {
9093
title: item.name,
9194
initialFocusedItemIndex: 0,
9295
width: WIDTH,
96+
disabled: item.disabled,
9397
size: 's',
9498
items: item.children ? convertItems(item.children) : [],
9599
}
@@ -104,6 +108,7 @@ const VersionDropdown = ({ items }: VersionDropdownProps) => {
104108
name: item.name,
105109
panel: item.children?.length ? index + 1 : undefined,
106110
href: item.href,
111+
disabled: item.disabled,
107112
}
108113
})
109114

@@ -117,7 +122,9 @@ const VersionDropdown = ({ items }: VersionDropdownProps) => {
117122
<EuiFlexItem grow={0}>
118123
<EuiIcon type="check" />
119124
</EuiFlexItem>
120-
<EuiFlexItem grow={1}>Current (9.0+)</EuiFlexItem>
125+
<EuiFlexItem grow={1}>
126+
Current ({currentVersion})
127+
</EuiFlexItem>
121128
</EuiFlexGroup>
122129
),
123130
width: WIDTH,
@@ -149,7 +156,7 @@ const VersionDropdown = ({ items }: VersionDropdownProps) => {
149156
font-size: 0.875rem;
150157
`}
151158
>
152-
Current (9.0+)
159+
Current ({currentVersion})
153160
</EuiText>
154161
</EuiButton>
155162
)
@@ -174,6 +181,7 @@ customElements.define(
174181
r2wc(VersionDropdown, {
175182
props: {
176183
items: 'json',
184+
currentVersion: 'string',
177185
},
178186
})
179187
)

src/Elastic.Documentation.Site/Layout/_SecondaryNav.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@if (Model.Features.IsVersionDropdownEnabled && Model.VersionDropdown is not null)
1818
{
1919
<div id="version-dropdown">
20-
<version-dropdown items='@(new HtmlString(Model.VersionDropdown))' />
20+
<version-dropdown current-version='@(Model.CurrentVersion)' items='@(new HtmlString(Model.VersionDropdown))' />
2121
</div>
2222
}
2323
</div>

src/Elastic.Documentation.Site/_ViewModels.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class GlobalLayoutViewModel
2626
public required INavigationItem? Next { get; init; }
2727

2828
public required string? VersionDropdown { get; init; }
29+
public required string? CurrentVersion { get; init; }
2930

3031
public required string NavigationHtml { get; init; }
3132
public required string? UrlPathPrefix { get; init; }

src/Elastic.Markdown/Slices/IndexViewModel.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,17 @@ public class VersionDrownDownItemViewModel
5959
[JsonPropertyName("href")]
6060
public required string? Href { get; init; }
6161

62+
[JsonPropertyName("disabled")]
63+
public required bool IsDisabled { get; init; }
64+
6265
[JsonPropertyName("children")]
6366
public required VersionDrownDownItemViewModel[]? Children { get; init; }
6467

6568
// This logic currently only handles one level of children. Although the model supports multiple levels, it is not currently used.
6669
public static VersionDrownDownItemViewModel[]? FromLegacyPageMappings(LegacyPageMapping[]? legacyPageMappings)
6770
{
6871
if (legacyPageMappings is null)
69-
{
7072
return null;
71-
}
7273
var groupedVersions = GroupByMajorVersion(legacyPageMappings);
7374
return groupedVersions.Select(m =>
7475
{
@@ -79,10 +80,12 @@ public class VersionDrownDownItemViewModel
7980
{
8081
Name = m.Key,
8182
Href = null,
83+
IsDisabled = false,
8284
Children = m.Value.Select(v => new VersionDrownDownItemViewModel
8385
{
8486
Name = v,
8587
Href = legacyPageMappings.First(x => x.Version == v).ToString(),
88+
IsDisabled = !legacyPageMappings.First(x => x.Version == v).Exists,
8689
Children = null
8790
}).ToArray()
8891
};
@@ -95,6 +98,7 @@ public class VersionDrownDownItemViewModel
9598
{
9699
Name = legacyPageMapping.Version,
97100
Href = legacyPageMapping.ToString(),
101+
IsDisabled = !legacyPageMapping.Exists,
98102
Children = null
99103
};
100104
}).ToArray();

src/Elastic.Markdown/Slices/MarkdownLayoutViewModel.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ public class MarkdownLayoutViewModel : GlobalLayoutViewModel
1616

1717
public required INavigationItem[] Parents { get; init; }
1818

19-
public required string? CurrentVersion { get; init; }
20-
2119
public required LegacyPageMapping[]? LegacyPages { get; init; }
2220

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

0 commit comments

Comments
 (0)