Skip to content

Commit 3b25e72

Browse files
tooltip, icons fix
1 parent 67305b3 commit 3b25e72

File tree

13 files changed

+3321
-4386
lines changed

13 files changed

+3321
-4386
lines changed

.coderabbit.yaml

Lines changed: 0 additions & 20 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"version": "11.3.0-pre",
77
"repository": "github:grafana/grafana",
88
"scripts": {
9-
"build": "NODE_ENV=dev nx exec --verbose -- webpack --config scripts/webpack/webpack.prod.js",
9+
"build": "NODE_ENV=production nx exec --verbose -- webpack --config scripts/webpack/webpack.prod.js",
1010
"build:nominify": "yarn run build -- --env noMinify=1",
1111
"dev": "NODE_ENV=dev nx exec -- webpack --config scripts/webpack/webpack.dev.js",
1212
"e2e": "./e2e/start-and-run-suite",

packages/grafana-ui/src/components/DateTimePickers/TimeRangePicker/TimeRangeContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ export const TimeRangeContent = (props: Props) => {
218218
type="button"
219219
onClick={onApply}
220220
style={{
221-
width: '100%',
221+
width: 193,
222222
textAlign: 'center',
223-
paddingLeft: '55px',
223+
paddingLeft: 45,
224224
}}
225225
>
226226
<Trans i18nKey="time-picker.range-content.apply-button">Apply time range</Trans>

packages/grafana-ui/src/components/Dropdown/ButtonSelect.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ const getStyles = (theme: GrafanaTheme2) => {
128128
}),
129129
menuWrapper: css({
130130
zIndex: theme.zIndex.dropdown,
131+
marginLeft: -25,
131132
}),
132133
};
133134
};

packages/grafana-ui/src/components/Icon/Icon.tsx

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const getIconStyles = (theme: GrafanaTheme2) => {
4242
};
4343
};
4444

45+
const cachedIcon = new Map<string, string>();
4546
export const Icon = React.forwardRef<SVGElement, IconProps>(
4647
({ size = 'md', type = 'default', name, className, style, title = '', ...rest }, ref) => {
4748
const styles = useStyles2(getIconStyles);
@@ -58,7 +59,28 @@ export const Icon = React.forwardRef<SVGElement, IconProps>(
5859
const svgHgt = svgSize;
5960
const svgWid = name.startsWith('gf-bar-align') ? 16 : name.startsWith('gf-interp') ? 30 : svgSize;
6061
const subDir = getIconSubDir(iconName, type);
61-
const svgPath = `${iconRoot}${subDir}/${iconName}.svg`;
62+
const [svgPath, setSvgPath] = React.useState<string | null | undefined>(null);
63+
64+
React.useEffect(() => {
65+
const iconPath = `${iconRoot}${subDir}/${iconName}.svg`;
66+
if (cachedIcon.has(iconPath)) {
67+
setSvgPath(cachedIcon.get(iconPath));
68+
return;
69+
}
70+
/**
71+
* For microfrontend, all the Grafana routes are behind the proxy, so we need to fetch the icon from the proxy.
72+
* When we use fetch request get intercepted and url is changed to the proxy url.
73+
*/
74+
fetch(iconPath).then(async (response) => {
75+
if (response.ok) {
76+
const icon = await response.text();
77+
cachedIcon.set(iconPath, icon);
78+
setSvgPath(icon);
79+
} else {
80+
console.error(`Icon ${iconName} not found`);
81+
}
82+
});
83+
}, [iconName, iconRoot, subDir]);
6284

6385
const composedClassName = cx(
6486
styles.icon,
@@ -70,23 +92,27 @@ export const Icon = React.forwardRef<SVGElement, IconProps>(
7092
);
7193

7294
return (
73-
<SVG
74-
aria-hidden={
75-
rest.tabIndex === undefined &&
76-
!title &&
77-
!rest['aria-label'] &&
78-
!rest['aria-labelledby'] &&
79-
!rest['aria-describedby']
80-
}
81-
innerRef={ref}
82-
src={svgPath}
83-
width={svgWid}
84-
height={svgHgt}
85-
title={title}
86-
className={composedClassName}
87-
style={style}
88-
{...rest}
89-
/>
95+
<>
96+
{svgPath && (
97+
<SVG
98+
aria-hidden={
99+
rest.tabIndex === undefined &&
100+
!title &&
101+
!rest['aria-label'] &&
102+
!rest['aria-labelledby'] &&
103+
!rest['aria-describedby']
104+
}
105+
innerRef={ref}
106+
src={svgPath}
107+
width={svgWid}
108+
height={svgHgt}
109+
title={title}
110+
className={composedClassName}
111+
style={style}
112+
{...rest}
113+
/>
114+
)}
115+
</>
90116
);
91117
}
92118
);

packages/grafana-ui/src/components/uPlot/plugins/TooltipPlugin2.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { css, cx } from '@emotion/css';
22
import { useLayoutEffect, useRef, useReducer, CSSProperties } from 'react';
33
import * as React from 'react';
4-
import { createPortal } from 'react-dom';
54
import uPlot from 'uplot';
65

76
import { GrafanaTheme2 } from '@grafana/data';
87
import { DashboardCursorSync } from '@grafana/schema';
98

109
import { useStyles2 } from '../../../themes';
1110
import { RangeSelection1D, RangeSelection2D, OnSelectRangeCallback } from '../../PanelChrome';
12-
import { getPortalContainer } from '../../Portal/Portal';
11+
import { getPortalContainer, Portal } from '../../Portal/Portal';
1312
import { UPlotConfigBuilder } from '../config/UPlotConfigBuilder';
1413

1514
import { CloseButton } from './CloseButton';
@@ -651,18 +650,18 @@ export const TooltipPlugin2 = ({
651650
}, [isHovering]);
652651

653652
if (plot && isHovering) {
654-
return createPortal(
655-
<div
656-
className={cx(styles.tooltipWrapper, isPinned && styles.pinned)}
657-
style={style}
658-
aria-live="polite"
659-
aria-atomic="true"
660-
ref={domRef}
661-
>
662-
{isPinned && <CloseButton onClick={dismiss} />}
663-
{contents}
664-
</div>,
665-
portalRoot.current
653+
return (
654+
<Portal>
655+
<div
656+
className={cx(styles.tooltipWrapper, isPinned && styles.pinned)}
657+
aria-live="polite"
658+
aria-atomic="true"
659+
ref={domRef}
660+
>
661+
{isPinned && <CloseButton onClick={dismiss} />}
662+
{contents}
663+
</div>
664+
</Portal>
666665
);
667666
}
668667

0 commit comments

Comments
 (0)