Skip to content

Keep the language selector when switching API examples - #4278

Draft
reakaleek wants to merge 2 commits into
mainfrom
api-catalog-language-selector
Draft

reakaleek wants to merge 2 commits into
mainfrom
api-catalog-language-selector

Conversation

@reakaleek

@reakaleek reakaleek commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Assembler preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/4278/api/doc/elasticsearch-serverless/operation/operation-inference-put-amazonbedrock

Choosing another API example keeps the language control on screen and leaves the selected language unchanged. An example with only one language does not show an empty language control.

Affects: API reference, Site UI

Prompt summary: Keep the language selector on screen after a different example is chosen, and keep the previously selected language. An example that exists in only one language must not show a broken empty selector. Fix this against the example switch on main. Do not rebuild the examples list from docs-builder#4269.

Why

The language control is rendered inside the scenario panel. Choosing another example hides that panel, so the control leaves the screen. This shows up on operations such as the one in elastic/docs-eng-team#891, where Console and curl belong to one example and the other examples are request JSON only. An empty language control on those JSON examples would leave the page with a selector that has nothing to select.

Closes elastic/docs-eng-team#891

What

Language control

The shared Console and curl samples render once above the example panels. Choosing another example hides that example's request body. The language control stays on screen, and the selected language stays selected.

Request example

The chosen example's request JSON stays in the panel under a Request example heading.

One language

An example that has only one language does not render a language control. The request body still shows, and the example dropdown still switches examples.

Verify

cd src/Elastic.Documentation.Site && npm test -- Assets/api-select.test.ts
dotnet build tests/Elastic.ApiExplorer.Tests
dotnet .artifacts/bin/Elastic.ApiExplorer.Tests/debug/Elastic.ApiExplorer.Tests.dll --treenode-filter "/*/*/OperationExamplesPanelRenderingTests/*"

Out of scope: Listing every example in the rail stays on docs-builder#4269. Heading markup and heading CSS are unchanged.

Made with Cursor

reakaleek and others added 2 commits October 1, 2026 12:28
A JSON-only example hides the control when it lives in the scenario panel. An example with one language must not render an empty selector.

Co-Authored-By: Grok 4.7 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Render the shared multi-language samples above the scenario panels so the switch hides the request example, not the language control.

Co-Authored-By: Grok 4.7 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Requesting changes due to a blocking initial-render mismatch between the selected scenario and the shared command samples.


What is this? | From workflow: PR Review

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

@if (shared is not null)
{
var sharedOptions = Model.Scenarios
.Select(choice => new ApiSelectOption(choice.Title, choice.TabId, choice.TabId == Model.Scenarios[0].TabId))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[HIGH] Initial selected example can disagree with the shared code samples

When shared resolves to a scenario that is not Model.Scenarios[0], the top shared code-sample card renders shared.CodeSamples but the scenario select is initialized to the first scenario (choice.TabId == Model.Scenarios[0].TabId). That creates an inconsistent initial state where the UI indicates one example is selected while showing command samples for a different example.

A concrete failure case is an operation where only the second scenario is multi-language and FindScenarioForCodeSamples maps code samples to that second scenario.

Please initialize the selected option (and initial visible scenario panel) from shared.TabId when shared samples are rendered, so scenario selection and displayed command samples stay aligned.

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Docs preview (local build)

Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4278/

This branch was successfully deployed

2 active deployments
docs-preview — dfdf941e Deployed Oct 1, 2026 by github-actions[bot]
assembler-preview — dfdf941e Deployed Oct 1, 2026 by github-actions[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant