display generated refID if exists, but do not persist it
This commit is contained in:
@@ -268,7 +268,7 @@ export { fuzzySearch } from './utils/fuzzySearch';
|
||||
|
||||
// Transformations
|
||||
export { standardTransformers } from './transformations/transformers';
|
||||
export { getTransformationLegacyRefId } from './transformations/transformers/utils';
|
||||
export { getTransformationDynamicRefId } from './transformations/transformers/utils';
|
||||
export {
|
||||
fieldMatchers,
|
||||
frameMatchers,
|
||||
|
||||
@@ -7,7 +7,7 @@ import { FieldMatcherID } from '../matchers/ids';
|
||||
|
||||
import { DataTransformerID } from './ids';
|
||||
import { joinDataFrames } from './joinDataFrames';
|
||||
import { getTransformationLegacyRefId } from './utils';
|
||||
import { getTransformationDynamicRefId } from './utils';
|
||||
|
||||
export enum JoinMode {
|
||||
outer = 'outer', // best for time series, non duplicated join on values
|
||||
@@ -44,11 +44,13 @@ export const joinByFieldTransformer: SynchronousDataTransformerInfo<JoinByFieldO
|
||||
}
|
||||
const joined = joinDataFrames({ frames: data, joinBy, mode: options.mode });
|
||||
if (joined) {
|
||||
joined.refId = options.refId ?? getTransformationLegacyRefId(DataTransformerID.joinByField, data);
|
||||
joined.refId = options.refId ?? getTransformationDynamicRefId(DataTransformerID.joinByField, data);
|
||||
return [joined];
|
||||
}
|
||||
}
|
||||
return data;
|
||||
};
|
||||
},
|
||||
|
||||
usesDynamicRefId: true,
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ import { DataFrame, Field } from '../../types/dataFrame';
|
||||
import { DataTransformerInfo, TransformationApplicabilityLevels } from '../../types/transformations';
|
||||
|
||||
import { DataTransformerID } from './ids';
|
||||
import { getTransformationLegacyRefId } from './utils';
|
||||
import { getTransformationDynamicRefId } from './utils';
|
||||
|
||||
interface ValuePointer {
|
||||
key: string;
|
||||
@@ -47,7 +47,7 @@ export const mergeTransformer: DataTransformerInfo<MergeTransformerOptions> = {
|
||||
const fieldIndexByName: Record<string, Record<number, number>> = {};
|
||||
const fieldNamesForKey: string[] = [];
|
||||
const dataFrame = new MutableDataFrame({
|
||||
refId: options.refId ?? getTransformationLegacyRefId(DataTransformerID.merge, data),
|
||||
refId: options.refId ?? getTransformationDynamicRefId(DataTransformerID.merge, data),
|
||||
fields: [],
|
||||
});
|
||||
|
||||
@@ -125,6 +125,7 @@ export const mergeTransformer: DataTransformerInfo<MergeTransformerOptions> = {
|
||||
return [dataFrame];
|
||||
})
|
||||
),
|
||||
usesDynamicRefId: true,
|
||||
};
|
||||
|
||||
const copyFieldStructure = (field: Field): Field => {
|
||||
|
||||
@@ -10,7 +10,7 @@ import { getFieldMatcher } from '../matchers';
|
||||
import { alwaysFieldMatcher, notTimeFieldMatcher } from '../matchers/predicates';
|
||||
|
||||
import { DataTransformerID } from './ids';
|
||||
import { getTransformationLegacyRefId } from './utils';
|
||||
import { getTransformationDynamicRefId } from './utils';
|
||||
|
||||
export enum ReduceTransformerMode {
|
||||
SeriesToRows = 'seriesToRows', // default
|
||||
@@ -62,12 +62,13 @@ export const reduceTransformer: DataTransformerInfo<ReduceTransformerOptions> =
|
||||
? [
|
||||
{
|
||||
...res,
|
||||
refId: options.refId ?? getTransformationLegacyRefId(DataTransformerID.reduce, data),
|
||||
refId: options.refId ?? getTransformationDynamicRefId(DataTransformerID.reduce, data),
|
||||
},
|
||||
]
|
||||
: [];
|
||||
})
|
||||
),
|
||||
usesDynamicRefId: true,
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
import { DataTransformerInfo } from '../../types/transformations';
|
||||
|
||||
import { DataTransformerID } from './ids';
|
||||
import { getTransformationLegacyRefId } from './utils';
|
||||
import { getTransformationDynamicRefId } from './utils';
|
||||
|
||||
export interface SeriesToRowsTransformerOptions {
|
||||
refId?: string;
|
||||
@@ -41,7 +41,7 @@ export const seriesToRowsTransformer: DataTransformerInfo<SeriesToRowsTransforme
|
||||
const timeFieldByIndex: Record<number, number> = {};
|
||||
const targetFields = new Set<string>();
|
||||
const dataFrame = new MutableDataFrame({
|
||||
refId: options.refId ?? getTransformationLegacyRefId(DataTransformerID.seriesToRows, data),
|
||||
refId: options.refId ?? getTransformationDynamicRefId(DataTransformerID.seriesToRows, data),
|
||||
fields: [],
|
||||
});
|
||||
const metricField: Field = {
|
||||
@@ -93,6 +93,7 @@ export const seriesToRowsTransformer: DataTransformerInfo<SeriesToRowsTransforme
|
||||
return [sortDataFrame(dataFrame, 0, true)];
|
||||
})
|
||||
),
|
||||
usesDynamicRefId: true,
|
||||
};
|
||||
|
||||
const copyFieldStructure = (field: Field, name: string): Field => {
|
||||
|
||||
@@ -34,6 +34,6 @@ export function getSpecialValue(specialValue: SpecialValue) {
|
||||
}
|
||||
}
|
||||
|
||||
export const getTransformationLegacyRefId = (transformationId: string, data: DataFrame[]) => {
|
||||
export const getTransformationDynamicRefId = (transformationId: string, data: DataFrame[]) => {
|
||||
return `${transformationId}-${data.map((frame) => frame.refId).join('-')}`;
|
||||
};
|
||||
|
||||
@@ -55,6 +55,10 @@ export interface DataTransformerInfo<TOptions = any> extends RegistryItemWithOpt
|
||||
* This way descriptions can be tailored relative to the underlying data.
|
||||
*/
|
||||
isApplicableDescription?: string | ((data: DataFrame[]) => string);
|
||||
/**
|
||||
* Does the transformation generate a dataframe and thus generates a refID automatically based on incoming data
|
||||
*/
|
||||
usesDynamicRefId?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+4
@@ -10,6 +10,7 @@ import {
|
||||
getFrameMatchers,
|
||||
transformDataFrame,
|
||||
DataFrame,
|
||||
getTransformationDynamicRefId,
|
||||
} from '@grafana/data';
|
||||
import { selectors } from '@grafana/e2e-selectors';
|
||||
import { t } from '@grafana/i18n';
|
||||
@@ -61,6 +62,8 @@ export const TransformationOperationRow = ({
|
||||
// output of previous transformation
|
||||
const [prevOutput, setPrevOutput] = useState<DataFrame[]>([]);
|
||||
|
||||
const dynamicRefId = getTransformationDynamicRefId(uiConfig.id, data.series);
|
||||
|
||||
const onDisableToggle = useCallback(
|
||||
(index: number) => {
|
||||
const current = configs[index].transformation;
|
||||
@@ -167,6 +170,7 @@ export const TransformationOperationRow = ({
|
||||
transformationTypeName={`${index + 1} - ${uiConfig.name}`}
|
||||
disabled
|
||||
onChange={onChange}
|
||||
dynamicRefId={uiConfig.transformation.usesDynamicRefId ? dynamicRefId : undefined}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
+3
-1
@@ -14,10 +14,11 @@ export interface Props {
|
||||
transformationTypeName: string;
|
||||
disabled?: boolean;
|
||||
onChange: (index: number, config: DataTransformerConfig) => void;
|
||||
dynamicRefId?: string;
|
||||
}
|
||||
|
||||
export const TransformationOperationRowHeader = (props: Props) => {
|
||||
const { index, transformation, transformations, onChange, disabled, transformationTypeName } = props;
|
||||
const { index, transformation, transformations, onChange, disabled, transformationTypeName, dynamicRefId } = props;
|
||||
|
||||
const styles = useStyles2(getStyles);
|
||||
const [isRefIdEditing, toggleIsRefIdEditing] = useToggle(false);
|
||||
@@ -97,6 +98,7 @@ export const TransformationOperationRowHeader = (props: Props) => {
|
||||
>
|
||||
<span className={cx(styles.refIdStyle, !isStaticRefId && styles.placeholderText)}>
|
||||
{transformation.refId ||
|
||||
dynamicRefId ||
|
||||
t(
|
||||
'dashboard.transformation-operation-row.transformation-editor-row-header.edit-refId-placeholder',
|
||||
'(Auto)'
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
DataTransformerID,
|
||||
Field,
|
||||
FieldType,
|
||||
getTransformationLegacyRefId,
|
||||
getTransformationDynamicRefId,
|
||||
SynchronousDataTransformerInfo,
|
||||
} from '@grafana/data';
|
||||
import { t } from '@grafana/i18n';
|
||||
@@ -38,6 +38,7 @@ export const getJoinByLabelsTransformer: () => SynchronousDataTransformerInfo<Jo
|
||||
return [joinByLabels(options, data)];
|
||||
};
|
||||
},
|
||||
usesDynamicRefId: true,
|
||||
});
|
||||
|
||||
interface JoinValues {
|
||||
@@ -119,7 +120,7 @@ export function joinByLabels(options: JoinByLabelsTransformOptions, data: DataFr
|
||||
const frame: DataFrame = {
|
||||
fields: [],
|
||||
length: nameValues[0].length,
|
||||
refId: options.refId ?? getTransformationLegacyRefId(DataTransformerID.joinByLabels, data),
|
||||
refId: options.refId ?? getTransformationDynamicRefId(DataTransformerID.joinByLabels, data),
|
||||
};
|
||||
for (let i = 0; i < join.length; i++) {
|
||||
frame.fields.push({
|
||||
|
||||
Reference in New Issue
Block a user