mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-09-04 22:22:21 +02:00
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 <marco.nenciarini@enterprisedb.com>
This commit is contained in:
parent
b547b6f05b
commit
8fb0d27df7
@ -1,17 +1,15 @@
|
|||||||
import {ReactElement} from 'react';
|
import {ReactElement} from 'react';
|
||||||
import CodeBlock from '@theme/CodeBlock';
|
import CodeBlock from '@theme/CodeBlock';
|
||||||
import {useActiveVersion} from '@docusaurus/plugin-content-docs/client';
|
import {useActiveVersion} from '@docusaurus/plugin-content-docs/client';
|
||||||
import {useCurrentVersion} from '@site/src/hooks/versions';
|
|
||||||
|
|
||||||
// InstallationSnippet is the kubectl incantation to install the Barman
|
// InstallationSnippet is the kubectl incantation to install the Barman
|
||||||
// Cloud Plugin: the manifest matching the doc version being viewed, or
|
// Cloud Plugin: the manifest matching the doc version being viewed, or
|
||||||
// (on the unreleased "current" docs) the latest manifest on main.
|
// (on the unreleased "current" docs) the latest manifest on main.
|
||||||
export function InstallationSnippet(): ReactElement<null> {
|
export function InstallationSnippet(): ReactElement<null> {
|
||||||
const activeVersion = useActiveVersion('default');
|
const activeVersion = useActiveVersion('default');
|
||||||
const version = useCurrentVersion('latest');
|
const url = activeVersion && activeVersion.name !== 'current'
|
||||||
const url = 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'
|
: '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`;
|
|
||||||
return (
|
return (
|
||||||
<CodeBlock language="sh">
|
<CodeBlock language="sh">
|
||||||
{`kubectl apply -f \\
|
{`kubectl apply -f \\
|
||||||
|
|||||||
@ -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;
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user