Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<a class="api-index-item" href="@row.Url" @(new HtmlString(Model.HxAttributes))>
@if (row.Endpoint is { Rows.Count: > 0 } endpoint)
{
@(await RenderPartialAsync<_HttpMethodBadge, string>(endpoint.Rows[0].Method))
@(await RenderPartialAsync<_HttpMethodBadge, IReadOnlyList<string>>(endpoint.Rows[0].Methods))
<span class="api-index-item-text">
<span class="api-index-item-title">@row.Title</span>
<code class="api-index-item-path">@endpoint.Rows[0].Route</code>
Expand Down
17 changes: 16 additions & 1 deletion src/Elastic.ApiExplorer/Operations/OperationEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ public sealed record EndpointSegment(string Text, bool Optional)
}

/// <summary>One distinct route of an operation, with its dominant method and the methods that behave the same.</summary>
public sealed record EndpointRow(string Route, string Method, IReadOnlyList<string> AlsoMethods, IReadOnlyList<EndpointSegment> Segments);
public sealed record EndpointRow(string Route, string Method, IReadOnlyList<string> AlsoMethods, IReadOnlyList<EndpointSegment> Segments)
{
/// <summary>Every method of the route, the dominant one first: what a method chip lists.</summary>
public IReadOnlyList<string> Methods => [Method, .. AlsoMethods];
}

