mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
TimeseriesPanel: Fix variables in data links (#56729)
* TimeseriesPanel: Fix variables in data links * Refactor variable fix for all Timeseries panels * cr mods
This commit is contained in:
@@ -26,3 +26,4 @@ export { PanelPlugin, type SetFieldConfigOptionsArgs, type StandardOptionConfig
|
|||||||
export { createFieldConfigRegistry } from './panel/registryFactories';
|
export { createFieldConfigRegistry } from './panel/registryFactories';
|
||||||
export { type QueryRunner, type QueryRunnerOptions } from './types/queryRunner';
|
export { type QueryRunner, type QueryRunnerOptions } from './types/queryRunner';
|
||||||
export { type GroupingToMatrixTransformerOptions } from './transformations/transformers/groupingToMatrix';
|
export { type GroupingToMatrixTransformerOptions } from './transformations/transformers/groupingToMatrix';
|
||||||
|
export { getLinksSupplier } from './field/fieldOverrides';
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ export class SortedVector<T = any> implements Vector<T> {
|
|||||||
return this.source.get(this.order[index]);
|
return this.source.get(this.order[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getOrderIndex(index: number): number {
|
||||||
|
return this.order[index];
|
||||||
|
}
|
||||||
|
|
||||||
toArray(): T[] {
|
toArray(): T[] {
|
||||||
return vectorToArray(this);
|
return vectorToArray(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import uPlot from 'uplot';
|
import uPlot from 'uplot';
|
||||||
|
|
||||||
import { Field, getDisplayProcessor, PanelProps } from '@grafana/data';
|
import { Field, getDisplayProcessor, PanelProps, getLinksSupplier } from '@grafana/data';
|
||||||
import { PanelDataErrorView } from '@grafana/runtime';
|
import { PanelDataErrorView } from '@grafana/runtime';
|
||||||
import { TooltipDisplayMode } from '@grafana/schema';
|
import { TooltipDisplayMode } from '@grafana/schema';
|
||||||
import { usePanelContext, TimeSeries, TooltipPlugin, ZoomPlugin, UPlotConfigBuilder, useTheme2 } from '@grafana/ui';
|
import { usePanelContext, TimeSeries, TooltipPlugin, ZoomPlugin, UPlotConfigBuilder, useTheme2 } from '@grafana/ui';
|
||||||
@@ -243,6 +243,16 @@ export const CandlestickPanel: React.FC<CandlestickPanelProps> = ({
|
|||||||
options={options}
|
options={options}
|
||||||
>
|
>
|
||||||
{(config, alignedDataFrame) => {
|
{(config, alignedDataFrame) => {
|
||||||
|
alignedDataFrame.fields.forEach((field) => {
|
||||||
|
field.getLinks = getLinksSupplier(
|
||||||
|
alignedDataFrame,
|
||||||
|
field,
|
||||||
|
field.state!.scopedVars!,
|
||||||
|
replaceVariables,
|
||||||
|
timeZone
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ZoomPlugin config={config} onZoom={onChangeTimeRange} />
|
<ZoomPlugin config={config} onZoom={onChangeTimeRange} />
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
|
|
||||||
import { Field, PanelProps } from '@grafana/data';
|
import { Field, PanelProps, getLinksSupplier } from '@grafana/data';
|
||||||
import { PanelDataErrorView } from '@grafana/runtime';
|
import { PanelDataErrorView } from '@grafana/runtime';
|
||||||
import { TooltipDisplayMode } from '@grafana/schema';
|
import { TooltipDisplayMode } from '@grafana/schema';
|
||||||
import { usePanelContext, TimeSeries, TooltipPlugin, ZoomPlugin, KeyboardPlugin } from '@grafana/ui';
|
import { usePanelContext, TimeSeries, TooltipPlugin, ZoomPlugin, KeyboardPlugin } from '@grafana/ui';
|
||||||
@@ -65,6 +65,16 @@ export const TimeSeriesPanel: React.FC<TimeSeriesPanelProps> = ({
|
|||||||
options={options}
|
options={options}
|
||||||
>
|
>
|
||||||
{(config, alignedDataFrame) => {
|
{(config, alignedDataFrame) => {
|
||||||
|
alignedDataFrame.fields.forEach((field) => {
|
||||||
|
field.getLinks = getLinksSupplier(
|
||||||
|
alignedDataFrame,
|
||||||
|
field,
|
||||||
|
field.state!.scopedVars!,
|
||||||
|
replaceVariables,
|
||||||
|
timeZone
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<KeyboardPlugin config={config} />
|
<KeyboardPlugin config={config} />
|
||||||
|
|||||||
@@ -2,7 +2,15 @@ import { css as cssCore, Global } from '@emotion/react';
|
|||||||
import React, { useCallback, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
import React, { useCallback, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { useClickAway } from 'react-use';
|
import { useClickAway } from 'react-use';
|
||||||
|
|
||||||
import { CartesianCoords2D, DataFrame, getFieldDisplayName, InterpolateFunction, TimeZone } from '@grafana/data';
|
import {
|
||||||
|
CartesianCoords2D,
|
||||||
|
DataFrame,
|
||||||
|
getFieldDisplayName,
|
||||||
|
InterpolateFunction,
|
||||||
|
SortedVector,
|
||||||
|
TimeZone,
|
||||||
|
ValueLinkConfig,
|
||||||
|
} from '@grafana/data';
|
||||||
import {
|
import {
|
||||||
ContextMenu,
|
ContextMenu,
|
||||||
GraphContextMenuHeader,
|
GraphContextMenuHeader,
|
||||||
@@ -249,23 +257,27 @@ export const ContextMenuView: React.FC<ContextMenuViewProps> = ({
|
|||||||
|
|
||||||
const hasLinks = field.config.links && field.config.links.length > 0;
|
const hasLinks = field.config.links && field.config.links.length > 0;
|
||||||
|
|
||||||
|
const valueLinkConfig: ValueLinkConfig = {};
|
||||||
|
|
||||||
|
if (field.values instanceof SortedVector) {
|
||||||
|
valueLinkConfig.valueRowIndex = field.values.getOrderIndex(dataIdx);
|
||||||
|
} else {
|
||||||
|
valueLinkConfig.valueRowIndex = dataIdx;
|
||||||
|
}
|
||||||
|
|
||||||
if (hasLinks) {
|
if (hasLinks) {
|
||||||
if (field.getLinks) {
|
if (field.getLinks) {
|
||||||
items.push({
|
items.push({
|
||||||
items: field
|
items: field.getLinks(valueLinkConfig).map<MenuItemProps>((link) => {
|
||||||
.getLinks({
|
return {
|
||||||
valueRowIndex: dataIdx,
|
label: link.title,
|
||||||
})
|
ariaLabel: link.title,
|
||||||
.map<MenuItemProps>((link) => {
|
url: link.href,
|
||||||
return {
|
target: link.target,
|
||||||
label: link.title,
|
icon: link.target === '_self' ? 'link' : 'external-link-alt',
|
||||||
ariaLabel: link.title,
|
onClick: link.onClick,
|
||||||
url: link.href,
|
};
|
||||||
target: link.target,
|
}),
|
||||||
icon: link.target === '_self' ? 'link' : 'external-link-alt',
|
|
||||||
onClick: link.onClick,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user