From 8fb0d27df70f1fef1ae6790eb39ce7843e568384 Mon Sep 17 00:00:00 2001 From: Marco Nenciarini Date: Tue, 25 Aug 2026 14:06:27 +0200 Subject: [PATCH] refactor(web): drop the now-dead useCurrentVersion abstraction Its 'latestReleased' branch had no remaining caller after the previous commit, and InstallationSnippet was calling useActiveVersion twice (once directly, once through the hook) to re-run the same check. Build the manifest URL straight from the active version and drop hooks/versions.ts entirely. Signed-off-by: Marco Nenciarini --- web/src/components/Installation/index.tsx | 8 +++----- web/src/hooks/versions.ts | 24 ----------------------- 2 files changed, 3 insertions(+), 29 deletions(-) delete mode 100644 web/src/hooks/versions.ts diff --git a/web/src/components/Installation/index.tsx b/web/src/components/Installation/index.tsx index b2223c4..b149709 100644 --- a/web/src/components/Installation/index.tsx +++ b/web/src/components/Installation/index.tsx @@ -1,17 +1,15 @@ import {ReactElement} from 'react'; import CodeBlock from '@theme/CodeBlock'; import {useActiveVersion} from '@docusaurus/plugin-content-docs/client'; -import {useCurrentVersion} from '@site/src/hooks/versions'; // InstallationSnippet is the kubectl incantation to install the Barman // Cloud Plugin: the manifest matching the doc version being viewed, or // (on the unreleased "current" docs) the latest manifest on main. export function InstallationSnippet(): ReactElement { const activeVersion = useActiveVersion('default'); - const version = useCurrentVersion('latest'); - const url = activeVersion?.name === 'current' - ? 'https://raw.githubusercontent.com/cloudnative-pg/plugin-barman-cloud/refs/heads/main/manifest.yaml' - : `https://github.com/cloudnative-pg/plugin-barman-cloud/releases/download/v${version}/manifest.yaml`; + const url = activeVersion && activeVersion.name !== 'current' + ? `https://github.com/cloudnative-pg/plugin-barman-cloud/releases/download/v${activeVersion.name}/manifest.yaml` + : 'https://raw.githubusercontent.com/cloudnative-pg/plugin-barman-cloud/refs/heads/main/manifest.yaml'; return ( {`kubectl apply -f \\ diff --git a/web/src/hooks/versions.ts b/web/src/hooks/versions.ts deleted file mode 100644 index af79a70..0000000 --- a/web/src/hooks/versions.ts +++ /dev/null @@ -1,24 +0,0 @@ -import {useActiveVersion, useLatestVersion} from '@docusaurus/plugin-content-docs/client'; - - -export function useCurrentVersion(fallback: 'latest' | 'latestReleased' = 'latest'): string { - switch (fallback) { - case 'latestReleased': - return useLatestReleasedVersion(); - case 'latest': { - const version = useActiveVersion('default'); - if (version && version.name !== 'current') { - return version.name; - } - return useLatestReleasedVersion(); - } - default: - // The following line ensures that if `fallback` is not 'latest' or 'latestReleased', - // an error is thrown. This can be useful for catching unexpected states. - throw new Error(`Unhandled fallback type: ${fallback}`); - } -} - -export function useLatestReleasedVersion(): string { - return useLatestVersion('default').name; -}