mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import React, { useMemo } from 'react';
|
|
|
|
import { SelectableValue } from '@grafana/data';
|
|
import { config } from '@grafana/runtime';
|
|
import { RadioButtonGroup } from '@grafana/ui';
|
|
|
|
import { STAT, TABLE, TIMESERIES } from '../utils/constants';
|
|
|
|
export type SupportedPanelPlugins = 'timeseries' | 'table' | 'stat';
|
|
|
|
type Props = {
|
|
value: SupportedPanelPlugins;
|
|
onChange: (value: SupportedPanelPlugins) => void;
|
|
size?: 'sm' | 'md';
|
|
};
|
|
|
|
export function PanelPluginsButtonGroup(props: Props): JSX.Element | null {
|
|
const { value, onChange, size = 'md' } = props;
|
|
const panels = useMemo(() => getSupportedPanels(), []);
|
|
|
|
return <RadioButtonGroup options={panels} value={value} onChange={onChange} size={size} />;
|
|
}
|
|
|
|
function getSupportedPanels(): Array<SelectableValue<SupportedPanelPlugins>> {
|
|
return Object.values(config.panels).reduce((panels: Array<SelectableValue<SupportedPanelPlugins>>, panel) => {
|
|
if (isSupportedPanelPlugin(panel.id)) {
|
|
panels.push({
|
|
value: panel.id,
|
|
label: panel.name,
|
|
imgUrl: panel.info.logos.small,
|
|
});
|
|
}
|
|
return panels;
|
|
}, []);
|
|
}
|
|
|
|
function isSupportedPanelPlugin(id: string): id is SupportedPanelPlugins {
|
|
switch (id) {
|
|
case TIMESERIES:
|
|
case TABLE:
|
|
case STAT:
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|