Skip to content

Support version switcher on versioned docs #573

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gavinelder
Copy link
Contributor

@gavinelder gavinelder commented Apr 29, 2025

Summary

The following is changes to the version switcher as part of #566

It was discovered when using Docusaurus native versioning the version switcher would not appear unless you were on a versioned doc because the URL path was looking for /24.1/ etc however this is not included when using docusaurus versioning.

Github Code Summary.

Enhancements to UI rendering:

  • Updated the button label to display "Version" when currentVersion is undefined, ensuring the UI remains functional and user-friendly.
  • Simplified the conditional rendering of the " (current)" label to handle undefined currentVersion gracefully.

This pull request refines the VersionSwitcher component in VersionSwitcher.tsx to improve its handling of edge cases and enhance code robustness. The changes primarily address potential issues with undefined values and simplify conditional logic.

Improvements to edge case handling:

  • Updated the pathname.startsWith check to remove the trailing slash when verifying the /platform-enterprise prefix, ensuring consistency in URL matching.
  • Added a null check for currentVersion in the filter logic to prevent potential errors when currentVersion is undefined.
  • Modified the logic for extracting the urlSuffix to handle cases where currentVersion is not defined, defaulting to an empty string.

Copy link

netlify bot commented Apr 29, 2025

Deploy Preview for seqera-docs ready!

Name Link
🔨 Latest commit c3b31dd
🔍 Latest deploy log https://app.netlify.com/sites/seqera-docs/deploys/6810a7ceaf51950008f2c7e7
😎 Deploy Preview https://deploy-preview-573--seqera-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@gavinelder gavinelder requested a review from Copilot April 29, 2025 10:23
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refines the VersionSwitcher component to improve handling of undefined values and simplify conditional rendering for versioned docs in Docusaurus.

  • Updated the URL prefix check to remove the trailing slash for consistent matching.
  • Added a null check in the version filter to safely handle undefined currentVersion.
  • Modified the extraction of urlSuffix and the button label rendering for improved UI handling.
Comments suppressed due to low confidence (2)

src/theme/DocSidebar/Desktop/ProductSwitcher/VersionSwitcher.tsx:48

  • [nitpick] Consider initializing urlSuffix with a conditional assignment (e.g., using a ternary operator) to reduce mutation and enhance clarity of intent.
let urlSuffix = "";

src/theme/DocSidebar/Desktop/ProductSwitcher/VersionSwitcher.tsx:42

  • Removing the trailing slash in the URL prefix check may allow paths that partially match "/platform-enterprise". Consider verifying that this relaxed condition does not inadvertently match unexpected routes.
if (!location.pathname.startsWith("/platform-enterprise")) return null;

@gavinelder gavinelder marked this pull request as ready for review April 29, 2025 10:26
@gavinelder gavinelder requested review from ewels and mavi-sqr April 29, 2025 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant