mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: add selector for items in the megamenu (#65633)
add selector for items in the megamenu
This commit is contained in:
@@ -247,6 +247,9 @@ export const Components = {
|
|||||||
button: 'Reporting',
|
button: 'Reporting',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
NavMenu: {
|
||||||
|
item: 'data-testid Nav menu item',
|
||||||
|
},
|
||||||
NavToolbar: {
|
NavToolbar: {
|
||||||
container: 'data-testid Nav toolbar',
|
container: 'data-testid Nav toolbar',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { css, cx } from '@emotion/css';
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { GrafanaTheme2 } from '@grafana/data';
|
import { GrafanaTheme2 } from '@grafana/data';
|
||||||
|
import { selectors } from '@grafana/e2e-selectors';
|
||||||
import { Icon, IconName, Link, useTheme2 } from '@grafana/ui';
|
import { Icon, IconName, Link, useTheme2 } from '@grafana/ui';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
@@ -31,7 +32,11 @@ export function NavBarMenuItem({ children, icon, isActive, isChild, onClick, tar
|
|||||||
);
|
);
|
||||||
|
|
||||||
let element = (
|
let element = (
|
||||||
<button className={cx(styles.button, styles.element)} onClick={onClick}>
|
<button
|
||||||
|
data-testid={selectors.components.NavMenu.item}
|
||||||
|
className={cx(styles.button, styles.element)}
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
{linkContent}
|
{linkContent}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
@@ -39,11 +44,23 @@ export function NavBarMenuItem({ children, icon, isActive, isChild, onClick, tar
|
|||||||
if (url) {
|
if (url) {
|
||||||
element =
|
element =
|
||||||
!target && url.startsWith('/') ? (
|
!target && url.startsWith('/') ? (
|
||||||
<Link className={styles.element} href={url} target={target} onClick={onClick}>
|
<Link
|
||||||
|
data-testid={selectors.components.NavMenu.item}
|
||||||
|
className={styles.element}
|
||||||
|
href={url}
|
||||||
|
target={target}
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
{linkContent}
|
{linkContent}
|
||||||
</Link>
|
</Link>
|
||||||
) : (
|
) : (
|
||||||
<a href={url} target={target} className={styles.element} onClick={onClick}>
|
<a
|
||||||
|
data-testid={selectors.components.NavMenu.item}
|
||||||
|
href={url}
|
||||||
|
target={target}
|
||||||
|
className={styles.element}
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
{linkContent}
|
{linkContent}
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user