/// <summary>
/// Every route and method of one operation merged into display rows: longest route first, the dominant method per
Expand All @@ -44,6 +48,17 @@ public sealed partial record OperationEndpoint(
public const string SpaceParameterDescription = "An identifier for the space. If `space_id` is not provided in the URL, the default space is used. "
+ SpacesNote;

/// <summary>Every method of every route: the leading route's dominant method first, the rest by rank.</summary>
public IReadOnlyList<string> Methods =>
[
Rows[0].Method,
.. Rows
.SelectMany(static r => r.Methods)
.Distinct(StringComparer.OrdinalIgnoreCase)
.Where(m => !string.Equals(m, Rows[0].Method, StringComparison.OrdinalIgnoreCase))
.OrderBy(Rank)
];

private static readonly string[] MethodRank = ["post", "put", "patch", "get", "delete", "head", "options", "trace"];

/// <summary>
Expand Down
13 changes: 7 additions & 6 deletions src/Elastic.ApiExplorer/Operations/OperationNavigationItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ public record ApiOperation(
string Route,
IOpenApiPathItem Path,
string ApiName
) : IApiModel<OperationPageModel>, IApiOperationNavigationModel
) : IApiModel<OperationPageModel>
{
// The page header leads with the dominant method, which can come from the description's method listing
// rather than the spec; the sidebar badge must agree with it.
string IApiOperationNavigationModel.HttpMethod => OperationEndpoint.Build(this, Operation.Description, []).Rows[0].Method;

/// <summary>
/// The one deprecation fact the page title badge, the overview rows, the sidebar row and the search index all read.
/// Collapsed siblings always agree on it, because operations that differ in lifecycle are never collapsed onto one page.
Expand Down Expand Up @@ -86,7 +82,7 @@ public class OperationNavigationItem(
apiOperation,
root,
parent
), IEndpointOrOperationNavigationItem
), IEndpointOrOperationNavigationItem, IApiOperationNavigationItem
{
/// <summary>Other operations of the same API collapsed onto this page (other methods and routes).</summary>
public IReadOnlyList<ApiOperation> Siblings { get; init; } = [];
Expand All @@ -96,4 +92,9 @@ public class OperationNavigationItem(

/// <summary>The routes and methods this page lists, its own and its <see cref="Siblings"/>'.</summary>
public OperationEndpoint Endpoint => field ??= OperationEndpoint.Build(Model, Model.Operation.Description, Siblings);

// The sidebar chip must list what the page header lists, including methods that come from the description's method listing or from collapsed siblings.
IReadOnlyList<string> IApiOperationNavigationItem.HttpMethods => Endpoint.Methods;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P3 (Low)

No test covers the fix this PR is about: the sidebar now lists methods from collapsed siblings. OperationEndpointTests calls OperationEndpoint.Build(..., []) with no siblings. The nav rendering tests set HttpMethods on NavigationRenderNode by hand. OperationDeprecatedProjectionTests only checks a single-method leaf. If HttpMethods went back to building without Siblings, or CreateLeaf stopped matching IApiOperationNavigationItem, every test would still pass. Add a projection test that builds the navigation for collapsed operations (for example POST and GET /_search) and checks that the leaf's HttpMethods equals post, get.

Generated by Libra. Specialist: libra-complexity. React with 👍 or 👎 to give feedback on this comment.


bool IApiOperationNavigationItem.Deprecated => Model.Deprecated;
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
@using Elastic.ApiExplorer.Operations
@inherits RazorSlice<EndpointPathModel>
@* One merged route: dominant method badge, "also GET" for methods that behave the same, optional segments dashed. *@
@* One merged route: one chip listing every method that behaves the same, the dominant one first, optional segments dashed. *@
@{
var row = Model.Row;
}
<span class="api-url">
@(await RenderPartialAsync<_HttpMethodBadge, string>(row.Method))
@if (row.AlsoMethods.Count > 0)
{
var also = string.Join(", ", row.AlsoMethods.Select(static m => m.ToUpperInvariant()));
<span class="api-url-also-method" data-tippy-content="@also works the same way: same parameters, body, and response.">also @also</span>
}
@(await RenderPartialAsync<_HttpMethodBadge, IReadOnlyList<string>>(row.Methods))
@* Segments on the brace lines: Razor would otherwise emit the indentation and line breaks as text, which inline layout shows as a space after each optional segment. *@
<span class="api-url-path">@if (row.Segments.Count == 0){@("/")}@foreach (var segment in row.Segments)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.ApiExplorer/_Partials/_ApiCodeSample.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="api-code-sample-title">
@if (!string.IsNullOrEmpty(Model.HttpMethod))
{
@(await RenderPartialAsync<_HttpMethodBadge, string>(Model.HttpMethod))
@(await RenderPartialAsync<_HttpMethodChip, string>(Model.HttpMethod))
}
@if (!string.IsNullOrEmpty(Model.Route))
{
Expand Down
27 changes: 15 additions & 12 deletions src/Elastic.ApiExplorer/_Partials/_HttpMethodBadge.cshtml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
@inherits RazorSlice<string>
@* Labeled HTTP method chip — Figma APIs node 10067:6424. Icons match the Nav V2 glyphs. *@
<span class="api-method api-method-@Model">
<span class="api-method-icon" aria-hidden="true">
@if (Model == "delete")
@inherits RazorSlice<IReadOnlyList<string>>
@* Labeled HTTP method chip — Figma APIs node 10067:6424. Icons match the Nav V2 glyphs. Several methods join into one chip, the dominant method first. *@
@if (Model is [var only])
{
@(await RenderPartialAsync<_HttpMethodChip, string>(only))
}
else
{
var names = Model.Select(static m => m.ToUpperInvariant()).ToArray();
var others = names[1..];
var alike = others.Length == 1 ? others[0] : string.Join(", ", others[..^1]) + " and " + others[^1];
<span class="api-method-group" data-tippy-content="@names[0] is the main method. @alike @(others.Length == 1 ? "works" : "work") the same way: same parameters, body, and response.">
@foreach (var method in Model)
{
<svg width="12" height="12" viewBox="0 0 12 12"><use href="#icon-api-x"/></svg>
}
else
{
<svg width="12" height="12" viewBox="0 0 12 12"><use href="#icon-api-arrow"/></svg>
@(await RenderPartialAsync<_HttpMethodChip, string>(method))
}
</span>
<span class="api-method-label">@Model.ToUpperInvariant()</span>
</span>
}
14 changes: 14 additions & 0 deletions src/Elastic.ApiExplorer/_Partials/_HttpMethodChip.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@inherits RazorSlice<string>
<span class="api-method api-method-@Model">
<span class="api-method-icon" aria-hidden="true">
@if (Model == "delete")
{
<svg width="12" height="12" viewBox="0 0 12 12"><use href="#icon-api-x"/></svg>
}
else
{
<svg width="12" height="12" viewBox="0 0 12 12"><use href="#icon-api-arrow"/></svg>
}
</span>
<span class="api-method-label">@Model.ToUpperInvariant()</span>
</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

namespace Elastic.Documentation.Navigation;

/// <summary>
/// An API operation leaf that exposes its HTTP methods and deprecation for sidebar chrome. It is the page's
/// navigation item rather than its model, because the methods of operations collapsed onto the page live there.
/// </summary>
public interface IApiOperationNavigationItem : INavigationItem
{
/// <summary>Lowercase HTTP method names (e.g. <c>post</c>, <c>get</c>), the page's dominant method first.</summary>
IReadOnlyList<string> HttpMethods { get; }

/// <summary>True when the spec marks the operation deprecated.</summary>
bool Deprecated { get; }
}

This file was deleted.

150 changes: 123 additions & 27 deletions src/Elastic.Documentation.Site/Assets/api-docs.css
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@
padding-top: 2px;
}

.api-url-row > .api-url .api-url-also-method {
margin-top: 4px;
}

/* The first route is the one to read; the alternates below it are compact and muted. */
.api-page-intro .api-url-listing > li:first-child .api-url {
padding: 4px 12px 4px 4px;
Expand All @@ -131,12 +127,6 @@
font-size: 11px;
}

.api-page-intro .api-url-listing > li + li .api-url-also-method {
margin-top: 3px;
font-size: 10px;
line-height: 14px;
}

.api-page-intro .api-url-listing > li + li .api-url .api-url-path {
padding-top: 1px;
}
Expand Down Expand Up @@ -650,6 +640,11 @@
font-size: 11px;
}

/* A joined chip is as wide as its methods; each part must not also claim a whole chip width. */
.api-index-item .api-method-group .api-method {
min-width: 0;
}

.api-index-item-title {
min-width: 0;
overflow-wrap: anywhere;
Expand Down Expand Up @@ -875,12 +870,128 @@
display: none;
}

/*
* An operation that accepts several methods: one pill, the dominant method on the left. The chips join on a slanted
* edge, each keeps its outline on its outer edges, and the pill owns the corner radius.
*/
.api-method-group,
.nav-v2-api-method-group {
display: inline-flex;
flex-shrink: 0;
align-items: flex-start;
align-self: flex-start;
}

.api-method-group {
border-radius: 8px;
}

.nav-v2-api-method-group {
border-radius: 4px;
}

.api-method-group > .api-method,
.nav-v2-api-method-group > .nav-v2-api-method {
--method-slant: 0.5em;
border-width: 1px 0;
border-radius: 0;
}

.api-method-group > .api-method:first-child,
.nav-v2-api-method-group > .nav-v2-api-method:first-child {
border-left-width: 1px;
border-top-left-radius: inherit;
border-bottom-left-radius: inherit;
}

.api-method-group > .api-method:last-child,
.nav-v2-api-method-group > .nav-v2-api-method:last-child {
border-right-width: 1px;
border-top-right-radius: inherit;
border-bottom-right-radius: inherit;
}

.api-method-group > .api-method:not(:last-child),
.nav-v2-api-method-group > .nav-v2-api-method:not(:last-child) {
clip-path: polygon(
0 0,
100% 0,
calc(100% - var(--method-slant)) 100%,
0 100%
);
}

.api-method-group > .api-method:not(:first-child),
.nav-v2-api-method-group > .nav-v2-api-method:not(:first-child) {
margin-left: calc(2px - var(--method-slant));
clip-path: polygon(var(--method-slant) 0, 100% 0, 100% 100%, 0 100%);
}

/* Room either side of the seam, so the labels do not crowd the slant. */
.api-method-group > .api-method:not(:last-child) > :last-child {
margin-right: 0.35em;
}

.api-method-group > .api-method:not(:first-child) > :first-child {
margin-left: 0.35em;
}

#pages-nav .nav-v2-api-method-group > .nav-v2-api-method:not(:last-child) {
padding-right: calc(4px + 0.35em);
}

