diff --git a/src/Elastic.ApiExplorer/Endpoints/EndpointView.cshtml b/src/Elastic.ApiExplorer/Endpoints/EndpointView.cshtml index b8487e1fb..95bc519ec 100644 --- a/src/Elastic.ApiExplorer/Endpoints/EndpointView.cshtml +++ b/src/Elastic.ApiExplorer/Endpoints/EndpointView.cshtml @@ -12,8 +12,6 @@ Next = null, NavigationHtml = Model.NavigationHtml, UrlPathPrefix = null, - VersionDropdown = null, - CurrentVersion = null, AllowIndexing = false, CanonicalBaseUrl = null, GoogleTagManager = new GoogleTagManagerConfiguration(), diff --git a/src/Elastic.ApiExplorer/Landing/LandingView.cshtml b/src/Elastic.ApiExplorer/Landing/LandingView.cshtml index f6af0e1d7..d24553791 100644 --- a/src/Elastic.ApiExplorer/Landing/LandingView.cshtml +++ b/src/Elastic.ApiExplorer/Landing/LandingView.cshtml @@ -12,8 +12,6 @@ Next = null, NavigationHtml = Model.NavigationHtml, UrlPathPrefix = null, - VersionDropdown = null, - CurrentVersion = "9.0+", AllowIndexing = false, CanonicalBaseUrl = null, GoogleTagManager = new GoogleTagManagerConfiguration(), diff --git a/src/Elastic.ApiExplorer/Operations/OperationView.cshtml b/src/Elastic.ApiExplorer/Operations/OperationView.cshtml index bf2593d1c..12d821176 100644 --- a/src/Elastic.ApiExplorer/Operations/OperationView.cshtml +++ b/src/Elastic.ApiExplorer/Operations/OperationView.cshtml @@ -12,8 +12,6 @@ Next = null, NavigationHtml = Model.NavigationHtml, UrlPathPrefix = null, - VersionDropdown = null, - CurrentVersion = null, AllowIndexing = false, CanonicalBaseUrl = null, GoogleTagManager = new GoogleTagManagerConfiguration(), diff --git a/src/Elastic.Documentation.Site/Assets/web-components/VersionDropdown.tsx b/src/Elastic.Documentation.Site/Assets/web-components/VersionDropdown.tsx index bc5b17576..c4d77844a 100644 --- a/src/Elastic.Documentation.Site/Assets/web-components/VersionDropdown.tsx +++ b/src/Elastic.Documentation.Site/Assets/web-components/VersionDropdown.tsx @@ -1,3 +1,5 @@ +'strict' + import { EuiButton, EuiContextMenu, @@ -6,7 +8,12 @@ import { EuiIcon, EuiPopover, EuiText, + EuiPanel, + EuiLink, + useEuiOverflowScroll, useGeneratedHtmlId, + useEuiTheme, + useEuiFontSize, } from '@elastic/eui' import { icon as EuiIconVisualizeApp } from '@elastic/eui/es/components/icon/assets/app_visualize' import { icon as EuiIconArrowDown } from '@elastic/eui/es/components/icon/assets/arrow_down' @@ -50,12 +57,18 @@ type VersionDropdownItem = { } type VersionDropdownProps = { - currentVersion: string - items: VersionDropdownItem[] + currentVersion?: string + allVersionsUrl?: string + items?: VersionDropdownItem[] } -const VersionDropdown = ({ currentVersion, items }: VersionDropdownProps) => { +const VersionDropdown = ({ + allVersionsUrl, + currentVersion, + items, +}: VersionDropdownProps) => { const [isPopoverOpen, setPopover] = useState(false) + const { euiTheme } = useEuiTheme() const contextMenuPopoverId = useGeneratedHtmlId({ prefix: 'contextMenuPopover', @@ -84,60 +97,112 @@ const VersionDropdown = ({ currentVersion, items }: VersionDropdownProps) => { const convertToPanels = ( items: VersionDropdownItem[] ): EuiContextMenuPanelDescriptor[] => { - return items.flatMap((item, index) => { - if (item.children == null) { - return [] - } else { - return { - id: index + 1, - title: item.name, - initialFocusedItemIndex: 0, - width: WIDTH, - disabled: item.disabled, - size: 's', - items: item.children ? convertItems(item.children) : [], - } - } - }) + return items == null + ? [] + : items.flatMap((item, index) => { + if (item.children == null) { + return [] + } else { + return { + id: index + 1, + title: item.name, + initialFocusedItemIndex: 0, + width: WIDTH, + disabled: item.disabled, + size: 's', + items: item.children + ? convertItems(item.children) + : [], + } + } + }) } const WIDTH = 175 - const topLevelItems = items.map((item, index) => { - return { - name: item.name, - panel: item.children?.length ? index + 1 : undefined, - href: item.href, - disabled: item.disabled, - } - }) + const topLevelItems = () => + items.map((item, index) => { + return { + name: item.name, + panel: item.children?.length ? index + 1 : undefined, + href: item.href, + disabled: item.disabled, + } + }) - const subpanels = convertToPanels(items) + const subpanels = () => convertToPanels(items) - const panels: EuiContextMenuPanelDescriptor[] = [ + const panels = (): EuiContextMenuPanelDescriptor[] => [ { id: 0, title: ( - + - Current ({currentVersion}) + {currentVersion} ), width: WIDTH, size: 's', items: [ - ...topLevelItems, - { - name: 'All versions', - href: 'https://elastic.co', - }, + ...(items == null + ? [ + { + renderItem: () => ( + + + There are no other versions available + for this page. + + + ), + }, + ] + : topLevelItems()), + ...(items?.length === 0 + ? [ + { + renderItem: () => ( + + + This page was fully migrated to the + current version. + + + ), + }, + ] + : []), + ...(allVersionsUrl != null + ? [ + { + renderItem: () => ( + + + + View all versions + + + + ), + }, + ] + : []), ], }, - ...subpanels, + ...(items != null ? subpanels() : []), ] const button = ( @@ -150,13 +215,12 @@ const VersionDropdown = ({ currentVersion, items }: VersionDropdownProps) => { style={{ borderRadius: 9999 }} > - Current ({currentVersion}) + Current version ({currentVersion}) ) @@ -168,10 +232,35 @@ const VersionDropdown = ({ currentVersion, items }: VersionDropdownProps) => { isOpen={isPopoverOpen} closePopover={closePopover} panelPaddingSize="none" - anchorPosition="downLeft" + anchorPosition="downRight" repositionOnScroll={true} > - + ) } @@ -182,6 +271,7 @@ customElements.define( props: { items: 'json', currentVersion: 'string', + allVersionsUrl: 'string', }, }) ) diff --git a/src/Elastic.Documentation.Site/Layout/_SecondaryNav.cshtml b/src/Elastic.Documentation.Site/Layout/_SecondaryNav.cshtml index 528317811..f4bd99a58 100644 --- a/src/Elastic.Documentation.Site/Layout/_SecondaryNav.cshtml +++ b/src/Elastic.Documentation.Site/Layout/_SecondaryNav.cshtml @@ -13,13 +13,6 @@ } Docs - - @if (Model.Features.IsVersionDropdownEnabled && Model.VersionDropdown is not null) - { -
- -
- } + }