mirror of
https://github.com/grafana/grafana.git
synced 2026-09-05 04:40:13 -05:00
FieldValues: Use plain arrays instead of Vector (part 3 of 2) (#66612)
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
co-authored by
Ryan McKinley
parent
24696d593b
commit
b24ba7b7ae
@@ -2,14 +2,7 @@ import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import React, { ComponentProps } from 'react';
|
||||
|
||||
import {
|
||||
ArrayVector,
|
||||
FieldType,
|
||||
LoadingState,
|
||||
MutableDataFrame,
|
||||
SupplementaryQueryType,
|
||||
DataSourceApi,
|
||||
} from '@grafana/data';
|
||||
import { FieldType, LoadingState, MutableDataFrame, SupplementaryQueryType, DataSourceApi } from '@grafana/data';
|
||||
import { DataQuery } from '@grafana/schema';
|
||||
|
||||
import { LogsSamplePanel } from './LogsSamplePanel';
|
||||
@@ -43,20 +36,20 @@ const sampleDataFrame = new MutableDataFrame({
|
||||
{
|
||||
name: 'labels',
|
||||
type: FieldType.other,
|
||||
values: new ArrayVector([
|
||||
values: [
|
||||
{ place: 'luna', source: 'data' },
|
||||
{ place: 'luna', source: 'data' },
|
||||
]),
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Time',
|
||||
type: FieldType.time,
|
||||
values: new ArrayVector(['2022-02-22T09:28:11.352440161Z', '2022-02-22T14:42:50.991981292Z']),
|
||||
values: ['2022-02-22T09:28:11.352440161Z', '2022-02-22T14:42:50.991981292Z'],
|
||||
},
|
||||
{
|
||||
name: 'Line',
|
||||
type: FieldType.string,
|
||||
values: new ArrayVector(['line1 ', 'line2']),
|
||||
values: ['line1 ', 'line2'],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ export function transformDataFrames(frame?: DataFrame): Trace | null {
|
||||
let data: TraceResponse =
|
||||
frame.fields.length === 1
|
||||
? // For backward compatibility when we sent whole json response in a single field/value
|
||||
frame.fields[0].values.get(0)
|
||||
frame.fields[0].values[0]
|
||||
: transformTraceDataFrame(frame);
|
||||
return transformTraceData(data);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import { thunkTester } from 'test/core/thunk/thunkTester';
|
||||
import { assertIsDefined } from 'test/helpers/asserts';
|
||||
|
||||
import {
|
||||
ArrayVector,
|
||||
DataQueryResponse,
|
||||
DataSourceApi,
|
||||
DataSourceJsonData,
|
||||
@@ -111,7 +110,7 @@ function setupQueryResponse(state: StoreState) {
|
||||
error: { message: 'test error' },
|
||||
data: [
|
||||
new MutableDataFrame({
|
||||
fields: [{ name: 'test', values: new ArrayVector() }],
|
||||
fields: [{ name: 'test', values: [] }],
|
||||
meta: {
|
||||
preferredVisualisationType: 'graph',
|
||||
},
|
||||
|
||||
@@ -267,9 +267,9 @@ describe('decorateWithTableResult', () => {
|
||||
expect(tableResult?.fields[0].name).toBe('Time');
|
||||
expect(tableResult?.fields[1].name).toBe('A-series');
|
||||
expect(tableResult?.fields[2].name).toBe('B-series');
|
||||
expect(tableResult?.fields[0].values.toArray()).toEqual([100, 200, 300]);
|
||||
expect(tableResult?.fields[1].values.toArray()).toEqual([4, 5, 6]);
|
||||
expect(tableResult?.fields[2].values.toArray()).toEqual([4, 5, 6]);
|
||||
expect(tableResult?.fields[0].values).toEqual([100, 200, 300]);
|
||||
expect(tableResult?.fields[1].values).toEqual([4, 5, 6]);
|
||||
expect(tableResult?.fields[2].values).toEqual([4, 5, 6]);
|
||||
});
|
||||
|
||||
it('should not override fields display property when filled', async () => {
|
||||
|
||||
@@ -18,7 +18,7 @@ export const getRawPrometheusListItemsFromDataFrame = (dataFrame: DataFrame): in
|
||||
const newFields = dataFrame.fields.filter((field) => !['Time'].includes(field.name));
|
||||
|
||||
// Get name from each series
|
||||
let metricNames: string[] = newFields.find((field) => field.name === '__name__')?.values.toArray() ?? [];
|
||||
let metricNames: string[] = newFields.find((field) => field.name === '__name__')?.values ?? [];
|
||||
if (!metricNames.length && newFields.length && newFields[0].values.length) {
|
||||
// These results do not have series labels
|
||||
// Matching the native prometheus UI which appears to only show the permutations of the first field in the query result.
|
||||
@@ -38,7 +38,7 @@ export const getRawPrometheusListItemsFromDataFrame = (dataFrame: DataFrame): in
|
||||
if (label !== 'Time') {
|
||||
// Initialize the objects
|
||||
if (typeof field?.display === 'function') {
|
||||
const stringValue = formattedValueToString(field?.display(field.values.get(i)));
|
||||
const stringValue = formattedValueToString(field?.display(field.values[i]));
|
||||
if (stringValue) {
|
||||
formattedMetric[label] = stringValue;
|
||||
} else if (label.includes('Value #')) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
ArrayVector,
|
||||
CoreApp,
|
||||
DataFrame,
|
||||
DataLink,
|
||||
@@ -211,7 +210,7 @@ describe('explore links utils', () => {
|
||||
const { field, range, dataFrame } = setup(noHyphenLink, true, {
|
||||
name: 'fluxDimensions',
|
||||
type: FieldType.string,
|
||||
values: new ArrayVector([ROW_WITH_TEXT_VALUE.value, ROW_WITH_NULL_VALUE.value]),
|
||||
values: [ROW_WITH_TEXT_VALUE.value, ROW_WITH_NULL_VALUE.value],
|
||||
config: {
|
||||
links: [noHyphenLink],
|
||||
},
|
||||
@@ -242,7 +241,7 @@ describe('explore links utils', () => {
|
||||
{
|
||||
name: 'fluxDimensions',
|
||||
type: FieldType.string,
|
||||
values: new ArrayVector([ROW_WITH_TEXT_VALUE.value, ROW_WITH_NULL_VALUE.value]),
|
||||
values: [ROW_WITH_TEXT_VALUE.value, ROW_WITH_NULL_VALUE.value],
|
||||
config: {
|
||||
links: [noHyphenLink],
|
||||
},
|
||||
@@ -251,7 +250,7 @@ describe('explore links utils', () => {
|
||||
{
|
||||
name: 'fluxDimension2',
|
||||
type: FieldType.string,
|
||||
values: new ArrayVector(['foo2', ROW_WITH_NULL_VALUE.value]),
|
||||
values: ['foo2', ROW_WITH_NULL_VALUE.value],
|
||||
config: {
|
||||
links: [noHyphenLink],
|
||||
},
|
||||
@@ -286,7 +285,7 @@ describe('explore links utils', () => {
|
||||
const { field, range, dataFrame } = setup(transformationLink, true, {
|
||||
name: 'msg',
|
||||
type: FieldType.string,
|
||||
values: new ArrayVector(['application=foo host=dev-001', 'application=bar host=prod-003']),
|
||||
values: ['application=foo host=dev-001', 'application=bar host=prod-003'],
|
||||
config: {
|
||||
links: [transformationLink],
|
||||
},
|
||||
@@ -335,7 +334,7 @@ describe('explore links utils', () => {
|
||||
const { field, range, dataFrame } = setup(transformationLink, true, {
|
||||
name: 'msg',
|
||||
type: FieldType.string,
|
||||
values: new ArrayVector(['fieldA=asparagus fieldB=banana', 'fieldA=broccoli fieldB=apple']),
|
||||
values: ['fieldA=asparagus fieldB=banana', 'fieldA=broccoli fieldB=apple'],
|
||||
config: {
|
||||
links: [transformationLink],
|
||||
},
|
||||
@@ -374,7 +373,7 @@ describe('explore links utils', () => {
|
||||
const { field, range, dataFrame } = setup(transformationLink, true, {
|
||||
name: 'msg',
|
||||
type: FieldType.string,
|
||||
values: new ArrayVector(['application=foo online=true', 'application=bar online=false']),
|
||||
values: ['application=foo online=true', 'application=bar online=false'],
|
||||
config: {
|
||||
links: [transformationLink],
|
||||
},
|
||||
@@ -417,7 +416,7 @@ describe('explore links utils', () => {
|
||||
{
|
||||
name: 'fieldWithLink',
|
||||
type: FieldType.string,
|
||||
values: new ArrayVector(['application=link', 'application=link2']),
|
||||
values: ['application=link', 'application=link2'],
|
||||
config: {
|
||||
links: [transformationLink],
|
||||
},
|
||||
@@ -426,7 +425,7 @@ describe('explore links utils', () => {
|
||||
{
|
||||
name: 'fieldNamedInTransformation',
|
||||
type: FieldType.string,
|
||||
values: new ArrayVector(['application=transform', 'application=transform2']),
|
||||
values: ['application=transform', 'application=transform2'],
|
||||
config: {},
|
||||
},
|
||||
]
|
||||
@@ -470,7 +469,7 @@ describe('explore links utils', () => {
|
||||
const { field, range, dataFrame } = setup(transformationLink, true, {
|
||||
name: 'msg',
|
||||
type: FieldType.string,
|
||||
values: new ArrayVector(['foo loki prod', 'dev bar grafana', 'prod grafana foo']),
|
||||
values: ['foo loki prod', 'dev bar grafana', 'prod grafana foo'],
|
||||
config: {
|
||||
links: [transformationLink],
|
||||
},
|
||||
@@ -545,7 +544,7 @@ describe('explore links utils', () => {
|
||||
const { field, range, dataFrame } = setup(transformationLink, true, {
|
||||
name: 'msg',
|
||||
type: FieldType.string,
|
||||
values: new ArrayVector(['application=foo host=dev-001']),
|
||||
values: ['application=foo host=dev-001'],
|
||||
config: {
|
||||
links: [transformationLink],
|
||||
},
|
||||
@@ -570,7 +569,7 @@ describe('explore links utils', () => {
|
||||
const { field, range, dataFrame } = setup(transformationLink, true, {
|
||||
name: 'msg',
|
||||
type: FieldType.string,
|
||||
values: new ArrayVector(['application=foo host=dev-001']),
|
||||
values: ['application=foo host=dev-001'],
|
||||
config: {
|
||||
links: [transformationLink],
|
||||
},
|
||||
@@ -712,7 +711,7 @@ function setup(
|
||||
const field: Field<string | null> = {
|
||||
name: 'flux-dimensions',
|
||||
type: FieldType.string,
|
||||
values: new ArrayVector([ROW_WITH_TEXT_VALUE.value, ROW_WITH_NULL_VALUE.value]),
|
||||
values: [ROW_WITH_TEXT_VALUE.value, ROW_WITH_NULL_VALUE.value],
|
||||
config: {
|
||||
links: [link],
|
||||
},
|
||||
|
||||
@@ -71,7 +71,7 @@ export const getFieldLinksForExplore = (options: {
|
||||
const scopedVars: ScopedVars = { ...(vars || {}) };
|
||||
scopedVars['__value'] = {
|
||||
value: {
|
||||
raw: field.values.get(rowIndex),
|
||||
raw: field.values[rowIndex],
|
||||
},
|
||||
text: 'Raw value',
|
||||
};
|
||||
@@ -130,9 +130,9 @@ export const getFieldLinksForExplore = (options: {
|
||||
let fieldValue;
|
||||
if (transformation.field) {
|
||||
const transformField = dataFrame?.fields.find((field) => field.name === transformation.field);
|
||||
fieldValue = transformField?.values.get(rowIndex);
|
||||
fieldValue = transformField?.values[rowIndex];
|
||||
} else {
|
||||
fieldValue = field.values.get(rowIndex);
|
||||
fieldValue = field.values[rowIndex];
|
||||
}
|
||||
|
||||
internalLinkSpecificVars = {
|
||||
|
||||
Reference in New Issue
Block a user