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
8 changes: 7 additions & 1 deletion src/Elastic.ApiExplorer/Landing/ApiOverviewRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,13 @@ bool designSystem
AddProductRows(classification, rows, versionsConfig, designSystem);
break;
case TagNavigationItem tag:
rows.Add(new ApiOverviewRow { Kind = OverviewRowKind.TagHeading, Title = tag.NavigationTitle, Url = tag.Url });
rows.Add(new ApiOverviewRow
{
Kind = OverviewRowKind.TagHeading,
Title = tag.NavigationTitle,
Url = tag.Url,
Deprecated = tag.Deprecated
});
AddProductRows(tag, rows, versionsConfig, designSystem);
break;
case OperationNavigationItem operation:
Expand Down
18 changes: 17 additions & 1 deletion src/Elastic.ApiExplorer/Landing/LandingNavigationItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,26 @@ public class TagNavigationItem(
string apiUrlSuffix,
IRootNavigationItem<IApiGroupingModel, INavigationItem> rootNavigation,
INodeNavigationItem<INavigationModel, INavigationItem> parent
) : ApiGroupingNavigationItem<ApiTag, INavigationItem>(tag, rootNavigation, parent)
) : ApiGroupingNavigationItem<ApiTag, INavigationItem>(tag, rootNavigation, parent), IDeprecatableNavigationItem
{
private readonly string _url = $"{ApiUrlBuilder.ProductRoot(urlPathPrefix, apiUrlSuffix)}/group/{tag.TagUrlSegment}";

/// <summary>True when the group has operations and every one is deprecated; one current operation keeps the group current.</summary>
public bool Deprecated
{
get
{
var any = false;
foreach (var operation in NavigationItems.OfType<OperationNavigationItem>())
{
if (!operation.Model.Deprecated)
return false;
any = true;
}
return any;
}
}

internal void ApplyIntroHeadings(IReadOnlyList<TocItem> introHeadings)
{
var operations = NavigationItems.Where(item => item is not IntroHeadingNavigationItem).ToArray();
Expand Down
1 change: 1 addition & 0 deletions src/Elastic.ApiExplorer/Landing/TagLandingView.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<section id="elastic-api-v3" class="api-group">
<div class="api-page-heading">
<h1>@Model.Tag.DisplayName</h1>
@await RenderPartialAsync(_TitleBadges.Create(new TitleBadgesModel(null, Model.Deprecated, Model.BuildContext.Configuration.Features.NavigationPreviewEnabled)))
@await RenderPartialAsync(_VersionNotice.Create(Model))
</div>
@if (!string.IsNullOrEmpty(Model.DescriptionMarkdown))
Expand Down
2 changes: 2 additions & 0 deletions src/Elastic.ApiExplorer/Landing/TagLandingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Tag.ExternalDocs is null
string.IsNullOrWhiteSpace(Tag.ExternalDocs.Description) ? "Documentation" : Tag.ExternalDocs.Description
);

public bool Deprecated => RenderContext.CurrentNavigation is TagNavigationItem { Deprecated: true };

/// <inheritdoc />
protected override string? LayoutPageTitle => Tag.DisplayName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
var row = Model.Row;
}
<li>
<a class="api-group-row" href="@row.Url" @(new HtmlString(Model.HxAttributes))>
<a class="api-group-row@(row.Deprecated ? " api-group-row--deprecated" : "")" href="@row.Url" @(new HtmlString(Model.HxAttributes))>
<span class="api-group-heading">
<span class="api-overview-title">@row.Title</span>
<span class="api-overview-title">@if (row.Deprecated){<s class="api-deprecated-title">@row.Title</s>}else{@row.Title}</span>
@await RenderPartialAsync(_TitleBadges.Create(new TitleBadgesModel(row.Availability, row.Deprecated, row.DesignSystem)))
</span>
<div class="api-group-routes">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<h3 class="api-index-group-title">
@if (heading.Url is not null)
{
<a href="@heading.Url" @(new HtmlString(Model.HxAttributes))>@heading.Title</a>
<a href="@heading.Url" @(new HtmlString(Model.HxAttributes))>@if (heading.Deprecated){<s class="api-deprecated-title">@heading.Title</s><span class="sr-only">Deprecated</span>}else{@heading.Title}</a>
}
else
{
Expand All @@ -23,12 +23,12 @@
@foreach (var row in Model.Group.Items)
{
<li>
<a class="api-index-item" href="@row.Url" @(new HtmlString(Model.HxAttributes))>
<a class="api-index-item@(row.Deprecated ? " api-index-item--deprecated" : "")" href="@row.Url" @(new HtmlString(Model.HxAttributes))>
@if (row.Endpoint is { Rows.Count: > 0 } endpoint)
{
@(await RenderPartialAsync<_HttpMethodBadge, IReadOnlyList<string>>(endpoint.Rows[0].Methods))
<span class="api-index-item-text">
<span class="api-index-item-title">@row.Title</span>
<span class="api-index-item-title">@if (row.Deprecated){<s class="api-deprecated-title">@row.Title</s><span class="sr-only">Deprecated</span>}else{@row.Title}</span>
<code class="api-index-item-path">@endpoint.Rows[0].Route</code>
</span>
}
Expand Down
4 changes: 2 additions & 2 deletions src/Elastic.ApiExplorer/Navigation/ApiNavigationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ HashSet<string> takenMonikers
}
}
}
// Spec order looks arbitrary in a long group; readers scan by the route and method each row shows.
return [.. operationItems.InListOrder(static item => item.Endpoint.Rows[0])];
// Spec order looks arbitrary in a long group; readers scan by the route and method each row shows, current operations first.
return [.. operationItems.InListOrder(static item => item.Endpoint.Rows[0], static item => item.Model.Deprecated)];
Comment thread
reakaleek marked this conversation as resolved.
Resolved
}

