mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
d4ef06451c
commit
c2a9d48dd6
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user