grafana/data: Move data frames processing functions from core (#60795)

This commit is contained in:
Dominik Prokop 2022-12-28 07:59:45 -08:00 committed by GitHub
parent aa0936127d
commit 78d7f11b8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 5 deletions

View File

@ -19,6 +19,7 @@ import {
DataFrameDTO,
TIME_SERIES_VALUE_FIELD_NAME,
TIME_SERIES_TIME_FIELD_NAME,
DataQueryResponseData,
} from '../types/index';
import { ArrayVector } from '../vector/ArrayVector';
import { SortedVector } from '../vector/SortedVector';
@ -510,3 +511,29 @@ export const getTimeField = (series: DataFrame): { timeField?: Field; timeIndex?
}
return {};
};
function getProcessedDataFrame(data: DataQueryResponseData): DataFrame {
const dataFrame = guessFieldTypes(toDataFrame(data));
if (dataFrame.fields && dataFrame.fields.length) {
// clear out the cached info
for (const field of dataFrame.fields) {
field.state = null;
}
}
return dataFrame;
}
/**
* Given data request results, will return data frames with field types set
*
* This is also used by PanelChrome for snapshot support
*/
export function getProcessedDataFrames(results?: DataQueryResponseData[]): DataFrame[] {
if (!results || !isArray(results)) {
return [];
}
return results.map((data) => getProcessedDataFrame(data));
}

View File

@ -1,8 +1,14 @@
import { applyFieldOverrides, ArrayDataFrame, getDefaultTimeRange, LoadingState, PanelData } from '@grafana/data';
import {
applyFieldOverrides,
ArrayDataFrame,
getDefaultTimeRange,
getProcessedDataFrames,
LoadingState,
PanelData,
} from '@grafana/data';
import { config } from 'app/core/config';
import { SnapshotWorker } from '../../query/state/DashboardQueryRunner/SnapshotWorker';
import { getProcessedDataFrames } from '../../query/state/runRequest';
import { getTimeSrv } from '../services/TimeSrv';
import { DashboardModel, PanelModel } from '../state';

View File

@ -1,8 +1,14 @@
import { from, of, OperatorFunction } from 'rxjs';
import { map, mergeMap } from 'rxjs/operators';
import { FieldType, getFieldDisplayName, isDataFrame, MetricFindValue, PanelData } from '@grafana/data';
import { getProcessedDataFrames } from 'app/features/query/state/runRequest';
import {
FieldType,
getFieldDisplayName,
getProcessedDataFrames,
isDataFrame,
MetricFindValue,
PanelData,
} from '@grafana/data';
import { ThunkDispatch } from '../../../types';
import { validateVariableSelectionState } from '../state/actions';

View File

@ -1,4 +1,4 @@
import { getProcessedDataFrames } from 'app/features/query/state/runRequest';
import { getProcessedDataFrames } from '@grafana/data';
import { DataProcessor } from '../data_processor';