From 6e4900dc45b670a634a284646635f462bd13a32f Mon Sep 17 00:00:00 2001 From: Kian Eliasi Date: Fri, 2 Sep 2022 14:35:27 +0430 Subject: [PATCH] Footer: Add release notes url to version label (#52909) * Add release note url to footer's version label * Filter out pre-release versions in release notes link at the footer * correct links for beta/prerelease release notes * make all links target blank * Fix TeamPages test Co-authored-by: joshhunt --- public/app/core/components/Footer/Footer.tsx | 46 ++++++++++++++++---- public/app/features/teams/TeamPages.test.tsx | 46 +++++++++++--------- public/sass/components/_footer.scss | 1 + 3 files changed, 64 insertions(+), 29 deletions(-) diff --git a/public/app/core/components/Footer/Footer.tsx b/public/app/core/components/Footer/Footer.tsx index 4fa437b7913..fb05620b3d8 100644 --- a/public/app/core/components/Footer/Footer.tsx +++ b/public/app/core/components/Footer/Footer.tsx @@ -8,7 +8,6 @@ export interface FooterLink { id?: string; icon?: IconName; url?: string; - target?: string; } export let getFooterLinks = (): FooterLink[] => { @@ -17,23 +16,30 @@ export let getFooterLinks = (): FooterLink[] => { text: 'Documentation', icon: 'document-info', url: 'https://grafana.com/docs/grafana/latest/?utm_source=grafana_footer', - target: '_blank', }, { text: 'Support', icon: 'question-circle', url: 'https://grafana.com/products/enterprise/?utm_source=grafana_footer', - target: '_blank', }, { text: 'Community', icon: 'comments-alt', url: 'https://community.grafana.com/?utm_source=grafana_footer', - target: '_blank', }, ]; }; +export function getVersionMeta(version: string) { + const containsHyphen = version.includes('-'); + const isBeta = version.includes('-beta'); + + return { + hasReleaseNotes: !containsHyphen || isBeta, + isBeta, + }; +} + export let getVersionLinks = (): FooterLink[] => { const { buildInfo, licenseInfo } = config; const links: FooterLink[] = []; @@ -45,7 +51,16 @@ export let getVersionLinks = (): FooterLink[] => { return links; } - links.push({ text: `v${buildInfo.version} (${buildInfo.commit})` }); + const { hasReleaseNotes, isBeta } = getVersionMeta(buildInfo.version); + const versionSlug = buildInfo.version.replace(/\./g, '-'); // replace all periods with hyphens + const docsVersion = isBeta ? 'next' : 'latest'; + + links.push({ + text: `v${buildInfo.version} (${buildInfo.commit})`, + url: hasReleaseNotes + ? `https://grafana.com/docs/grafana/${docsVersion}/release-notes/release-notes-${versionSlug}/` + : undefined, + }); if (buildInfo.hasUpdate) { links.push({ @@ -53,7 +68,6 @@ export let getVersionLinks = (): FooterLink[] => { text: `New version available!`, icon: 'download-alt', url: 'https://grafana.com/grafana/download?utm_source=grafana_footer', - target: '_blank', }); } @@ -77,9 +91,7 @@ export const Footer: FC = React.memo(() => { @@ -89,3 +101,19 @@ export const Footer: FC = React.memo(() => { }); Footer.displayName = 'Footer'; + +function FooterItem({ item }: { item: FooterLink }) { + const content = item.url ? ( + + {item.text} + + ) : ( + item.text + ); + + return ( + <> + {item.icon && } {content} + + ); +} diff --git a/public/app/features/teams/TeamPages.test.tsx b/public/app/features/teams/TeamPages.test.tsx index df5d5d79ab7..2e165284c12 100644 --- a/public/app/features/teams/TeamPages.test.tsx +++ b/public/app/features/teams/TeamPages.test.tsx @@ -40,6 +40,12 @@ jest.mock('@grafana/runtime', () => ({ bootData: { navTree: [], user: {} }, buildInfo: { edition: 'Open Source', + version: '7.5.0', + commit: 'abc123', + env: 'production', + latestVersion: '', + hasUpdate: false, + hideVersion: false, }, appSubUrl: '', }, @@ -93,7 +99,7 @@ const setup = (propOverrides?: object) => { ); }; -describe('Render', () => { +describe('TeamPages', () => { it('should render member page if team not empty', async () => { setup({ team: getMockTeam(), @@ -123,26 +129,26 @@ describe('Render', () => { expect(await screen.findByText('Team group sync')).toBeInTheDocument(); }); -}); -describe('when feature toggle editorsCanAdmin is turned on', () => { - it('should render settings page if user is team admin', async () => { - setup({ - team: getMockTeam(), - pageName: 'settings', - preferences: { - homeDashboardUID: 'home-dashboard', - theme: 'Default', - timezone: 'Default', - }, - editorsCanAdmin: true, - signedInUser: { - id: 1, - isGrafanaAdmin: false, - orgRole: OrgRole.Admin, - } as User, + describe('when feature toggle editorsCanAdmin is turned on', () => { + it('should render settings page if user is team admin', async () => { + setup({ + team: getMockTeam(), + pageName: 'settings', + preferences: { + homeDashboardUID: 'home-dashboard', + theme: 'Default', + timezone: 'Default', + }, + editorsCanAdmin: true, + signedInUser: { + id: 1, + isGrafanaAdmin: false, + orgRole: OrgRole.Admin, + } as User, + }); + + expect(await screen.findByText('Team settings')).toBeInTheDocument(); }); - - expect(await screen.findByText('Team settings')).toBeInTheDocument(); }); }); diff --git a/public/sass/components/_footer.scss b/public/sass/components/_footer.scss index e3478e93c8c..9300b277150 100644 --- a/public/sass/components/_footer.scss +++ b/public/sass/components/_footer.scss @@ -14,6 +14,7 @@ &:hover { color: $footer-link-hover; + text-decoration: underline; } i {