mirror of https://github.com/portainer/portainer
fix(help): add versioned doc links to support LTS/STS docs [EE-6780] (#11282)
parent
a43454076b
commit
ff178641be
|
@ -2,6 +2,8 @@ import { HelpCircle } from 'lucide-react';
|
||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import { useCurrentStateAndParams } from '@uirouter/react';
|
import { useCurrentStateAndParams } from '@uirouter/react';
|
||||||
|
|
||||||
|
import { useSystemVersion } from '@/react/portainer/system/useSystemVersion';
|
||||||
|
|
||||||
import headerStyles from '../HeaderTitle.module.css';
|
import headerStyles from '../HeaderTitle.module.css';
|
||||||
import './ContextHelp.css';
|
import './ContextHelp.css';
|
||||||
|
|
||||||
|
@ -11,7 +13,7 @@ export function ContextHelp() {
|
||||||
return (
|
return (
|
||||||
<div className={headerStyles.menuButton}>
|
<div className={headerStyles.menuButton}>
|
||||||
<a
|
<a
|
||||||
href={`https://docs.portainer.io${docsUrl}`}
|
href={docsUrl}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
color="none"
|
color="none"
|
||||||
className={clsx(
|
className={clsx(
|
||||||
|
@ -32,11 +34,26 @@ export function ContextHelp() {
|
||||||
|
|
||||||
function useDocsUrl(): string {
|
function useDocsUrl(): string {
|
||||||
const { state } = useCurrentStateAndParams();
|
const { state } = useCurrentStateAndParams();
|
||||||
|
const versionQuery = useSystemVersion();
|
||||||
|
|
||||||
if (!state) {
|
if (!state) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let url = 'https://docs.portainer.io/';
|
||||||
|
if (versionQuery.data) {
|
||||||
|
let { ServerVersion } = versionQuery.data;
|
||||||
|
if (ServerVersion[0] === 'v') {
|
||||||
|
ServerVersion = ServerVersion.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const parts = ServerVersion.split('.');
|
||||||
|
if (parts.length >= 2) {
|
||||||
|
const version = parts.slice(0, 2).join('.');
|
||||||
|
url += `v/${version}/`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const { data } = state;
|
const { data } = state;
|
||||||
if (
|
if (
|
||||||
data &&
|
data &&
|
||||||
|
@ -44,8 +61,8 @@ function useDocsUrl(): string {
|
||||||
'docs' in data &&
|
'docs' in data &&
|
||||||
typeof data.docs === 'string'
|
typeof data.docs === 'string'
|
||||||
) {
|
) {
|
||||||
return data.docs;
|
return url + data.docs;
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return url;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { QueryClient, QueryClientProvider } from 'react-query';
|
||||||
|
|
||||||
import { UserContext } from '@/react/hooks/useUser';
|
import { UserContext } from '@/react/hooks/useUser';
|
||||||
import { UserViewModel } from '@/portainer/models/user';
|
import { UserViewModel } from '@/portainer/models/user';
|
||||||
import { render } from '@/react-tools/test-utils';
|
import { render } from '@/react-tools/test-utils';
|
||||||
|
@ -23,14 +25,17 @@ test('should not render without a wrapping HeaderContainer', async () => {
|
||||||
test('should display a HeaderTitle', async () => {
|
test('should display a HeaderTitle', async () => {
|
||||||
const username = 'username';
|
const username = 'username';
|
||||||
const user = new UserViewModel({ Username: username });
|
const user = new UserViewModel({ Username: username });
|
||||||
|
const queryClient = new QueryClient();
|
||||||
|
|
||||||
const title = 'title';
|
const title = 'title';
|
||||||
const { queryByText } = render(
|
const { queryByText } = render(
|
||||||
<UserContext.Provider value={{ user }}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<HeaderContainer>
|
<UserContext.Provider value={{ user }}>
|
||||||
<HeaderTitle title={title} />
|
<HeaderContainer>
|
||||||
</HeaderContainer>
|
<HeaderTitle title={title} />
|
||||||
</UserContext.Provider>
|
</HeaderContainer>
|
||||||
|
</UserContext.Provider>
|
||||||
|
</QueryClientProvider>
|
||||||
);
|
);
|
||||||
|
|
||||||
const heading = queryByText(title);
|
const heading = queryByText(title);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { UserContext } from '@/react/hooks/useUser';
|
import { UserContext } from '@/react/hooks/useUser';
|
||||||
import { UserViewModel } from '@/portainer/models/user';
|
import { UserViewModel } from '@/portainer/models/user';
|
||||||
import { render } from '@/react-tools/test-utils';
|
import { renderWithQueryClient } from '@/react-tools/test-utils';
|
||||||
|
|
||||||
import { PageHeader } from './PageHeader';
|
import { PageHeader } from './PageHeader';
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ test('should display a PageHeader', async () => {
|
||||||
const user = new UserViewModel({ Username: username });
|
const user = new UserViewModel({ Username: username });
|
||||||
|
|
||||||
const title = 'title';
|
const title = 'title';
|
||||||
const { queryByText } = render(
|
const { queryByText } = renderWithQueryClient(
|
||||||
<UserContext.Provider value={{ user }}>
|
<UserContext.Provider value={{ user }}>
|
||||||
<PageHeader title={title} />
|
<PageHeader title={title} />
|
||||||
</UserContext.Provider>
|
</UserContext.Provider>
|
||||||
|
|
Loading…
Reference in New Issue