mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* bring in source from database
* bring in transformations from database
* add regex transformations to scopevar
* Consolidate types, add better example, cleanup
* Add var only if match
* Change ScopedVar to not require text, do not leak transformation-made variables between links
* Add mappings and start implementing logfmt
* Add mappings and start implementing logfmt
* Remove mappings, turn off global regex
* Add example yaml and omit transformations if empty
* Fix the yaml
* Add logfmt transformation
* Cleanup transformations and yaml
* add transformation field to FE types and use it, safeStringify logfmt values
* Add tests, only safe stringify if non-string, fix bug with safe stringify where it would return empty string with false value
* Add test for transformation field
* Do not add null transformations object
* Break out transformation logic, add tests to backend code
* Fix lint errors I understand 😅
* Fix the backend lint error
* Remove unnecessary code and mark new Transformations object as internal
* Add support for named capture groups
* Remove type assertion
* Remove variable name from transformation
* Add test for overriding regexes
* Add back variable name field, but change to mapValue
* fix go api test
* Change transformation types to enum, add better provisioning checks for bad type name and format
* Check for expression with regex transformations
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import { DataFrame } from '@grafana/data';
|
|
|
|
import { CorrelationData } from './useCorrelations';
|
|
|
|
type DataFrameRefIdToDataSourceUid = Record<string, string>;
|
|
|
|
/**
|
|
* Creates data links from provided CorrelationData object
|
|
*
|
|
* @param dataFrames list of data frames to be processed
|
|
* @param correlations list of of possible correlations that can be applied
|
|
* @param dataFrameRefIdToDataSourceUid a map that for provided refId references corresponding data source ui
|
|
*/
|
|
export const attachCorrelationsToDataFrames = (
|
|
dataFrames: DataFrame[],
|
|
correlations: CorrelationData[],
|
|
dataFrameRefIdToDataSourceUid: DataFrameRefIdToDataSourceUid
|
|
): DataFrame[] => {
|
|
dataFrames.forEach((dataFrame) => {
|
|
const frameRefId = dataFrame.refId;
|
|
if (!frameRefId) {
|
|
return;
|
|
}
|
|
const dataSourceUid = dataFrameRefIdToDataSourceUid[frameRefId];
|
|
const sourceCorrelations = correlations.filter((correlation) => correlation.source.uid === dataSourceUid);
|
|
decorateDataFrameWithInternalDataLinks(dataFrame, sourceCorrelations);
|
|
});
|
|
|
|
return dataFrames;
|
|
};
|
|
|
|
const decorateDataFrameWithInternalDataLinks = (dataFrame: DataFrame, correlations: CorrelationData[]) => {
|
|
dataFrame.fields.forEach((field) => {
|
|
correlations.map((correlation) => {
|
|
if (correlation.config?.field === field.name) {
|
|
field.config.links = field.config.links || [];
|
|
field.config.links.push({
|
|
internal: {
|
|
query: correlation.config?.target,
|
|
datasourceUid: correlation.target.uid,
|
|
datasourceName: correlation.target.name,
|
|
transformations: correlation.config?.transformations,
|
|
},
|
|
url: '',
|
|
title: correlation.label || correlation.target.name,
|
|
});
|
|
}
|
|
});
|
|
});
|
|
};
|