Correlations: Show labels fields that have links (#69120)

* Show labels fields that have links

* Fix test

* Do not safestringify strings and numbers
This commit is contained in:
Kristina 2023-05-31 08:46:33 -05:00 committed by GitHub
parent d4ef06451c
commit c2a9d48dd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
import memoizeOne from 'memoize-one'; import memoizeOne from 'memoize-one';
import { DataFrame, Field, FieldType, LinkModel, LogRowModel } from '@grafana/data'; import { DataFrame, Field, FieldType, LinkModel, LogRowModel } from '@grafana/data';
import { safeStringifyValue } from 'app/core/utils/explore';
import { ExploreFieldLinkModel } from 'app/features/explore/utils/links'; import { ExploreFieldLinkModel } from 'app/features/explore/utils/links';
export type FieldDef = { export type FieldDef = {
@ -69,9 +70,14 @@ export const getDataframeFields = memoizeOne(
.filter((field, index) => !shouldRemoveField(field, index, row)) .filter((field, index) => !shouldRemoveField(field, index, row))
.map((field) => { .map((field) => {
const links = getFieldLinks ? getFieldLinks(field, row.rowIndex, row.dataFrame) : []; const links = getFieldLinks ? getFieldLinks(field, row.rowIndex, row.dataFrame) : [];
const fieldVal = field.values[row.rowIndex];
const outputVal =
typeof fieldVal === 'string' || typeof fieldVal === 'number'
? fieldVal.toString()
: safeStringifyValue(fieldVal);
return { return {
keys: [field.name], keys: [field.name],
values: [field.values[row.rowIndex].toString()], values: [outputVal],
links: links, links: links,
fieldIndex: field.index, fieldIndex: field.index,
}; };
@ -82,7 +88,7 @@ export const getDataframeFields = memoizeOne(
function shouldRemoveField(field: Field, index: number, row: LogRowModel) { function shouldRemoveField(field: Field, index: number, row: LogRowModel) {
// Remove field if it is: // Remove field if it is:
// "labels" field that is in Loki used to store all labels // "labels" field that is in Loki used to store all labels
if (field.name === 'labels' && field.type === FieldType.other) { if (field.name === 'labels' && field.type === FieldType.other && (field.config.links?.length || 0) === 0) {
return true; return true;
} }
// id and tsNs are arbitrary added fields in the backend and should be hidden in the UI // id and tsNs are arbitrary added fields in the backend and should be hidden in the UI