mirror of https://github.com/grafana/grafana.git
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import * as React from 'react';
|
|
|
|
import { SceneObject } from '@grafana/scenes';
|
|
import { Icon, ModalsController } from '@grafana/ui';
|
|
import { t } from 'app/core/internationalization';
|
|
|
|
import { OnRowOptionsUpdate } from './RowOptionsForm';
|
|
import { RowOptionsModal } from './RowOptionsModal';
|
|
|
|
export interface RowOptionsButtonProps {
|
|
title: string;
|
|
repeat?: string;
|
|
parent: SceneObject;
|
|
onUpdate: OnRowOptionsUpdate;
|
|
warning?: React.ReactNode;
|
|
}
|
|
|
|
export const RowOptionsButton = ({ repeat, title, parent, onUpdate, warning }: RowOptionsButtonProps) => {
|
|
const onUpdateChange = (hideModal: () => void) => (title: string, repeat?: string | null) => {
|
|
onUpdate(title, repeat);
|
|
hideModal();
|
|
};
|
|
|
|
return (
|
|
<ModalsController>
|
|
{({ showModal, hideModal }) => {
|
|
return (
|
|
<button
|
|
type="button"
|
|
className="pointer"
|
|
aria-label={t('dashboard.default-layout.row-options.button.label', 'Row options')}
|
|
onClick={() => {
|
|
showModal(RowOptionsModal, {
|
|
title,
|
|
repeat,
|
|
parent,
|
|
onDismiss: hideModal,
|
|
onUpdate: onUpdateChange(hideModal),
|
|
warning,
|
|
});
|
|
}}
|
|
>
|
|
<Icon name="cog" />
|
|
</button>
|
|
);
|
|
}}
|
|
</ModalsController>
|
|
);
|
|
};
|
|
|
|
RowOptionsButton.displayName = 'RowOptionsButton';
|