Skip to content

Commit 8d34063

Browse files
authored
Merge branch 'main' into feature/open-api-docs-2
2 parents 6445661 + c7be45e commit 8d34063

File tree

12 files changed

+189
-60
lines changed

12 files changed

+189
-60
lines changed

src/Elastic.ApiExplorer/Endpoints/EndpointView.cshtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
Next = null,
1313
NavigationHtml = Model.NavigationHtml,
1414
UrlPathPrefix = null,
15-
VersionDropdown = null,
1615
AllowIndexing = false,
1716
CanonicalBaseUrl = null,
1817
GoogleTagManager = new GoogleTagManagerConfiguration(),

src/Elastic.ApiExplorer/Landing/LandingView.cshtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
Next = null,
1313
NavigationHtml = Model.NavigationHtml,
1414
UrlPathPrefix = null,
15-
VersionDropdown = null,
1615
AllowIndexing = false,
1716
CanonicalBaseUrl = null,
1817
GoogleTagManager = new GoogleTagManagerConfiguration(),

src/Elastic.ApiExplorer/Operations/OperationView.cshtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
Next = null,
1616
NavigationHtml = Model.NavigationHtml,
1717
UrlPathPrefix = null,
18-
VersionDropdown = null,
1918
AllowIndexing = false,
2019
CanonicalBaseUrl = null,
2120
GoogleTagManager = new GoogleTagManagerConfiguration(),

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

