2020-06-04 06:44:48 -05:00
|
|
|
import React, { FC } from 'react';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2020-06-04 06:44:48 -05:00
|
|
|
import { Icon, ModalsController } from '@grafana/ui';
|
|
|
|
|
|
|
|
import { OnRowOptionsUpdate } from './RowOptionsForm';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { RowOptionsModal } from './RowOptionsModal';
|
2020-06-04 06:44:48 -05:00
|
|
|
|
|
|
|
export interface RowOptionsButtonProps {
|
2021-07-20 03:57:03 -05:00
|
|
|
title: string;
|
|
|
|
repeat?: string | null;
|
2020-06-04 06:44:48 -05:00
|
|
|
onUpdate: OnRowOptionsUpdate;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const RowOptionsButton: FC<RowOptionsButtonProps> = ({ repeat, title, onUpdate }) => {
|
2021-07-20 03:57:03 -05:00
|
|
|
const onUpdateChange = (hideModal: () => void) => (title: string, repeat?: string | null) => {
|
2020-06-04 06:44:48 -05:00
|
|
|
onUpdate(title, repeat);
|
|
|
|
hideModal();
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ModalsController>
|
|
|
|
{({ showModal, hideModal }) => {
|
|
|
|
return (
|
|
|
|
<a
|
|
|
|
className="pointer"
|
2022-05-31 10:51:44 -05:00
|
|
|
role="button"
|
|
|
|
aria-label="Row options"
|
2020-06-04 06:44:48 -05:00
|
|
|
onClick={() => {
|
|
|
|
showModal(RowOptionsModal, { title, repeat, onDismiss: hideModal, onUpdate: onUpdateChange(hideModal) });
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Icon name="cog" />
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</ModalsController>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
RowOptionsButton.displayName = 'RowOptionsButton';
|