From a546db4b3a8267a2da25e7e36a14a0df1eb9e58d Mon Sep 17 00:00:00 2001 From: Laura Benz <48948963+L-M-K-B@users.noreply.github.com> Date: Tue, 17 Oct 2023 10:34:44 +0200 Subject: [PATCH] Nav: Remove and refactor MegaMenu and its sub-components (#76614) * refactor: remove hasActiveChild * refactor: remove unused properties from MegeMenuItemText * refactor: remove MegaMenuItemIcon * refactor after code review --- .../AppChrome/DockedMegaMenu/MegaMenuItem.tsx | 11 ++---- .../DockedMegaMenu/MegaMenuItemIcon.tsx | 38 ------------------- .../DockedMegaMenu/MegaMenuItemText.tsx | 23 +++-------- 3 files changed, 9 insertions(+), 63 deletions(-) delete mode 100644 public/app/core/components/AppChrome/DockedMegaMenu/MegaMenuItemIcon.tsx diff --git a/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenuItem.tsx b/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenuItem.tsx index c733f0bc0ed..1179ceed2fb 100644 --- a/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenuItem.tsx +++ b/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenuItem.tsx @@ -2,13 +2,12 @@ import { css, cx } from '@emotion/css'; import React from 'react'; import { useLocalStorage } from 'react-use'; -import { GrafanaTheme2, NavModelItem } from '@grafana/data'; +import { GrafanaTheme2, NavModelItem, toIconName } from '@grafana/data'; import { Button, Icon, useStyles2, Text } from '@grafana/ui'; import { Indent } from '../../Indent/Indent'; import { FeatureHighlight } from './FeatureHighlight'; -import { MegaMenuItemIcon } from './MegaMenuItemIcon'; import { MegaMenuItemText } from './MegaMenuItemText'; import { hasChildMatch } from './utils'; @@ -46,11 +45,12 @@ export function MegaMenuItem({ link, activeItem, level = 0, onClick }: Props) {
-
{level === 0 && }
+
+ {level === 0 && link.icon && } +
{link.text} @@ -143,9 +143,6 @@ const getStyles = (theme: GrafanaTheme2) => ({ backgroundImage: theme.colors.gradients.brandVertical, }, }), - hasActiveChild: css({ - color: theme.colors.text.primary, - }), }); function linkHasChildren(link: NavModelItem): link is NavModelItem & { children: NavModelItem[] } { diff --git a/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenuItemIcon.tsx b/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenuItemIcon.tsx deleted file mode 100644 index b33f616fa7b..00000000000 --- a/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenuItemIcon.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import { css, cx } from '@emotion/css'; -import React from 'react'; - -import { GrafanaTheme2, NavModelItem } from '@grafana/data'; -import { Icon, toIconName, useTheme2 } from '@grafana/ui'; - -import { Branding } from '../../Branding/Branding'; - -interface NavBarItemIconProps { - link: NavModelItem; -} - -export function MegaMenuItemIcon({ link }: NavBarItemIconProps) { - const theme = useTheme2(); - const styles = getStyles(theme); - - if (link.icon === 'grafana') { - return ; - } else if (link.icon) { - const iconName = toIconName(link.icon); - return ; - } else { - // consumer of NavBarItemIcon gives enclosing element an appropriate label - return ; - } -} - -function getStyles(theme: GrafanaTheme2) { - return { - img: css({ - height: theme.spacing(3), - width: theme.spacing(3), - }), - round: css({ - borderRadius: theme.shape.radius.circle, - }), - }; -} diff --git a/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenuItemText.tsx b/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenuItemText.tsx index ec0480a0d8c..08c511d8364 100644 --- a/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenuItemText.tsx +++ b/public/app/core/components/AppChrome/DockedMegaMenu/MegaMenuItemText.tsx @@ -3,26 +3,22 @@ import React from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { selectors } from '@grafana/e2e-selectors'; -import { Icon, IconName, Link, useTheme2 } from '@grafana/ui'; +import { Icon, Link, useTheme2 } from '@grafana/ui'; export interface Props { children: React.ReactNode; - icon?: IconName; isActive?: boolean; - isChild?: boolean; onClick?: () => void; target?: HTMLAnchorElement['target']; url?: string; } -export function MegaMenuItemText({ children, icon, isActive, isChild, onClick, target, url }: Props) { +export function MegaMenuItemText({ children, isActive, onClick, target, url }: Props) { const theme = useTheme2(); - const styles = getStyles(theme, isActive, isChild); + const styles = getStyles(theme, isActive); const linkContent = (
- {icon && } - {children} {target === '_blank' && ( @@ -71,7 +67,7 @@ export function MegaMenuItemText({ children, icon, isActive, isChild, onClick, t MegaMenuItemText.displayName = 'MegaMenuItemText'; -const getStyles = (theme: GrafanaTheme2, isActive: Props['isActive'], isChild: Props['isActive']) => ({ +const getStyles = (theme: GrafanaTheme2, isActive: Props['isActive']) => ({ button: css({ backgroundColor: 'unset', borderStyle: 'unset', @@ -91,15 +87,9 @@ const getStyles = (theme: GrafanaTheme2, isActive: Props['isActive'], isChild: P boxSizing: 'border-box', position: 'relative', color: isActive ? theme.colors.text.primary : theme.colors.text.secondary, - padding: theme.spacing(1, 1, 1, isChild ? 5 : 0), - ...(isChild && { - borderRadius: theme.shape.radius.default, - }), + padding: theme.spacing(1, 1, 1, 0), width: '100%', '&:hover, &:focus-visible': { - ...(isChild && { - background: theme.colors.emphasize(theme.colors.background.primary, 0.03), - }), textDecoration: 'underline', color: theme.colors.text.primary, }, @@ -127,8 +117,5 @@ const getStyles = (theme: GrafanaTheme2, isActive: Props['isActive'], isChild: P position: 'relative', display: 'flex', width: '100%', - ...(isChild && { - padding: theme.spacing(0, 2), - }), }), });