The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/trails/LayoutSwitcher.tsx

42 lines
1.2 KiB

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} />;
};
}