From 45837728045b6ac651a6211d63b276cfdcddb449 Mon Sep 17 00:00:00 2001 From: Jonathan Ash Date: Fri, 25 Feb 2022 10:16:28 +0000 Subject: [PATCH] - Switched out MUI with Backstage to handle external links Signed-off-by: Jonathan Ash --- .../src/layout/Sidebar/SidebarSubmenuItem.tsx | 14 ++------------ .../src/layout/Sidebar/utils.test.ts | 12 ------------ .../core-components/src/layout/Sidebar/utils.ts | 2 -- 3 files changed, 2 insertions(+), 26 deletions(-) diff --git a/packages/core-components/src/layout/Sidebar/SidebarSubmenuItem.tsx b/packages/core-components/src/layout/Sidebar/SidebarSubmenuItem.tsx index a0ecc75918..d204728bcf 100644 --- a/packages/core-components/src/layout/Sidebar/SidebarSubmenuItem.tsx +++ b/packages/core-components/src/layout/Sidebar/SidebarSubmenuItem.tsx @@ -14,15 +14,10 @@ * limitations under the License. */ import React, { useContext, useState } from 'react'; -import { - NavLink, - resolvePath, - useLocation, - useResolvedPath, -} from 'react-router-dom'; +import { resolvePath, useLocation, useResolvedPath } from 'react-router-dom'; import { makeStyles } from '@material-ui/core/styles'; import Typography from '@material-ui/core/Typography'; -import Link from '@material-ui/core/Link'; +import { Link } from '../../components/Link'; import { IconComponent } from '@backstage/core-plugin-api'; import classnames from 'classnames'; import { BackstageTheme } from '@backstage/theme'; @@ -30,8 +25,6 @@ import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown'; import ArrowDropUpIcon from '@material-ui/icons/ArrowDropUp'; import { SidebarItemWithSubmenuContext } from './config'; import { isLocationMatch } from './utils'; -import { Link as BackstageLink } from '../../components/Link'; -import { isExternalLink } from './utils'; const useStyles = makeStyles(theme => ({ item: { @@ -135,7 +128,6 @@ export const SidebarSubmenuItem = (props: SidebarSubmenuItemProps) => { const handleClickDropdown = () => { setShowDropDown(!showDropDown); }; - if (dropdownItems !== undefined) { dropdownItems.some(item => { const resolvedPath = resolvePath(item.to); @@ -166,7 +158,6 @@ export const SidebarSubmenuItem = (props: SidebarSubmenuItemProps) => {
{dropdownItems.map((object, key) => ( { return (
{ expect(isLocationMatch(currentLocation, toLocation)).toBe(true); }); }); - -describe('isExternalLink', () => { - beforeEach(() => expect.hasAssertions()); - - it('should return true if provided with an external link', () => { - expect(isExternalLink('https://backstage.io/')).toEqual(true); - }); - - it('should return false if provided with a relative link', () => { - expect(isExternalLink('catalog')).toEqual(false); - }); -}); diff --git a/packages/core-components/src/layout/Sidebar/utils.ts b/packages/core-components/src/layout/Sidebar/utils.ts index 0c586ee3b3..1afebe796d 100644 --- a/packages/core-components/src/layout/Sidebar/utils.ts +++ b/packages/core-components/src/layout/Sidebar/utils.ts @@ -33,5 +33,3 @@ export function isLocationMatch(currentLocation: Location, toLocation: Path) { return matching; } - -export const isExternalLink = (link: string) => /^https?:/.test(link);