mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Stop using ArrayVector and MutableField (#67333)
This commit is contained in:
parent
353e11b771
commit
5c4ecf7a86
@ -7,6 +7,7 @@ import { FunctionalVector } from '../vector/FunctionalVector';
|
||||
|
||||
import { guessFieldTypeFromValue, guessFieldTypeForField, toDataFrameDTO } from './processDataFrame';
|
||||
|
||||
/** @deprecated */
|
||||
export type MutableField<T = any> = Field<T>;
|
||||
|
||||
type MutableVectorCreator = (buffer?: any[]) => any[];
|
||||
@ -65,14 +66,14 @@ export class MutableDataFrame<T = any> extends FunctionalVector<T> implements Da
|
||||
return this.first.length;
|
||||
}
|
||||
|
||||
addFieldFor(value: unknown, name?: string): MutableField {
|
||||
addFieldFor(value: unknown, name?: string): Field {
|
||||
return this.addField({
|
||||
name: name || '', // Will be filled in
|
||||
type: guessFieldTypeFromValue(value),
|
||||
});
|
||||
}
|
||||
|
||||
addField(f: Field | FieldDTO, startLength?: number): MutableField {
|
||||
addField(f: Field | FieldDTO, startLength?: number): Field {
|
||||
let buffer: any[] | undefined = undefined;
|
||||
|
||||
if (f.values) {
|
||||
@ -98,7 +99,7 @@ export class MutableDataFrame<T = any> extends FunctionalVector<T> implements Da
|
||||
name = `Field ${this.fields.length + 1}`;
|
||||
}
|
||||
|
||||
const field: MutableField = {
|
||||
const field: Field = {
|
||||
...f,
|
||||
name,
|
||||
type,
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { MutableField } from '../../dataframe/MutableDataFrame';
|
||||
import { guessFieldTypeForField } from '../../dataframe/processDataFrame';
|
||||
import { getFieldDisplayName } from '../../field/fieldState';
|
||||
import { DataFrame, Field, FieldType } from '../../types/dataFrame';
|
||||
@ -63,7 +62,7 @@ export const groupByTransformer: DataTransformerInfo<GroupByTransformerOptions>
|
||||
|
||||
// Group the values by fields and groups so we can get all values for a
|
||||
// group for a given field.
|
||||
const valuesByGroupKey = new Map<string, Record<string, MutableField>>();
|
||||
const valuesByGroupKey = new Map<string, Record<string, Field>>();
|
||||
for (let rowIndex = 0; rowIndex < frame.length; rowIndex++) {
|
||||
const groupKey = String(groupByFields.map((field) => field.values[rowIndex]));
|
||||
const valuesByField = valuesByGroupKey.get(groupKey) ?? {};
|
||||
|
@ -15,7 +15,6 @@ import {
|
||||
formatLabels,
|
||||
getDisplayProcessor,
|
||||
Labels,
|
||||
MutableField,
|
||||
PreferredVisualisationType,
|
||||
ScopedVars,
|
||||
TIME_SERIES_TIME_FIELD_NAME,
|
||||
@ -208,7 +207,7 @@ export function transformDFToTable(dfs: DataFrame[]): DataFrame[] {
|
||||
const valueText = getValueText(refIds.length, refId);
|
||||
const valueField = getValueField({ data: [], valueName: valueText });
|
||||
const timeField = getTimeField([]);
|
||||
const labelFields: MutableField[] = [];
|
||||
const labelFields: Field[] = [];
|
||||
|
||||
// Fill labelsFields with labels from dataFrames
|
||||
dataFramesByRefId[refId].forEach((df) => {
|
||||
@ -329,14 +328,13 @@ export function transform(
|
||||
|
||||
// Return early if result type is scalar
|
||||
if (prometheusResult.resultType === 'scalar') {
|
||||
return [
|
||||
{
|
||||
meta: options.meta,
|
||||
refId: options.refId,
|
||||
length: 1,
|
||||
fields: [getTimeField([prometheusResult.result]), getValueField({ data: [prometheusResult.result] })],
|
||||
},
|
||||
];
|
||||
const df: DataFrame = {
|
||||
meta: options.meta,
|
||||
refId: options.refId,
|
||||
length: 1,
|
||||
fields: [getTimeField([prometheusResult.result]), getValueField({ data: [prometheusResult.result] })],
|
||||
};
|
||||
return [df];
|
||||
}
|
||||
|
||||
// Return early again if the format is table, this needs special transformation.
|
||||
@ -556,7 +554,7 @@ function getLabelValue(metric: PromMetric, label: string): string | number {
|
||||
return '';
|
||||
}
|
||||
|
||||
function getTimeField(data: PromValue[], isMs = false): MutableField {
|
||||
function getTimeField(data: PromValue[], isMs = false): Field<number> {
|
||||
return {
|
||||
name: TIME_SERIES_TIME_FIELD_NAME,
|
||||
type: FieldType.time,
|
||||
@ -579,7 +577,7 @@ function getValueField({
|
||||
parseValue = true,
|
||||
labels,
|
||||
displayNameFromDS,
|
||||
}: ValueFieldOptions): MutableField {
|
||||
}: ValueFieldOptions): Field {
|
||||
return {
|
||||
name: valueName,
|
||||
type: FieldType.number,
|
||||
|
@ -2,7 +2,7 @@ import { GridSelection } from '@glideapps/glide-data-grid';
|
||||
import { capitalize } from 'lodash';
|
||||
import React from 'react';
|
||||
|
||||
import { ArrayVector, DataFrame, FieldType } from '@grafana/data';
|
||||
import { DataFrame, FieldType } from '@grafana/data';
|
||||
import { convertFieldType } from '@grafana/data/src/transformations/transformers/convertFieldType';
|
||||
import { ContextMenu, MenuGroup, MenuItem } from '@grafana/ui';
|
||||
import { MenuDivider } from '@grafana/ui/src/components/Menu/MenuDivider';
|
||||
@ -111,8 +111,7 @@ export const DatagridContextMenu = ({
|
||||
label="Clear column"
|
||||
onClick={() => {
|
||||
const field = data.fields[column];
|
||||
field.values = new ArrayVector(field.values.toArray().map(() => null));
|
||||
|
||||
field.values = field.values.map(() => null);
|
||||
saveData({
|
||||
...data,
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user