/// <summary>
Expand Down
12 changes: 6 additions & 6 deletions src/Elastic.ApiExplorer/Operations/ApiOperationOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
namespace Elastic.ApiExplorer.Operations;

/// <summary>
/// The order operations are listed in: by route, then by method in resource lifecycle order (GET, POST, PUT, PATCH,
/// DELETE, HEAD, OPTIONS, TRACE, CONNECT). Unlike <see cref="OperationEndpoint"/>'s dominant method, this ranks for
/// scanning a list, not for choosing which method a page leads with.
/// The order operations are listed in: current before deprecated, then by route, then by method in resource lifecycle
/// order (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, TRACE, CONNECT). Unlike <see cref="OperationEndpoint"/>'s
/// dominant method, this ranks for scanning a list, not for choosing which method a page leads with.
/// </summary>
public static class ApiOperationOrder
{
private static readonly string[] Lifecycle = ["get", "post", "put", "patch", "delete", "head", "options", "trace", "connect"];

/// <summary>Orders <paramref name="items"/> by the route and method of the endpoint row each one shows first.</summary>
public static IOrderedEnumerable<T> InListOrder<T>(this IEnumerable<T> items, Func<T, EndpointRow> row) =>
items.OrderBy(i => row(i).Route, StringComparer.Ordinal).ThenBy(i => MethodRank(row(i).Method));
/// <summary>Orders <paramref name="items"/> deprecated last, then by the route and method of the endpoint row each one shows first.</summary>
public static IOrderedEnumerable<T> InListOrder<T>(this IEnumerable<T> items, Func<T, EndpointRow> row, Func<T, bool> deprecated) =>
items.OrderBy(deprecated).ThenBy(i => row(i).Route, StringComparer.Ordinal).ThenBy(i => MethodRank(row(i).Method));

/// <summary>The method's place in the lifecycle, ignoring case; an unknown method sorts last.</summary>
public static int MethodRank(string method)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ public class OperationNavigationItem(
// 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;

bool IApiOperationNavigationItem.Deprecated => Model.Deprecated;
bool IDeprecatableNavigationItem.Deprecated => Model.Deprecated;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ namespace Elastic.Documentation.Navigation;
/// 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
public interface IApiOperationNavigationItem : IDeprecatableNavigationItem
{
/// <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; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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>A navigation item the sidebar strikes through when it is deprecated.</summary>
public interface IDeprecatableNavigationItem : INavigationItem
{
bool Deprecated { get; }
}
10 changes: 8 additions & 2 deletions src/Elastic.Documentation.Site/Assets/api-docs.css
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@
}

.api-group .api-page-heading > h1 {
flex: 0 1 auto;
font-size: 24px;
line-height: 32px;
}
Expand Down Expand Up @@ -1162,13 +1163,18 @@
border-color: var(--color-grey-100);
}

#pages-nav a.nav-link--deprecated > span:first-child {
/* Every row that links to a deprecated operation looks the same; the operation page itself only shows the badge. */
/* API titles strike their own <s>, so a row's hover underline adds to the strike instead of replacing it. */
#pages-nav a.nav-link--deprecated > span:first-child,
.api-deprecated-title {
text-decoration: line-through;
opacity: 0.7;
Comment thread
reakaleek marked this conversation as resolved.
Resolved
}

/* The chip keeps its method colour so a retired DELETE still reads as a delete; lower saturation says it is retired. */
#pages-nav a.nav-link--deprecated .nav-v2-api-method {
#pages-nav a.nav-link--deprecated .nav-v2-api-method,
.api-group-row--deprecated .api-method,
.api-index-item--deprecated .api-method {
filter: saturate(0.4);
Comment thread
infra-vault-gh-plugin-prod[bot] marked this conversation as resolved.
Resolved
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<input class="nav-tree__toggle" type="checkbox" id="@item.Id" data-nav-toggle aria-label="Show pages under @item.NavigationTitle">
}
<div class="nav-tree__row">
<a class="nav-tree__link" href="@item.Url">@await RenderPartialAsync(_NavTreeLabel.Create(item))</a>
<a class="nav-tree__link@(item.Deprecated ? " nav-tree__link--deprecated" : "")" href="@item.Url">@await RenderPartialAsync(_NavTreeLabel.Create(item))</a>
@if (item.ShowToggle)
{
<label class="nav-tree__chevron" for="@item.Id" aria-hidden="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,18 @@
overflow-wrap: anywhere;
}

/* The same deprecated treatment as the sidebar's nav-tree rows: the title strikes its own <s>, so a hover underline adds to it. */
.api-deprecated-title {
text-decoration: line-through;
opacity: 0.7;
}

/* The chip keeps its method colour so a retired DELETE still reads as a delete; lower saturation says it is retired. */
.api-group-row--deprecated .api-method,
.api-index-item--deprecated .api-method {
filter: saturate(0.4);
}

/* The path sits under the title, so a familiar endpoint is easy to spot. The chip stays centered on the two lines. */
.api-index-item-text {
display: flex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public sealed record NavigationRenderNode
public string? Badge { get; init; }
/// <summary>Lowercase HTTP methods for API operation leaves, the dominant one first; drives the sidebar method chip.</summary>
public IReadOnlyList<string> HttpMethods { get; init; } = [];
/// <summary>True for an API operation leaf the spec marks deprecated.</summary>
/// <summary>True for an API operation the spec marks deprecated, or an API group whose every operation is.</summary>
public bool Deprecated { get; init; }
/// <summary>Only projected for nodes, where it drives the expand/collapse checkbox and its persisted state.</summary>
public string? Id { get; init; }
Expand Down Expand Up @@ -387,6 +387,7 @@ private static NavigationRenderNode CreateNode(INodeNavigationItem<INavigationMo
Url = isHeading ? "" : node.Url,
Id = node.Id,
ShowToggle = !isGroup && !node.NavigationItems.All(n => n.Hidden),
Deprecated = node is IDeprecatableNavigationItem { Deprecated: true },
NavigationItems = [.. CreateNavigationItems(node, isTopLevel: isGroup)]
};
}
Expand All @@ -402,7 +403,7 @@ private static NavigationRenderNode CreateLeaf(INavigationItem item, bool isTopL
NavigationTitle = navigationTitle,
Badge = badge,
HttpMethods = operation?.HttpMethods ?? [],
Deprecated = operation?.Deprecated ?? false,
Deprecated = item is IDeprecatableNavigationItem { Deprecated: true },
Url = item.Url
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@
{
<li class="nav-folder @(item.IsTopLevel ? "mt-6" : "mt-4")">
<div class="peer grid grid-cols-[1fr_auto] w-full">
<a href="@item.Url" class="sidebar-link nav-folder-link@(item.IsTopLevel ? " font-semibold" : "")">
<a href="@item.Url" class="sidebar-link nav-folder-link@(item.IsTopLevel ? " font-semibold" : "")@(item.Deprecated ? " nav-link--deprecated" : "")">
<span>@item.NavigationTitle</span>
@if (item.Deprecated) { <span class="sr-only">Deprecated</span> }
@if (item.Badge is not null) { <span class="nav-badge nav-badge-@item.Badge">@item.Badge</span> }
@await RenderPartialAsync(_NavHttpMethodGlyph.Create(item))
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Mixed</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<h3 class="api-index-group-title">
<a href="/api/test/group/endpoint-mixed" preload="mousedown">Mixed</a>
<span class="api-index-count">2</span>
</h3>
<ul class="api-index-list">
<li>
<a class="api-index-item" href="/api/test/operation/operation-mixed-get" preload="mousedown">
<span class="api-method api-method-get">
<span class="api-method-icon" aria-hidden="true">
<svg width="12" height="12" viewBox="0 0 12 12">
<use href="#icon-api-arrow"></use>
</svg>
</span>
<span class="api-method-label">GET</span>
</span>
<span class="api-index-item-text">
<span class="api-index-item-title">Get mixed</span>
<code class="api-index-item-path">/mixed/{id}</code>
</span>
</a>
</li>
<li>
<a class="api-index-item api-index-item--deprecated" href="/api/test/operation/operation-mixed-create" preload="mousedown">
<span class="api-method api-method-post">
<span class="api-method-icon" aria-hidden="true">
<svg width="12" height="12" viewBox="0 0 12 12">
<use href="#icon-api-arrow"></use>
</svg>
</span>
<span class="api-method-label">POST</span>
</span>
<span class="api-index-item-text">
<span class="api-index-item-title">
<s class="api-deprecated-title">Create mixed</s>
<span class="sr-only">Deprecated</span>
</span>
<code class="api-index-item-path">/mixed</code>
</span>
</a>
</li>
</ul>
<h3 class="api-index-group-title">
<a href="/api/test/group/endpoint-retired" preload="mousedown">
<s class="api-deprecated-title">Retired</s>
<span class="sr-only">Deprecated</span>
</a>
<span class="api-index-count">2</span>
</h3>
<ul class="api-index-list">
<li>
<a class="api-index-item api-index-item--deprecated" href="/api/test/operation/operation-retired-list" preload="mousedown">
<span class="api-method api-method-get">
<span class="api-method-icon" aria-hidden="true">
<svg width="12" height="12" viewBox="0 0 12 12">
<use href="#icon-api-arrow"></use>
</svg>
</span>
<span class="api-method-label">GET</span>
</span>
<span class="api-index-item-text">
<span class="api-index-item-title">
<s class="api-deprecated-title">List retired</s>
<span class="sr-only">Deprecated</span>
</span>
<code class="api-index-item-path">/retired</code>
</span>
</a>
</li>
<li>
<a class="api-index-item api-index-item--deprecated" href="/api/test/operation/operation-retired-delete" preload="mousedown">
<span class="api-method api-method-delete">
<span class="api-method-icon" aria-hidden="true">
<svg width="12" height="12" viewBox="0 0 12 12">
<use href="#icon-api-x"></use>
</svg>
</span>
<span class="api-method-label">DELETE</span>
</span>
<span class="api-index-item-text">
<span class="api-index-item-title">
<s class="api-deprecated-title">Delete retired</s>
<span class="sr-only">Deprecated</span>
</span>
<code class="api-index-item-path">/retired/{id}</code>
</span>
</a>
</li>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1>Retired</h1>
<span class="api-title-badges">
<span class="applies applies-inline">
<span class="applicable-info api-badge--danger">
<span class="applicable-name">Deprecated</span>
</span>
</span>
</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<a href="/api/test/group/endpoint-mixed" class="sidebar-link nav-folder-link font-semibold">
<span>Mixed</span>
</a>
<label for="3F8FEE62" class="group/label flex mr-2 items-start">
<div class="nav-toggle-btn">
<svg class="nav-chevron" viewBox="0 0 24 24">
<use href="#icon-chevron-down"></use>
</svg>
</div>
<input id="3F8FEE62" type="checkbox" class="hidden" aria-hidden="true">
</label>
<a href="/api/test/group/endpoint-retired" class="sidebar-link nav-folder-link font-semibold nav-link--deprecated">
<span>Retired</span>
<span class="sr-only">Deprecated</span>
</a>
<label for="5B720147" class="group/label flex mr-2 items-start">
<div class="nav-toggle-btn">
<svg class="nav-chevron" viewBox="0 0 24 24">
<use href="#icon-chevron-down"></use>
</svg>
</div>
<input id="5B720147" type="checkbox" class="hidden" aria-hidden="true">
</label>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<span class="nav-tree__text">Operations</span>
<a class="nav-tree__link" href="/api/test/group/endpoint-mixed">
<span class="nav-tree__text">Mixed</span>
</a>
<label class="nav-tree__chevron" for="3F8FEE62" aria-hidden="true">
<svg class="icon icon--sm" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="m8 10.293 5.646-5.647.708.708L8 11.707 1.646 5.354l.708-.708L8 10.293Z" clip-rule="evenodd"></path>
</svg>
</label>
<a class="nav-tree__link nav-tree__link--deprecated" href="/api/test/group/endpoint-retired">
<span class="nav-tree__text">Retired</span>
<span class="sr-only">Deprecated</span>
</a>
<label class="nav-tree__chevron" for="5B720147" aria-hidden="true">
<svg class="icon icon--sm" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="m8 10.293 5.646-5.647.708.708L8 11.707 1.646 5.354l.708-.708L8 10.293Z" clip-rule="evenodd"></path>
</svg>
</label>
Loading
Loading