mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
* fix: Cascader: allow disabled state * fix: datatrails metrics selection scene stability - clear panels and filter data when datasource changes - detect metric names loading / error state and disable components accordingly - put all scene variable dependencies together - reset metric names without clearing panels when time range changes
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { FieldType, LoadingState } from '@grafana/data';
|
|
import { SceneCSSGridItem, sceneGraph } from '@grafana/scenes';
|
|
|
|
import { MetricSelectScene } from './MetricSelectScene';
|
|
|
|
export function hideEmptyPreviews(metric: string) {
|
|
return (gridItem: SceneCSSGridItem) => {
|
|
const data = sceneGraph.getData(gridItem);
|
|
if (!data) {
|
|
return;
|
|
}
|
|
|
|
data.subscribeToState((state) => {
|
|
if (state.data?.state === LoadingState.Loading || state.data?.state === LoadingState.Error) {
|
|
return;
|
|
}
|
|
const scene = sceneGraph.getAncestor(gridItem, MetricSelectScene);
|
|
|
|
if (!state.data?.series.length) {
|
|
scene.updateMetricPanel(metric, true, true);
|
|
return;
|
|
}
|
|
|
|
let hasValue = false;
|
|
for (const frame of state.data.series) {
|
|
for (const field of frame.fields) {
|
|
if (field.type !== FieldType.number) {
|
|
continue;
|
|
}
|
|
|
|
hasValue = field.values.some((v) => v != null && !isNaN(v) && v !== 0);
|
|
if (hasValue) {
|
|
break;
|
|
}
|
|
}
|
|
if (hasValue) {
|
|
break;
|
|
}
|
|
}
|
|
scene.updateMetricPanel(metric, true, !hasValue);
|
|
});
|
|
};
|
|
}
|