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>
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import React from 'react';
|
|
|
|
import { SelectableValue } from '@grafana/data';
|
|
import { SceneComponentProps, SceneObject, SceneObjectBase, SceneObjectState } from '@grafana/scenes';
|
|
import { Field, RadioButtonGroup } from '@grafana/ui';
|
|
|
|
export interface LayoutSwitcherState extends SceneObjectState {
|
|
active: LayoutType;
|
|
layouts: SceneObject[];
|
|
options: Array<SelectableValue<LayoutType>>;
|
|
}
|
|
|
|
export type LayoutType = 'single' | 'grid' | 'rows';
|
|
|
|
export class LayoutSwitcher extends SceneObjectBase<LayoutSwitcherState> {
|
|
public Selector({ model }: { model: LayoutSwitcher }) {
|
|
const { active, options } = model.useState();
|
|
|
|
return (
|
|
<Field label="View">
|
|
<RadioButtonGroup options={options} value={active} onChange={model.onLayoutChange} />
|
|
</Field>
|
|
);
|
|
}
|
|
|
|
public onLayoutChange = (active: LayoutType) => {
|
|
this.setState({ active });
|
|
};
|
|
|
|
public static Component = ({ model }: SceneComponentProps<LayoutSwitcher>) => {
|
|
const { layouts, options, active } = model.useState();
|
|
|
|
const index = options.findIndex((o) => o.value === active);
|
|
if (index === -1) {
|
|
return null;
|
|
}
|
|
|
|
const layout = layouts[index];
|
|
|
|
return <layout.Component model={layout} />;
|
|
};
|
|
}
|