Skip to content

New version dropdown: Disable non-existing items and pass current version to react component #1384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/Elastic.ApiExplorer/Endpoints/EndpointView.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
NavigationHtml = Model.NavigationHtml,
UrlPathPrefix = null,
VersionDropdown = null,
CurrentVersion = null,
AllowIndexing = false,
CanonicalBaseUrl = null,
GoogleTagManager = new GoogleTagManagerConfiguration(),
Expand Down
1 change: 1 addition & 0 deletions src/Elastic.ApiExplorer/Landing/LandingView.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
NavigationHtml = Model.NavigationHtml,
UrlPathPrefix = null,
VersionDropdown = null,
CurrentVersion = "9.0+",
AllowIndexing = false,
CanonicalBaseUrl = null,
GoogleTagManager = new GoogleTagManagerConfiguration(),
Expand Down
1 change: 1 addition & 0 deletions src/Elastic.ApiExplorer/Operations/OperationView.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
NavigationHtml = Model.NavigationHtml,
UrlPathPrefix = null,
VersionDropdown = null,
CurrentVersion = null,
AllowIndexing = false,
CanonicalBaseUrl = null,
GoogleTagManager = new GoogleTagManagerConfiguration(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ appendIconComponentCache({
type VersionDropdownItem = {
name: string
href?: string
disabled: boolean
children?: VersionDropdownItem[]
}

type VersionDropdownProps = {
currentVersion: string
items: VersionDropdownItem[]
}

const VersionDropdown = ({ items }: VersionDropdownProps) => {
const VersionDropdown = ({ currentVersion, items }: VersionDropdownProps) => {
const [isPopoverOpen, setPopover] = useState(false)

const contextMenuPopoverId = useGeneratedHtmlId({
Expand All @@ -74,6 +76,7 @@ const VersionDropdown = ({ items }: VersionDropdownProps) => {
return {
name: item.name,
href: item.href,
disabled: item.disabled,
}
})
}
Expand All @@ -90,6 +93,7 @@ const VersionDropdown = ({ items }: VersionDropdownProps) => {
title: item.name,
initialFocusedItemIndex: 0,
width: WIDTH,
disabled: item.disabled,
size: 's',
items: item.children ? convertItems(item.children) : [],
}
Expand All @@ -104,6 +108,7 @@ const VersionDropdown = ({ items }: VersionDropdownProps) => {
name: item.name,
panel: item.children?.length ? index + 1 : undefined,
href: item.href,
disabled: item.disabled,
}
})

Expand All @@ -117,7 +122,9 @@ const VersionDropdown = ({ items }: VersionDropdownProps) => {
<EuiFlexItem grow={0}>
<EuiIcon type="check" />
</EuiFlexItem>
<EuiFlexItem grow={1}>Current (9.0+)</EuiFlexItem>
<EuiFlexItem grow={1}>
Current ({currentVersion})
</EuiFlexItem>
</EuiFlexGroup>
),
width: WIDTH,
Expand Down Expand Up @@ -149,7 +156,7 @@ const VersionDropdown = ({ items }: VersionDropdownProps) => {
font-size: 0.875rem;
`}
>
Current (9.0+)
Current ({currentVersion})
</EuiText>
</EuiButton>
)
Expand All @@ -174,6 +181,7 @@ customElements.define(
r2wc(VersionDropdown, {
props: {
items: 'json',
currentVersion: 'string',
},
})
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@if (Model.Features.IsVersionDropdownEnabled && Model.VersionDropdown is not null)
{
<div id="version-dropdown">
<version-dropdown items='@(new HtmlString(Model.VersionDropdown))' />
<version-dropdown current-version='@(Model.CurrentVersion)' items='@(new HtmlString(Model.VersionDropdown))' />
</div>
}
</div>
Expand Down
1 change: 1 addition & 0 deletions src/Elastic.Documentation.Site/_ViewModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class GlobalLayoutViewModel
public required INavigationItem? Next { get; init; }

public required string? VersionDropdown { get; init; }
public required string? CurrentVersion { get; init; }

public required string NavigationHtml { get; init; }
public required string? UrlPathPrefix { get; init; }
Expand Down
8 changes: 6 additions & 2 deletions src/Elastic.Markdown/Slices/IndexViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,17 @@ public class VersionDrownDownItemViewModel
[JsonPropertyName("href")]
public required string? Href { get; init; }

[JsonPropertyName("disabled")]
public required bool IsDisabled { get; init; }

[JsonPropertyName("children")]
public required VersionDrownDownItemViewModel[]? Children { get; init; }

// This logic currently only handles one level of children. Although the model supports multiple levels, it is not currently used.
public static VersionDrownDownItemViewModel[]? FromLegacyPageMappings(LegacyPageMapping[]? legacyPageMappings)
{
if (legacyPageMappings is null)
{
return null;
}
var groupedVersions = GroupByMajorVersion(legacyPageMappings);
return groupedVersions.Select(m =>
{
Expand All @@ -79,10 +80,12 @@ public class VersionDrownDownItemViewModel
{
Name = m.Key,
Href = null,
IsDisabled = false,
Children = m.Value.Select(v => new VersionDrownDownItemViewModel
{
Name = v,
Href = legacyPageMappings.First(x => x.Version == v).ToString(),
IsDisabled = !legacyPageMappings.First(x => x.Version == v).Exists,
Children = null
}).ToArray()
};
Expand All @@ -95,6 +98,7 @@ public class VersionDrownDownItemViewModel
{
Name = legacyPageMapping.Version,
Href = legacyPageMapping.ToString(),
IsDisabled = !legacyPageMapping.Exists,
Children = null
};
}).ToArray();
Expand Down
2 changes: 0 additions & 2 deletions src/Elastic.Markdown/Slices/MarkdownLayoutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public class MarkdownLayoutViewModel : GlobalLayoutViewModel

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

public required string? CurrentVersion { get; init; }

public required LegacyPageMapping[]? LegacyPages { get; init; }

public required IReadOnlyCollection<PageTocItem> PageTocItems { get; init; }
Expand Down
Loading