Lines changed: 137 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'strict'
2+
13
import {
24
EuiButton,
35
EuiContextMenu,
@@ -6,7 +8,12 @@ import {
68
EuiIcon,
79
EuiPopover,
810
EuiText,
11+
EuiPanel,
12+
EuiLink,
13+
useEuiOverflowScroll,
914
useGeneratedHtmlId,
15+
useEuiTheme,
16+
useEuiFontSize,
1017
} from '@elastic/eui'
1118
import { icon as EuiIconVisualizeApp } from '@elastic/eui/es/components/icon/assets/app_visualize'
1219
import { icon as EuiIconArrowDown } from '@elastic/eui/es/components/icon/assets/arrow_down'
@@ -45,15 +52,23 @@ appendIconComponentCache({
4552
type VersionDropdownItem = {
4653
name: string
4754
href?: string
55+
disabled: boolean
4856
children?: VersionDropdownItem[]
4957
}
5058

5159
type VersionDropdownProps = {
52-
items: VersionDropdownItem[]
60+
currentVersion?: string
61+
allVersionsUrl?: string
62+
items?: VersionDropdownItem[]
5363
}
5464

55-
const VersionDropdown = ({ items }: VersionDropdownProps) => {
65+
const VersionDropdown = ({
66+
allVersionsUrl,
67+
currentVersion,
68+
items,
69+
}: VersionDropdownProps) => {
5670
const [isPopoverOpen, setPopover] = useState(false)
71+
const { euiTheme } = useEuiTheme()
5772

5873
const contextMenuPopoverId = useGeneratedHtmlId({
5974
prefix: 'contextMenuPopover',
@@ -74,63 +89,120 @@ const VersionDropdown = ({ items }: VersionDropdownProps) => {
7489
return {
7590
name: item.name,
7691
href: item.href,
92+
disabled: item.disabled,
7793
}
7894
})
7995
}
8096

8197
const convertToPanels = (
8298
items: VersionDropdownItem[]
8399
): EuiContextMenuPanelDescriptor[] => {
84-
return items.flatMap((item, index) => {
85-
if (item.children == null) {
86-
return []
87-
} else {
88-
return {
89-
id: index + 1,
90-
title: item.name,
91-
initialFocusedItemIndex: 0,
92-
width: WIDTH,
93-
size: 's',
94-
items: item.children ? convertItems(item.children) : [],
95-
}
96-
}
97-
})
100+
return items == null
101+
? []
102+
: items.flatMap((item, index) => {
103+
if (item.children == null) {
104+
return []
105+
} else {
106+
return {
107+
id: index + 1,
108+
title: item.name,
109+
initialFocusedItemIndex: 0,
110+
width: WIDTH,
111+
disabled: item.disabled,
112+
size: 's',
113+
items: item.children
114+
? convertItems(item.children)
115+
: [],
116+
}
117+
}
118+
})
98119
}
99120

100121
const WIDTH = 175
101122

102-
const topLevelItems = items.map((item, index) => {
103-
return {
104-
name: item.name,
105-
panel: item.children?.length ? index + 1 : undefined,
106-
href: item.href,
107-
}
108-
})
123+
const topLevelItems = () =>
124+
items.map((item, index) => {
125+
return {
126+
name: item.name,
127+
panel: item.children?.length ? index + 1 : undefined,
128+
href: item.href,
129+
disabled: item.disabled,
130+
}
131+
})
109132

110-
const subpanels = convertToPanels(items)
133+
const subpanels = () => convertToPanels(items)
111134

112-
const panels: EuiContextMenuPanelDescriptor[] = [
135+
const panels = (): EuiContextMenuPanelDescriptor[] => [
113136
{
114137
id: 0,
115138
title: (
116139
<EuiFlexGroup gutterSize="s" alignItems="center">
117140
<EuiFlexItem grow={0}>
118-
<EuiIcon type="check" />
141+
<EuiIcon type="check" size="s" />
142+
</EuiFlexItem>
143+
<EuiFlexItem grow={1}>
144+
<EuiText size="s">{currentVersion}</EuiText>
119145
</EuiFlexItem>
120-
<EuiFlexItem grow={1}>Current (9.0+)</EuiFlexItem>
121146
</EuiFlexGroup>
122147
),
123148
width: WIDTH,
124149
size: 's',
125150
items: [
126-
...topLevelItems,
127-
{
128-
name: 'All versions',
129-
href: 'https://elastic.co',
130-
},
151+
...(items == null
152+
? [
153+
{
154+
renderItem: () => (
155+
<EuiPanel paddingSize="s" hasShadow={false}>
156+
<EuiText size="xs" color="subdued">
157+
There are no other versions available
158+
for this page.
159+
</EuiText>
160+
</EuiPanel>
161+
),
162+
},
163+
]
164+
: topLevelItems()),
165+
...(items?.length === 0
166+
? [
167+
{
168+
renderItem: () => (
169+
<EuiPanel paddingSize="s" hasShadow={false}>
170+
<EuiText size="xs" color="subdued">
171+
This page was fully migrated to the
172+
current version.
173+
</EuiText>
174+
</EuiPanel>
175+
),
176+
},
177+
]
178+
: []),
179+
...(allVersionsUrl != null
180+
? [
181+
{
182+
renderItem: () => (
183+
<EuiPanel
184+
css={css`
185+
border-top: 1px solid
186+
${euiTheme.border.color};
187+
padding: ${euiTheme.size.s};
188+
`}
189+
>
190+
<EuiLink
191+
href="/docs/versions"
192+
color="text"
193+
>
194+
<EuiText size="s">
195+
View all versions
196+
</EuiText>
197+
</EuiLink>
198+
</EuiPanel>
199+
),
200+
},
201+
]
202+
: []),
131203
],
132204
},
133-
...subpanels,
205+
...(items != null ? subpanels() : []),
134206
]
135207

136208
const button = (
@@ -143,13 +215,12 @@ const VersionDropdown = ({ items }: VersionDropdownProps) => {
143215
style={{ borderRadius: 9999 }}
144216
>
145217
<EuiText
146-
size="xs"
147218
css={css`
148-
font-weight: 600;
149-
font-size: 0.875rem;
219+
font-weight: ${euiTheme.font.weight.bold};
220+
font-size: ${useEuiFontSize('xs').fontSize};
150221
`}
151222
>
152-
Current (9.0+)
223+
Current version ({currentVersion})
153224
</EuiText>
154225
</EuiButton>
155226
)
@@ -161,10 +232,35 @@ const VersionDropdown = ({ items }: VersionDropdownProps) => {
161232
isOpen={isPopoverOpen}
162233
closePopover={closePopover}
163234
panelPaddingSize="none"
164-
anchorPosition="downLeft"
235+
anchorPosition="downRight"
165236
repositionOnScroll={true}
166237
>
167-
<EuiContextMenu initialPanelId={0} size="s" panels={panels} />
238+
<EuiContextMenu
239+
initialPanelId={0}
240+
size="s"
241+
panels={panels()}
242+
css={css`
243+
max-height: 70vh;
244+
// This is needed because the CSS reset we are using
245+
// is probably not fully compatible with the EUI
246+
button {
247+
cursor: pointer;
248+
&:disabled {
249+
cursor: default;
250+
}
251+
}
252+
.euiContextMenuPanel__title {
253+
position: sticky;
254+
top: 0;
255+
// !important because clicking on the title
256+
// makes the background transparent
257+
// and you unexpectedly see the items behind it.
258+
background-color: ${euiTheme.colors
259+
.backgroundBasePlain} !important;
260+
}
261+
${useEuiOverflowScroll('y')}
262+
`}
263+
/>
168264
</EuiPopover>
169265
)
170266
}
@@ -174,6 +270,8 @@ customElements.define(
174270
r2wc(VersionDropdown, {
175271
props: {
176272
items: 'json',
273+
currentVersion: 'string',
274+
allVersionsUrl: 'string',
177275
},
178276
})
179277
)

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
</label>
1414
}
1515
<a href="@Model.Link("/")" class="text-lg leading-[1em] hover:text-blue-elastic active:text-blue-elastic-100">Docs</a>
16-
17-
@if (Model.Features.IsVersionDropdownEnabled && Model.VersionDropdown is not null)
18-
{
19-
<div id="version-dropdown">
20-
<version-dropdown items='@(new HtmlString(Model.VersionDropdown))' />
21-
</div>
22-
}
2316
</div>
2417
<ul class="flex gap-6">
2518
<li class="text-nowrap hover:text-blue-elastic active:text-blue-elastic-100">

src/Elastic.Documentation.Site/_ViewModels.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public class GlobalLayoutViewModel
2525
public required INavigationItem? Previous { get; init; }
2626
public required INavigationItem? Next { get; init; }
2727

28-
public required string? VersionDropdown { get; init; }
29-
3028
public required string NavigationHtml { get; init; }
3129
public required string? UrlPathPrefix { get; init; }
3230
public required Uri? CanonicalBaseUrl { get; init; }

src/Elastic.Markdown/Slices/HtmlWriter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ private async Task<string> RenderLayout(MarkdownFile markdown, MarkdownDocument
9494
.Distinct()
9595
.ToHashSet();
9696

97+
string? allVersionsUrl = null;
98+
99+
if (PositionalNavigation.MarkdownNavigationLookup.TryGetValue("docs-content://versions.md", out var item))
100+
allVersionsUrl = item.Url;
101+
97102
var slice = Index.Create(new IndexViewModel
98103
{
99104
SiteName = siteName,
@@ -120,6 +125,7 @@ private async Task<string> RenderLayout(MarkdownFile markdown, MarkdownDocument
120125
StaticFileContentHashProvider = StaticFileContentHashProvider,
121126
ReportIssueUrl = reportUrl,
122127
CurrentVersion = legacyPages?.Count > 0 ? legacyPages.ElementAt(0).Version : "9.0+",
128+
AllVersionsUrl = allVersionsUrl,
123129
LegacyPages = legacyPages?.Skip(1).ToArray(),
124130
VersionDropdownItems = VersionDrownDownItemViewModel.FromLegacyPageMappings(legacyPages?.Skip(1).ToArray()),
125131
Products = allProducts

src/Elastic.Markdown/Slices/Index.cshtml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,23 @@
3131
ReportIssueUrl = Model.ReportIssueUrl,
3232
LegacyPages = Model.LegacyPages,
3333
CurrentVersion = Model.CurrentVersion,
34-
VersionDropdown = JsonSerializer.Serialize(Model.VersionDropdownItems,
34+
AllVersionsUrl = Model.AllVersionsUrl,
35+
VersionDropdownSerializedModel = JsonSerializer.Serialize(Model.VersionDropdownItems,
3536
ViewModelSerializerContext.Default.VersionDrownDownItemViewModelArray),
3637
};
3738
protected override Task ExecuteSectionAsync(string name)
3839
{
40+
if (name == GlobalSections.Head)
41+
{
42+
<meta class="elastic" name="product_version" content="@Model.CurrentVersion"/>
43+
<meta name="DC.identifier" content="@Model.CurrentVersion"/>
44+
}
3945
if (name == GlobalSections.Head && Model.Products is { Count: > 0 })
4046
{
4147
var products = string.Join(",", Model.Products.Select(p => p.DisplayName));
4248
<meta class="elastic" name="product_name" content="@(products)"/>
4349
<meta name="DC.subject" content="@(products)"/>
4450
}
45-
4651
return Task.CompletedTask;
4752
}
4853
}

0 commit comments

Comments
 (0)