#pages-nav .nav-v2-api-method-group > .nav-v2-api-method:not(:first-child) {
padding-left: calc(4px + 0.35em);
}

/* The dominant method keeps its colour; the others recede to the old "also" look: no fill, dashed grey outline, muted text. */
.api-method-group > .api-method:not(:first-child),
#pages-nav
a.sidebar-link
.nav-v2-api-method-group
> .nav-v2-api-method:not(:first-child) {
border-style: dashed;
border-color: var(--color-grey-40, #98a2b3);
background-color: transparent;
color: var(--color-grey-100);
}

.api-method-group > .api-method:not(:first-child) {
font-weight: 400;
}

#pages-nav .nav-v2-api-method-group {
margin-top: 2px;
}

#pages-nav .nav-v2-api-method-group > .nav-v2-api-method {
margin-top: 0;
border-width: 1px 0;
border-radius: 0;
}

#pages-nav .nav-v2-api-method-group > .nav-v2-api-method:first-child {
border-left-width: 1px;
border-top-left-radius: inherit;
border-bottom-left-radius: inherit;
}

#pages-nav .nav-v2-api-method-group > .nav-v2-api-method:last-child {
border-right-width: 1px;
border-top-right-radius: inherit;
border-bottom-right-radius: inherit;
}

/* Legacy rows reserve 32px on the right; a row with a chip needs less. */
#pages-nav li:has(> a.sidebar-link > .nav-v2-api-method) {
#pages-nav
li:has(
> a.sidebar-link > :is(.nav-v2-api-method, .nav-v2-api-method-group)
) {
padding-right: 8px;
}

#pages-nav a.sidebar-link:has(> .nav-v2-api-method) {
#pages-nav
a.sidebar-link:has(> :is(.nav-v2-api-method, .nav-v2-api-method-group)) {
display: flex;
align-items: flex-start;
justify-content: space-between;
Expand Down Expand Up @@ -3473,21 +3584,6 @@ html:has(.api-page-shell) {
}
}

/* Merged endpoint rows: dominant method, "also GET", optional segments dashed. */
.api-url-also-method {
flex-shrink: 0;
padding: 0 6px;
border: 1px dashed var(--color-grey-40, #98a2b3);
border-radius: 999px;
color: #516381;
font-family: var(--font-body, Inter, ui-sans-serif, system-ui, sans-serif);
font-size: 11px;
font-weight: 500;
line-height: 16px;
white-space: nowrap;
cursor: help;
}

.api-url-path {
min-width: 0;
}
Expand Down
Loading
Loading