mirror of https://github.com/grafana/grafana
Frontend: Make datalinks work with status history and state timeline (#50226)
* fix datalinks for state and status panels * Add close button on tooltip * fix links from all series displayed in tooltip * Allow annotations creation, tweak UI * Nits * Remove unused property * fix returns made from review * setupUPlotConfig renamed to addTooltipSupport Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com> Co-authored-by: Victor Marin <victor.marin@grafana.com>pull/52728/head^2
parent
c56aae6f63
commit
2054414d37
@ -0,0 +1,94 @@ |
||||
import React from 'react'; |
||||
|
||||
import { |
||||
DataFrame, |
||||
FALLBACK_COLOR, |
||||
Field, |
||||
getDisplayProcessor, |
||||
getFieldDisplayName, |
||||
TimeZone, |
||||
LinkModel, |
||||
} from '@grafana/data'; |
||||
import { MenuItem, SeriesTableRow, useTheme2 } from '@grafana/ui'; |
||||
|
||||
interface StatusHistoryTooltipProps { |
||||
data: DataFrame[]; |
||||
alignedData: DataFrame; |
||||
seriesIdx: number; |
||||
datapointIdx: number; |
||||
timeZone: TimeZone; |
||||
} |
||||
|
||||
export const StatusHistoryTooltip: React.FC<StatusHistoryTooltipProps> = ({ |
||||
data, |
||||
alignedData, |
||||
seriesIdx, |
||||
datapointIdx, |
||||
timeZone, |
||||
}) => { |
||||
const theme = useTheme2(); |
||||
|
||||
if (!data || datapointIdx == null) { |
||||
return null; |
||||
} |
||||
|
||||
const field = alignedData.fields[seriesIdx!]; |
||||
|
||||
const links: Array<LinkModel<Field>> = []; |
||||
const linkLookup = new Set<string>(); |
||||
|
||||
if (field.getLinks) { |
||||
const v = field.values.get(datapointIdx); |
||||
const disp = field.display ? field.display(v) : { text: `${v}`, numeric: +v }; |
||||
field.getLinks({ calculatedValue: disp, valueRowIndex: datapointIdx }).forEach((link) => { |
||||
const key = `${link.title}/${link.href}`; |
||||
if (!linkLookup.has(key)) { |
||||
links.push(link); |
||||
linkLookup.add(key); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
const dataFrameFieldIndex = field.state?.origin; |
||||
const fieldFmt = field.display || getDisplayProcessor({ field, timeZone, theme }); |
||||
const value = field.values.get(datapointIdx!); |
||||
const display = fieldFmt(value); |
||||
const fieldDisplayName = dataFrameFieldIndex |
||||
? getFieldDisplayName( |
||||
data[dataFrameFieldIndex.frameIndex].fields[dataFrameFieldIndex.fieldIndex], |
||||
data[dataFrameFieldIndex.frameIndex], |
||||
data |
||||
) |
||||
: null; |
||||
|
||||
return ( |
||||
<div> |
||||
<div style={{ fontSize: theme.typography.bodySmall.fontSize }}> |
||||
{fieldDisplayName} |
||||
<br /> |
||||
<SeriesTableRow label={display.text} color={display.color || FALLBACK_COLOR} isActive /> |
||||
</div> |
||||
{links.length > 0 && ( |
||||
<div |
||||
style={{ |
||||
margin: theme.spacing(1, -1, -1, -1), |
||||
borderTop: `1px solid ${theme.colors.border.weak}`, |
||||
}} |
||||
> |
||||
{links.map((link, i) => ( |
||||
<MenuItem |
||||
key={i} |
||||
icon={'external-link-alt'} |
||||
target={link.target} |
||||
label={link.title} |
||||
url={link.href} |
||||
onClick={link.onClick} |
||||
/> |
||||
))} |
||||
</div> |
||||
)} |
||||
</div> |
||||
); |
||||
}; |
||||
|
||||
StatusHistoryTooltip.displayName = 'StatusHistoryTooltip'; |
Loading…
Reference in new issue