Update heatmap exemplar popover styles (#59988)

* Put traceID on top

* Update exemplar popover styles

* Remove console.log

* Make exemplar header opt-in via optional prop

Co-authored-by: nmarrs <nathanielmarrs@gmail.com>
This commit is contained in:
ismail simsek 2022-12-08 21:55:39 +03:00 committed by GitHub
parent a83268db7b
commit 29d2f86955
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 81 additions and 31 deletions

View File

@ -24,5 +24,5 @@ export const DataHoverRow = ({ feature }: Props) => {
data = new ArrayDataFrame([properties]); data = new ArrayDataFrame([properties]);
} }
return <DataHoverView data={data} rowIndex={rowIndex} />; return <DataHoverView data={data} rowIndex={rowIndex} displayExemplarHeader={false} />;
}; };

View File

@ -19,25 +19,36 @@ export interface Props {
columnIndex?: number | null; // the hover column columnIndex?: number | null; // the hover column
sortOrder?: SortOrder; sortOrder?: SortOrder;
mode?: TooltipDisplayMode | null; mode?: TooltipDisplayMode | null;
displayExemplarHeader?: boolean;
} }
export const DataHoverView = ({ data, rowIndex, columnIndex, sortOrder, mode }: Props) => { export const DataHoverView = ({
data,
rowIndex,
columnIndex,
sortOrder,
mode,
displayExemplarHeader = true,
}: Props) => {
const styles = useStyles2(getStyles); const styles = useStyles2(getStyles);
if (!data || rowIndex == null) { if (!data || rowIndex == null) {
return null; return null;
} }
// Put the traceID field in front.
const visibleFields = data.fields.filter((f) => !Boolean(f.config.custom?.hideFrom?.tooltip)); const visibleFields = data.fields.filter((f) => !Boolean(f.config.custom?.hideFrom?.tooltip));
const traceIDField = visibleFields.find((field) => field.name === 'traceID') || data.fields[0];
const orderedVisibleFields = [traceIDField, ...visibleFields.filter((field) => traceIDField !== field)];
if (visibleFields.length === 0) { if (orderedVisibleFields.length === 0) {
return null; return null;
} }
const displayValues: Array<[string, unknown, string]> = []; const displayValues: Array<[string, unknown, string]> = [];
const links: Record<string, Array<LinkModel<Field>>> = {}; const links: Record<string, Array<LinkModel<Field>>> = {};
for (const f of visibleFields) { for (const f of orderedVisibleFields) {
const v = f.values.get(rowIndex); const v = f.values.get(rowIndex);
const disp = f.display ? f.display(v) : { text: `${v}`, numeric: +v }; const disp = f.display ? f.display(v) : { text: `${v}`, numeric: +v };
if (f.getLinks) { if (f.getLinks) {
@ -58,23 +69,30 @@ export const DataHoverView = ({ data, rowIndex, columnIndex, sortOrder, mode }:
} }
return ( return (
<table className={styles.infoWrap}> <div className={styles.wrapper}>
<tbody> {displayExemplarHeader && (
{(mode === TooltipDisplayMode.Multi || mode == null) && <div className={styles.header}>
displayValues.map((v, i) => ( <span className={styles.title}>Exemplar</span>
<tr key={`${i}/${rowIndex}`} className={i === columnIndex ? styles.highlight : ''}> </div>
<th>{v[0]}:</th> )}
<td>{renderWithLinks(v[0], v[2], links)}</td> <table className={styles.infoWrap}>
<tbody>
{(mode === TooltipDisplayMode.Multi || mode == null) &&
displayValues.map((v, i) => (
<tr key={`${i}/${rowIndex}`} className={i === columnIndex ? styles.highlight : ''}>
<th>{v[0]}:</th>
<td>{renderWithLinks(v[0], v[2], links)}</td>
</tr>
))}
{mode === TooltipDisplayMode.Single && columnIndex && (
<tr key={`${columnIndex}/${rowIndex}`}>
<th>{displayValues[columnIndex][0]}:</th>
<td>{renderWithLinks(displayValues[columnIndex][0], displayValues[columnIndex][2], links)}</td>
</tr> </tr>
))} )}
{mode === TooltipDisplayMode.Single && columnIndex && ( </tbody>
<tr key={`${columnIndex}/${rowIndex}`}> </table>
<th>{displayValues[columnIndex][0]}:</th> </div>
<td>{renderWithLinks(displayValues[columnIndex][0], displayValues[columnIndex][2], links)}</td>
</tr>
)}
</tbody>
</table>
); );
}; };
@ -102,15 +120,46 @@ const renderWithLinks = (key: string, val: string, links: Record<string, Array<L
<>{val}</> <>{val}</>
); );
const getStyles = (theme: GrafanaTheme2) => ({ const getStyles = (theme: GrafanaTheme2) => {
infoWrap: css` const bg = theme.isDark ? theme.v1.palette.dark2 : theme.v1.palette.white;
padding: 8px; const headerBg = theme.isDark ? theme.v1.palette.dark9 : theme.v1.palette.gray5;
th { const tableBgOdd = theme.isDark ? theme.v1.palette.dark3 : theme.v1.palette.gray6;
return {
wrapper: css`
background: ${bg};
border: 1px solid ${headerBg};
border-radius: ${theme.shape.borderRadius(2)};
`,
header: css`
background: ${headerBg};
padding: 6px 10px;
display: flex;
`,
title: css`
font-weight: ${theme.typography.fontWeightMedium}; font-weight: ${theme.typography.fontWeightMedium};
padding: ${theme.spacing(0.25, 2)}; padding-right: ${theme.spacing(2)};
} overflow: hidden;
`, display: inline-block;
highlight: css` white-space: nowrap;
background: ${theme.colors.action.hover}; text-overflow: ellipsis;
`, flex-grow: 1;
}); `,
infoWrap: css`
padding: 8px;
th {
font-weight: ${theme.typography.fontWeightMedium};
padding: ${theme.spacing(0.25, 2)};
}
tr {
background-color: ${theme.colors.background.primary};
&:nth-child(even) {
background-color: ${tableBgOdd};
}
}
`,
highlight: css`
background: ${theme.colors.action.hover};
`,
};
};

View File

@ -212,6 +212,7 @@ export const HeatmapPanel: React.FC<HeatmapPanelProps> = ({
width: '100%', width: '100%',
display: 'flex', display: 'flex',
justifyContent: 'flex-end', justifyContent: 'flex-end',
paddingBottom: '6px',
}} }}
> >
<CloseButton <CloseButton