Repository navigation
Add quick links to the sections of an operation page #4641
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
Merged
akira28
merged 12 commits into
feature/api-explorer-expand-collapsible
from
feature/api-explorer-section-links
Nov 4, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4799b30
Add quick links to the sections of an operation page
akira28 ee6bb59
Reuse the outline scroll-spy and count pill for section links
akira28 b3057fd
Mark the last outline entry at the page bottom and drop stale spies
akira28 71e8d6c
Give the section links test a page taller than the window
akira28 d215759
Keep the examples rail in view while the sections scroll
akira28 3d62575
Scroll the examples, not the rail, so Copy page is not clipped
akira28 54203c6
Show a count on every section quick link
akira28 c30051f
Drop the counts from the section quick links
akira28 b69ec01
Name the response section #response and mark the clicked quick link
akira28 fa14790
Keep the #responses anchor and update the outline on link clicks
akira28 64e12cf
Rename the quick links and keep Authorization out of the bar
akira28 d077c89
Rename Required authorization to Required privileges
akira28 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/Elastic.ApiExplorer/Operations/_Partials/_SectionLinks.cshtml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| @inherits RazorSlice<IReadOnlyList<Elastic.ApiExplorer.Operations.SectionLink>> | ||
| @* Quick links to the sections below. The scroll-spy of the "On this page" outline (ds/toc.ts) marks the link of the section in view. *@ | ||
| <nav class="api-section-links" aria-label="Sections of this endpoint" data-toc data-toc-sticky> | ||
| @foreach (var link in Model) | ||
| { | ||
| <a href="#@link.Anchor" data-toc-link>@link.Label</a> | ||
| } | ||
| </nav> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/Elastic.Documentation.Site/Assets/api-section-links.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { initApiDocs } from './api-docs' | ||
| import { beforeAll, describe, expect, it } from 'vitest' | ||
|
|
||
| describe('section links', () => { | ||
| beforeAll(() => initApiDocs()) | ||
|
|
||
| it('marks the first link of the bar on an operation page, through the outline scroll-spy', () => { | ||
| document.body.innerHTML = ` | ||
| <section id="elastic-api-v3"> | ||
| <nav class="api-section-links" data-toc data-toc-sticky> | ||
| <a href="#query-params" data-toc-link>Query</a> | ||
| <a href="#responses" data-toc-link>Response</a> | ||
| </nav> | ||
| <h2 id="query-params"></h2> | ||
| <h2 id="responses"></h2> | ||
| </section>` | ||
| // jsdom has no layout: a page taller than the window, scrolled to the top | ||
| Object.defineProperty(document.documentElement, 'scrollHeight', { | ||
| value: 5000, | ||
| configurable: true, | ||
| }) | ||
| // jsdom has no layout: the first section is in view, the second is below the fold | ||
| const top = { 'query-params': -100, responses: 900 } | ||
| for (const [id, y] of Object.entries(top)) | ||
| document.getElementById(id)!.getBoundingClientRect = () => | ||
| ({ top: y }) as DOMRect | ||
| initApiDocs() | ||
|
|
||
| const current = document.querySelectorAll('[aria-current]') | ||
| expect(current).toHaveLength(1) | ||
| expect(current[0].getAttribute('href')).toBe('#query-params') | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.