Data Links: Allow passing data links post processor via context (#110590)
* Data Links: Allow passing data links post processor via context * Deprecate data links post processor in PanelContext * Mark new context as internal
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { isNumber, set, unset, get, cloneDeep } from 'lodash';
|
||||
import { useMemo, useRef } from 'react';
|
||||
import { createContext, useContext, useMemo, useRef } from 'react';
|
||||
import { usePrevious } from 'react-use';
|
||||
|
||||
import { ThresholdsMode, VariableFormatID } from '@grafana/schema';
|
||||
@@ -583,13 +583,14 @@ export function useFieldOverrides(
|
||||
data: PanelData | undefined,
|
||||
timeZone: string,
|
||||
theme: GrafanaTheme2,
|
||||
replace: InterpolateFunction,
|
||||
dataLinkPostProcessor?: DataLinkPostProcessor
|
||||
replace: InterpolateFunction
|
||||
): PanelData | undefined {
|
||||
const fieldConfigRegistry = plugin?.fieldConfigRegistry;
|
||||
const structureRev = useRef(0);
|
||||
const prevSeries = usePrevious(data?.series);
|
||||
|
||||
const { dataLinkPostProcessor } = useDataLinksContext();
|
||||
|
||||
return useMemo(() => {
|
||||
if (!fieldConfigRegistry || !fieldConfig || !data) {
|
||||
return;
|
||||
@@ -650,3 +651,15 @@ export function getFieldDataContextClone(frame: DataFrame, field: Field, fieldSc
|
||||
|
||||
return { value: { frame, field, data: [frame] } };
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const DataLinksContext = createContext<{
|
||||
dataLinkPostProcessor: DataLinkPostProcessor;
|
||||
}>({ dataLinkPostProcessor: defaultInternalLinkPostProcessor });
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const useDataLinksContext = () => useContext(DataLinksContext);
|
||||
|
||||
@@ -150,6 +150,8 @@ export {
|
||||
applyRawFieldOverrides,
|
||||
useFieldOverrides,
|
||||
getFieldDataContextClone,
|
||||
DataLinksContext,
|
||||
useDataLinksContext,
|
||||
} from './field/fieldOverrides';
|
||||
export { getFieldDisplayValuesProxy } from './field/getFieldDisplayValuesProxy';
|
||||
export {
|
||||
|
||||
@@ -96,6 +96,7 @@ export interface PanelContext {
|
||||
/**
|
||||
* Optional supplier for internal data links. If not provided a link pointing to Explore will be generated.
|
||||
* @internal
|
||||
* @deprecated Please use DataLinksContext instead. This property will be removed in next major.
|
||||
*/
|
||||
dataLinkPostProcessor?: DataLinkPostProcessor;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user