remove unneeded decoupling, filter fields when there are no links

This commit is contained in:
Kristina Durivage
2024-10-21 20:26:01 -05:00
parent 3408ad436e
commit 2513594a95
6 changed files with 20 additions and 37 deletions
+1 -10
View File
@@ -101,16 +101,7 @@ export function decoupleHideFromState(frames: DataFrame[], fieldConfig: FieldCon
};
// original with perm overrides
if (field.config.custom !== undefined) {
field.config.custom.hideFrom = hideFrom;
} else {
field.config = {
...field.config,
custom: {
hideFrom: hideFrom,
},
};
}
field.config.custom.hideFrom = hideFrom;
});
});
}
@@ -167,12 +167,17 @@ export class GraphNG extends Component<GraphNGProps, GraphNGState> {
// filter join field and fields.y
alignedFrameFinal = {
...alignedFrame,
fields: alignedFrame.fields
.filter((field, i) => i === 0 || fields.y(field, alignedFrame, [alignedFrame]))
.filter((field) => field.config.custom?.hideFrom?.viz !== true),
fields: alignedFrame.fields.filter((field, i) => i === 0 || fields.y(field, alignedFrame, [alignedFrame])),
};
}
const nonHiddenFields = alignedFrameFinal.fields.filter((field) => field.config.custom?.hideFrom?.viz !== true);
alignedFrameFinal = {
...alignedFrameFinal,
fields: nonHiddenFields,
length: nonHiddenFields.length,
};
let config = this.state?.config;
if (withConfig) {
@@ -8,7 +8,6 @@ import {
DataFrame,
fieldMatchers,
FieldMatcherID,
FieldConfigSource,
} from '@grafana/data';
import { LegendDisplayMode, VizLegendOptions } from '@grafana/schema';
@@ -34,12 +33,6 @@ describe('prepare timeline graph', () => {
to: dateTime(3),
},
};
const fieldConfig: FieldConfigSource = {
defaults: {},
overrides: [],
};
it('errors with no time fields', () => {
const frames = [
toDataFrame({
@@ -49,7 +42,7 @@ describe('prepare timeline graph', () => {
],
}),
];
const info = prepareTimelineFields(frames, true, timeRange, theme, fieldConfig);
const info = prepareTimelineFields(frames, true, timeRange, theme);
expect(info.warn).toEqual('Data does not have a time field');
});
@@ -62,7 +55,7 @@ describe('prepare timeline graph', () => {
],
}),
];
const info = prepareTimelineFields(frames, true, timeRange, theme, fieldConfig);
const info = prepareTimelineFields(frames, true, timeRange, theme);
expect(info.warn).toEqual('No graphable fields');
});
@@ -75,7 +68,7 @@ describe('prepare timeline graph', () => {
],
}),
];
const info = prepareTimelineFields(frames, true, timeRange, theme, fieldConfig);
const info = prepareTimelineFields(frames, true, timeRange, theme);
expect(info.warn).toBeUndefined();
const out = info.frames![0];
@@ -104,7 +97,7 @@ describe('prepare timeline graph', () => {
],
}),
];
const result = prepareTimelineFields(frames, true, timeRange, theme, fieldConfig);
const result = prepareTimelineFields(frames, true, timeRange, theme);
expect(result.frames?.[0].fields[0].values).toEqual([1, 2, 3, 4]);
});
@@ -161,7 +154,7 @@ describe('prepare timeline graph', () => {
}),
];
const info = prepareTimelineFields(frames, true, timeRange2, theme, fieldConfig);
const info = prepareTimelineFields(frames, true, timeRange2, theme);
let joined = preparePlotFrame(
info.frames!,
@@ -252,7 +245,7 @@ describe('prepare timeline graph', () => {
}),
];
const info = prepareTimelineFields(frames, true, timeRange2, theme, fieldConfig);
const info = prepareTimelineFields(frames, true, timeRange2, theme);
let joined = preparePlotFrame(
info.frames!,
@@ -18,9 +18,7 @@ import {
outerJoinDataFrames,
ValueMapping,
ThresholdsConfig,
FieldConfigSource,
} from '@grafana/data';
import { decoupleHideFromState } from '@grafana/data/src/field/fieldState';
import { maybeSortFrame, NULL_RETAIN } from '@grafana/data/src/transformations/transformers/joinDataFrames';
import { applyNullInsertThreshold } from '@grafana/data/src/transformations/transformers/nulls/nullInsertThreshold';
import { nullToValue } from '@grafana/data/src/transformations/transformers/nulls/nullToValue';
@@ -298,15 +296,13 @@ export function prepareTimelineFields(
series: DataFrame[] | undefined,
mergeValues: boolean,
timeRange: TimeRange,
theme: GrafanaTheme2,
fieldConfig: FieldConfigSource
theme: GrafanaTheme2
): { frames?: DataFrame[]; warn?: string } {
if (!series?.length) {
return { warn: 'No data in response' };
}
cacheFieldDisplayNames(series);
decoupleHideFromState(series, fieldConfig);
let hasTimeseries = false;
const frames: DataFrame[] = [];
@@ -104,7 +104,6 @@ export const StateTimelinePanel = ({
height,
replaceVariables,
onChangeTimeRange,
fieldConfig,
}: TimelinePanelProps) => {
const theme = useTheme2();
@@ -114,8 +113,8 @@ export const StateTimelinePanel = ({
const cursorSync = sync?.() ?? DashboardCursorSync.Off;
const { frames, warn } = useMemo(
() => prepareTimelineFields(data.series, options.mergeValues ?? true, timeRange, theme, fieldConfig),
[data.series, options.mergeValues, timeRange, theme, fieldConfig]
() => prepareTimelineFields(data.series, options.mergeValues ?? true, timeRange, theme),
[data.series, options.mergeValues, timeRange, theme]
);
const { paginatedFrames, paginationRev, paginationElement, paginationHeight } = usePagination(
@@ -31,7 +31,6 @@ export const StatusHistoryPanel = ({
height,
replaceVariables,
onChangeTimeRange,
fieldConfig,
}: TimelinePanelProps) => {
const theme = useTheme2();
@@ -43,8 +42,8 @@ export const StatusHistoryPanel = ({
const enableAnnotationCreation = Boolean(canAddAnnotations && canAddAnnotations());
const { frames, warn } = useMemo(
() => prepareTimelineFields(data.series, false, timeRange, theme, fieldConfig),
[data.series, timeRange, theme, fieldConfig]
() => prepareTimelineFields(data.series, false, timeRange, theme),
[data.series, timeRange, theme]
);
const legendItems = useMemo(