mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
Adds basic support for switching between Metrics and Logs in Explore. Currently only test datasource that supports both Metrics and Logs. Summary of changes: * Moves mode (Metric, Logs) selection to the left of datasource picker and add some quick styling. * Only trigger change in ToggleButton if not selected * Set correct mode if datasource only supports logs Closes #16808
64 lines
1.5 KiB
TypeScript
64 lines
1.5 KiB
TypeScript
import React, { FC, ReactNode, PureComponent } from 'react';
|
|
import { Tooltip } from '@grafana/ui';
|
|
|
|
interface ToggleButtonGroupProps {
|
|
label?: string;
|
|
children: JSX.Element[];
|
|
transparent?: boolean;
|
|
}
|
|
|
|
export default class ToggleButtonGroup extends PureComponent<ToggleButtonGroupProps> {
|
|
render() {
|
|
const { children, label, transparent } = this.props;
|
|
|
|
return (
|
|
<div className="gf-form">
|
|
{label && <label className={`gf-form-label ${transparent ? 'gf-form-label--transparent' : ''}`}>{label}</label>}
|
|
<div className={`toggle-button-group ${transparent ? 'toggle-button-group--transparent' : ''}`}>{children}</div>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
interface ToggleButtonProps {
|
|
onChange?: (value: any) => void;
|
|
selected?: boolean;
|
|
value: any;
|
|
className?: string;
|
|
children: ReactNode;
|
|
tooltip?: string;
|
|
}
|
|
|
|
export const ToggleButton: FC<ToggleButtonProps> = ({
|
|
children,
|
|
selected,
|
|
className = '',
|
|
value = null,
|
|
tooltip,
|
|
onChange,
|
|
}) => {
|
|
const onClick = (event: React.SyntheticEvent) => {
|
|
event.stopPropagation();
|
|
if (!selected && onChange) {
|
|
onChange(value);
|
|
}
|
|
};
|
|
|
|
const btnClassName = `btn ${className} ${selected ? 'active' : ''}`;
|
|
const button = (
|
|
<button className={btnClassName} onClick={onClick}>
|
|
<span>{children}</span>
|
|
</button>
|
|
);
|
|
|
|
if (tooltip) {
|
|
return (
|
|
<Tooltip content={tooltip} placement="bottom">
|
|
{button}
|
|
</Tooltip>
|
|
);
|
|
} else {
|
|
return button;
|
|
}
|
|
};
|