2023-03-14 07:38:21 -07:00
|
|
|
import React, { useCallback, useState } from 'react';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2023-08-28 10:00:11 -03:00
|
|
|
import { selectors } from '@grafana/e2e-selectors';
|
2024-03-26 13:14:17 +01:00
|
|
|
import { Button, Field, Modal, Input, Alert } from '@grafana/ui';
|
|
|
|
|
import { Form } from 'app/core/components/Form/Form';
|
2020-06-04 13:44:48 +02:00
|
|
|
|
|
|
|
|
import { RepeatRowSelect } from '../RepeatRowSelect/RepeatRowSelect';
|
|
|
|
|
|
2021-07-20 09:57:03 +01:00
|
|
|
export type OnRowOptionsUpdate = (title: string, repeat?: string | null) => void;
|
2020-06-04 13:44:48 +02:00
|
|
|
|
|
|
|
|
export interface Props {
|
2021-07-20 09:57:03 +01:00
|
|
|
title: string;
|
2024-01-17 11:13:14 +00:00
|
|
|
repeat?: string;
|
2020-06-04 13:44:48 +02:00
|
|
|
onUpdate: OnRowOptionsUpdate;
|
|
|
|
|
onCancel: () => void;
|
2023-08-28 10:00:11 -03:00
|
|
|
warning?: React.ReactNode;
|
2020-06-04 13:44:48 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-28 10:00:11 -03:00
|
|
|
export const RowOptionsForm = ({ repeat, title, warning, onUpdate, onCancel }: Props) => {
|
2024-01-17 11:13:14 +00:00
|
|
|
const [newRepeat, setNewRepeat] = useState<string | undefined>(repeat);
|
|
|
|
|
const onChangeRepeat = useCallback((name?: string) => setNewRepeat(name), [setNewRepeat]);
|
2020-06-04 13:44:48 +02:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Form
|
|
|
|
|
defaultValues={{ title }}
|
2021-07-20 09:57:03 +01:00
|
|
|
onSubmit={(formData: { title: string }) => {
|
2020-06-04 13:44:48 +02:00
|
|
|
onUpdate(formData.title, newRepeat);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{({ register }) => (
|
|
|
|
|
<>
|
|
|
|
|
<Field label="Title">
|
2021-04-29 16:54:38 +03:00
|
|
|
<Input {...register('title')} type="text" />
|
2020-06-04 13:44:48 +02:00
|
|
|
</Field>
|
|
|
|
|
<Field label="Repeat for">
|
|
|
|
|
<RepeatRowSelect repeat={newRepeat} onChange={onChangeRepeat} />
|
|
|
|
|
</Field>
|
2023-08-28 10:00:11 -03:00
|
|
|
{warning && (
|
|
|
|
|
<Alert
|
|
|
|
|
data-testid={selectors.pages.Dashboard.Rows.Repeated.ConfigSection.warningMessage}
|
|
|
|
|
severity="warning"
|
|
|
|
|
title=""
|
|
|
|
|
topSpacing={3}
|
|
|
|
|
bottomSpacing={0}
|
|
|
|
|
>
|
|
|
|
|
{warning}
|
|
|
|
|
</Alert>
|
|
|
|
|
)}
|
2021-04-26 18:26:56 +02:00
|
|
|
<Modal.ButtonRow>
|
2021-05-24 16:21:54 +02:00
|
|
|
<Button type="button" variant="secondary" onClick={onCancel} fill="outline">
|
2020-06-04 13:44:48 +02:00
|
|
|
Cancel
|
|
|
|
|
</Button>
|
2021-04-27 15:36:48 +02:00
|
|
|
<Button type="submit">Update</Button>
|
2021-04-26 18:26:56 +02:00
|
|
|
</Modal.ButtonRow>
|
2020-06-04 13:44:48 +02:00
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</Form>
|
|
|
|
|
);
|
|
|
|
|
};
|