-
Notifications
You must be signed in to change notification settings - Fork 82
EPMRPP-117636 || Add a version warning banner for previous documentation versions #1173
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
allaprischepa
merged 1 commit into
develop
from
feature/EPMRPP-117636-add-a-version-warning-banner-for-previous-documentation-versions
Sep 16, 2026
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import clsx from 'clsx'; | ||
| import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; | ||
| import Link from '@docusaurus/Link'; | ||
| import Translate from '@docusaurus/Translate'; | ||
| import { | ||
| useActivePlugin, | ||
| useDocVersionSuggestions, | ||
| useDocsPreferredVersion, | ||
| useDocsVersion, | ||
| } from '@docusaurus/plugin-content-docs/client'; | ||
| import { ThemeClassNames } from '@docusaurus/theme-common'; | ||
|
|
||
| function UnreleasedVersionLabel({ productName, versionMetadata }) { | ||
| return ( | ||
| <Translate | ||
| id="theme.docs.versions.unreleasedVersionLabel" | ||
| description="The label used to tell the user that he's browsing an unreleased doc version" | ||
| values={{ | ||
| productName, | ||
| versionLabel: <b>{versionMetadata.label}</b>, | ||
| }} | ||
| > | ||
| {'You are viewing unreleased {productName} documentation version {versionLabel}.'} | ||
| </Translate> | ||
| ); | ||
| } | ||
|
|
||
| UnreleasedVersionLabel.propTypes = { | ||
| productName: PropTypes.string.isRequired, | ||
| versionMetadata: PropTypes.shape({ | ||
| label: PropTypes.string, | ||
| }).isRequired, | ||
| }; | ||
|
|
||
| function UnmaintainedVersionLabel({ productName, versionMetadata }) { | ||
| return ( | ||
| <Translate | ||
| id="theme.docs.versions.unmaintainedVersionLabel" | ||
| description="The label used to tell the user that he's browsing an unmaintained doc version" | ||
| values={{ | ||
| productName, | ||
| versionLabel: <b>{versionMetadata.label}</b>, | ||
| }} | ||
| > | ||
| {'You are viewing {productName} documentation version {versionLabel}.'} | ||
| </Translate> | ||
| ); | ||
| } | ||
|
|
||
| UnmaintainedVersionLabel.propTypes = { | ||
| productName: PropTypes.string.isRequired, | ||
| versionMetadata: PropTypes.shape({ | ||
| label: PropTypes.string, | ||
| }).isRequired, | ||
| }; | ||
|
|
||
| const BannerLabelComponents = { | ||
| unreleased: UnreleasedVersionLabel, | ||
| unmaintained: UnmaintainedVersionLabel, | ||
| }; | ||
|
|
||
| function BannerLabel({ productName, versionMetadata }) { | ||
| const BannerLabelComponent = BannerLabelComponents[versionMetadata.banner]; | ||
| return <BannerLabelComponent productName={productName} versionMetadata={versionMetadata} />; | ||
| } | ||
|
|
||
| BannerLabel.propTypes = { | ||
| productName: PropTypes.string.isRequired, | ||
| versionMetadata: PropTypes.shape({ | ||
| banner: PropTypes.oneOf(['unreleased', 'unmaintained']), | ||
| label: PropTypes.string, | ||
| }).isRequired, | ||
| }; | ||
|
|
||
| function LatestVersionSuggestionLabel({ versionLabel, to, onClick }) { | ||
| return ( | ||
| <Translate | ||
| id="theme.docs.versions.latestVersionSuggestionLabel" | ||
| description="The label used to tell the user to check the latest version" | ||
| values={{ | ||
| versionLabel, | ||
| latestVersionLink: ( | ||
| <Link to={to} onClick={onClick}> | ||
| <Translate | ||
| id="theme.docs.versions.latestVersionLinkLabel" | ||
| description="The label used for the latest version suggestion link label" | ||
| > | ||
| latest documentation | ||
| </Translate> | ||
| </Link> | ||
| ), | ||
| }} | ||
| > | ||
| { | ||
| 'For the latest features and updates, please visit the {latestVersionLink} ({versionLabel}).' | ||
| } | ||
| </Translate> | ||
| ); | ||
| } | ||
|
|
||
| LatestVersionSuggestionLabel.propTypes = { | ||
| versionLabel: PropTypes.string.isRequired, | ||
| to: PropTypes.string.isRequired, | ||
| onClick: PropTypes.func.isRequired, | ||
| }; | ||
|
|
||
| function DocVersionBannerEnabled({ className = undefined, versionMetadata }) { | ||
| const { | ||
| siteConfig: { customFields }, | ||
| } = useDocusaurusContext(); | ||
| const productName = customFields?.productName ?? 'ReportPortal'; | ||
| const { pluginId } = useActivePlugin({ failfast: true }); | ||
| const getVersionMainDoc = (version) => version.docs.find((doc) => doc.id === version.mainDocId); | ||
| const { savePreferredVersionName } = useDocsPreferredVersion(pluginId); | ||
| const { latestDocSuggestion, latestVersionSuggestion } = useDocVersionSuggestions(pluginId); | ||
| // Try to link to same doc in latest version (not always possible), falling | ||
| // back to main doc of latest version | ||
| const latestVersionSuggestedDoc = | ||
| latestDocSuggestion ?? getVersionMainDoc(latestVersionSuggestion); | ||
| return ( | ||
| <div | ||
| className={clsx( | ||
| className, | ||
| ThemeClassNames.docs.docVersionBanner, | ||
| 'alert alert--warning margin-bottom--md', | ||
| )} | ||
| role="alert" | ||
| > | ||
| <div> | ||
| <BannerLabel productName={productName} versionMetadata={versionMetadata} /> | ||
| </div> | ||
| <div className="margin-top--md"> | ||
| <LatestVersionSuggestionLabel | ||
| versionLabel={latestVersionSuggestion.label} | ||
| to={latestVersionSuggestedDoc.path} | ||
| onClick={() => savePreferredVersionName(latestVersionSuggestion.name)} | ||
| /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| DocVersionBannerEnabled.propTypes = { | ||
| className: PropTypes.string, | ||
| versionMetadata: PropTypes.shape({ | ||
| banner: PropTypes.oneOf(['unreleased', 'unmaintained']), | ||
| label: PropTypes.string, | ||
| }).isRequired, | ||
| }; | ||
|
|
||
| export default function DocVersionBanner({ className = undefined }) { | ||
| const versionMetadata = useDocsVersion(); | ||
| if (versionMetadata.banner) { | ||
| return <DocVersionBannerEnabled className={className} versionMetadata={versionMetadata} />; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| DocVersionBanner.propTypes = { | ||
| className: PropTypes.string, | ||
| }; |
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.