mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 10:03:33 -06:00
* Use last used datasource or default datasource when starting a trail * Use tabs and move actions bar to same line when possible * Added overview tab with description, type and labels * Clickable labels in overview tab * Show label value counts next to the label name * Fix action bar zIndex * Address PR comments * Refactor * Refactor getLabelOptions to utils * Reuse language provider from state * betterer * testing some refactors * Remove unreachable code * Refactor GROUP_BY var to MetricScene * Fix url by excluding var-groupby * Fix conflicts * Use <Text/> instead of custom styles * Simplify setting overview as default tab --------- Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import React from 'react';
|
|
|
|
import { LoadingState, PanelData, DataFrame } from '@grafana/data';
|
|
import {
|
|
SceneObjectState,
|
|
SceneFlexItem,
|
|
SceneObjectBase,
|
|
sceneGraph,
|
|
SceneComponentProps,
|
|
SceneByFrameRepeater,
|
|
SceneLayout,
|
|
} from '@grafana/scenes';
|
|
|
|
interface ByFrameRepeaterState extends SceneObjectState {
|
|
body: SceneLayout;
|
|
getLayoutChild(data: PanelData, frame: DataFrame, frameIndex: number): SceneFlexItem;
|
|
}
|
|
|
|
export class ByFrameRepeater extends SceneObjectBase<ByFrameRepeaterState> {
|
|
public constructor(state: ByFrameRepeaterState) {
|
|
super(state);
|
|
|
|
this.addActivationHandler(() => {
|
|
const data = sceneGraph.getData(this);
|
|
|
|
this._subs.add(
|
|
data.subscribeToState((data) => {
|
|
if (data.data?.state === LoadingState.Done) {
|
|
this.performRepeat(data.data);
|
|
}
|
|
})
|
|
);
|
|
|
|
if (data.state.data) {
|
|
this.performRepeat(data.state.data);
|
|
}
|
|
});
|
|
}
|
|
|
|
private performRepeat(data: PanelData) {
|
|
const newChildren: SceneFlexItem[] = [];
|
|
|
|
for (let seriesIndex = 0; seriesIndex < data.series.length; seriesIndex++) {
|
|
const layoutChild = this.state.getLayoutChild(data, data.series[seriesIndex], seriesIndex);
|
|
newChildren.push(layoutChild);
|
|
}
|
|
|
|
this.state.body.setState({ children: newChildren });
|
|
}
|
|
|
|
public static Component = ({ model }: SceneComponentProps<SceneByFrameRepeater>) => {
|
|
const { body } = model.useState();
|
|
return <body.Component model={body} />;
|
|
};
|
|
}
|