mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboard Links: Fix styles for very long dashboard titles (#52443)
This commit is contained in:
parent
3bdec4d138
commit
0142c8ccd1
@ -4363,12 +4363,6 @@ exports[`better eslint`] = {
|
|||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
|
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
|
||||||
],
|
],
|
||||||
"public/app/features/dashboard/components/SubMenu/DashboardLinksDashboard.tsx:5381": [
|
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
|
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
|
|
||||||
],
|
|
||||||
"public/app/features/dashboard/components/SubMenu/SubMenu.tsx:5381": [
|
"public/app/features/dashboard/components/SubMenu/SubMenu.tsx:5381": [
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||||
],
|
],
|
||||||
|
@ -2,6 +2,7 @@ import { css, cx } from '@emotion/css';
|
|||||||
import React, { useRef, useState, useLayoutEffect } from 'react';
|
import React, { useRef, useState, useLayoutEffect } from 'react';
|
||||||
import { useAsync } from 'react-use';
|
import { useAsync } from 'react-use';
|
||||||
|
|
||||||
|
import { GrafanaTheme2 } from '@grafana/data';
|
||||||
import { sanitize, sanitizeUrl } from '@grafana/data/src/text/sanitize';
|
import { sanitize, sanitizeUrl } from '@grafana/data/src/text/sanitize';
|
||||||
import { selectors } from '@grafana/e2e-selectors';
|
import { selectors } from '@grafana/e2e-selectors';
|
||||||
import { Icon, ToolbarButton, Tooltip, useStyles2 } from '@grafana/ui';
|
import { Icon, ToolbarButton, Tooltip, useStyles2 } from '@grafana/ui';
|
||||||
@ -14,7 +15,7 @@ import { DashboardLink } from '../../state/DashboardModel';
|
|||||||
interface Props {
|
interface Props {
|
||||||
link: DashboardLink;
|
link: DashboardLink;
|
||||||
linkInfo: { title: string; href: string };
|
linkInfo: { title: string; href: string };
|
||||||
dashboardId: any;
|
dashboardId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DashboardLinksDashboard: React.FC<Props> = (props) => {
|
export const DashboardLinksDashboard: React.FC<Props> = (props) => {
|
||||||
@ -23,13 +24,7 @@ export const DashboardLinksDashboard: React.FC<Props> = (props) => {
|
|||||||
const [dropdownCssClass, setDropdownCssClass] = useState('invisible');
|
const [dropdownCssClass, setDropdownCssClass] = useState('invisible');
|
||||||
const [opened, setOpened] = useState(0);
|
const [opened, setOpened] = useState(0);
|
||||||
const resolvedLinks = useResolvedLinks(props, opened);
|
const resolvedLinks = useResolvedLinks(props, opened);
|
||||||
|
const styles = useStyles2(getStyles);
|
||||||
const buttonStyle = useStyles2(
|
|
||||||
(theme) =>
|
|
||||||
css`
|
|
||||||
color: ${theme.colors.text.primary};
|
|
||||||
`
|
|
||||||
);
|
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
setDropdownCssClass(getDropdownLocationCssClass(listRef.current));
|
setDropdownCssClass(getDropdownLocationCssClass(listRef.current));
|
||||||
@ -41,17 +36,22 @@ export const DashboardLinksDashboard: React.FC<Props> = (props) => {
|
|||||||
<>
|
<>
|
||||||
<ToolbarButton
|
<ToolbarButton
|
||||||
onClick={() => setOpened(Date.now())}
|
onClick={() => setOpened(Date.now())}
|
||||||
className={cx('gf-form-label gf-form-label--dashlink', buttonStyle)}
|
className={cx('gf-form-label gf-form-label--dashlink', styles.button)}
|
||||||
data-placement="bottom"
|
data-placement="bottom"
|
||||||
data-toggle="dropdown"
|
data-toggle="dropdown"
|
||||||
aria-expanded={!!opened}
|
aria-expanded={!!opened}
|
||||||
aria-controls="dropdown-list"
|
aria-controls="dropdown-list"
|
||||||
aria-haspopup="menu"
|
aria-haspopup="menu"
|
||||||
>
|
>
|
||||||
<Icon aria-hidden name="bars" style={{ marginRight: '4px' }} />
|
<Icon aria-hidden name="bars" className={styles.iconMargin} />
|
||||||
<span>{linkInfo.title}</span>
|
<span>{linkInfo.title}</span>
|
||||||
</ToolbarButton>
|
</ToolbarButton>
|
||||||
<ul id="dropdown-list" className={`dropdown-menu ${dropdownCssClass}`} role="menu" ref={listRef}>
|
<ul
|
||||||
|
id="dropdown-list"
|
||||||
|
className={`dropdown-menu ${styles.dropdown} ${dropdownCssClass}`}
|
||||||
|
role="menu"
|
||||||
|
ref={listRef}
|
||||||
|
>
|
||||||
{resolvedLinks.length > 0 &&
|
{resolvedLinks.length > 0 &&
|
||||||
resolvedLinks.map((resolvedLink, index) => {
|
resolvedLinks.map((resolvedLink, index) => {
|
||||||
return (
|
return (
|
||||||
@ -130,13 +130,13 @@ const useResolvedLinks = ({ link, dashboardId }: Props, opened: number): Resolve
|
|||||||
};
|
};
|
||||||
|
|
||||||
interface ResolvedLinkDTO {
|
interface ResolvedLinkDTO {
|
||||||
id: any;
|
id: number;
|
||||||
url: string;
|
url: string;
|
||||||
title: string;
|
title: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function searchForTags(
|
export async function searchForTags(
|
||||||
tags: any[],
|
tags: string[],
|
||||||
dependencies: { getBackendSrv: typeof getBackendSrv } = { getBackendSrv }
|
dependencies: { getBackendSrv: typeof getBackendSrv } = { getBackendSrv }
|
||||||
): Promise<DashboardSearchHit[]> {
|
): Promise<DashboardSearchHit[]> {
|
||||||
const limit = 100;
|
const limit = 100;
|
||||||
@ -146,7 +146,7 @@ export async function searchForTags(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function resolveLinks(
|
export function resolveLinks(
|
||||||
dashboardId: any,
|
dashboardId: number,
|
||||||
link: DashboardLink,
|
link: DashboardLink,
|
||||||
searchHits: DashboardSearchHit[],
|
searchHits: DashboardSearchHit[],
|
||||||
dependencies: { getLinkSrv: typeof getLinkSrv; sanitize: typeof sanitize; sanitizeUrl: typeof sanitizeUrl } = {
|
dependencies: { getLinkSrv: typeof getLinkSrv; sanitize: typeof sanitize; sanitizeUrl: typeof sanitizeUrl } = {
|
||||||
@ -185,3 +185,24 @@ function getDropdownLocationCssClass(element: HTMLElement | null) {
|
|||||||
return 'pull-right';
|
return 'pull-right';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getStyles(theme: GrafanaTheme2) {
|
||||||
|
return {
|
||||||
|
iconMargin: css({
|
||||||
|
marginRight: theme.spacing(0.5),
|
||||||
|
}),
|
||||||
|
dropdown: css({
|
||||||
|
maxWidth: 'max(30vw, 300px)',
|
||||||
|
maxHeight: '70vh',
|
||||||
|
overflowY: 'auto',
|
||||||
|
a: {
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
button: css({
|
||||||
|
color: theme.colors.text.primary,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user