2020-06-04 06:44:48 -05:00
|
|
|
import React, { FC, useCallback, useState } from 'react';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2021-04-26 11:26:56 -05:00
|
|
|
import { Button, Field, Form, Modal, Input } from '@grafana/ui';
|
2020-06-04 06:44:48 -05:00
|
|
|
|
|
|
|
import { RepeatRowSelect } from '../RepeatRowSelect/RepeatRowSelect';
|
|
|
|
|
2021-07-20 03:57:03 -05:00
|
|
|
export type OnRowOptionsUpdate = (title: string, repeat?: string | null) => void;
|
2020-06-04 06:44:48 -05:00
|
|
|
|
|
|
|
export interface Props {
|
2021-07-20 03:57:03 -05:00
|
|
|
title: string;
|
Chore: Fix all Typescript strict null errors (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2020-07-10 05:46:59 -05:00
|
|
|
repeat?: string | null;
|
2020-06-04 06:44:48 -05:00
|
|
|
onUpdate: OnRowOptionsUpdate;
|
|
|
|
onCancel: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const RowOptionsForm: FC<Props> = ({ repeat, title, onUpdate, onCancel }) => {
|
Chore: Fix all Typescript strict null errors (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2020-07-10 05:46:59 -05:00
|
|
|
const [newRepeat, setNewRepeat] = useState<string | null | undefined>(repeat);
|
2021-07-20 03:57:03 -05:00
|
|
|
const onChangeRepeat = useCallback((name?: string | null) => setNewRepeat(name), [setNewRepeat]);
|
2020-06-04 06:44:48 -05:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Form
|
|
|
|
defaultValues={{ title }}
|
2021-07-20 03:57:03 -05:00
|
|
|
onSubmit={(formData: { title: string }) => {
|
2020-06-04 06:44:48 -05:00
|
|
|
onUpdate(formData.title, newRepeat);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{({ register }) => (
|
|
|
|
<>
|
|
|
|
<Field label="Title">
|
2021-04-29 08:54:38 -05:00
|
|
|
<Input {...register('title')} type="text" />
|
2020-06-04 06:44:48 -05:00
|
|
|
</Field>
|
|
|
|
|
|
|
|
<Field label="Repeat for">
|
|
|
|
<RepeatRowSelect repeat={newRepeat} onChange={onChangeRepeat} />
|
|
|
|
</Field>
|
|
|
|
|
2021-04-26 11:26:56 -05:00
|
|
|
<Modal.ButtonRow>
|
2021-05-24 09:21:54 -05:00
|
|
|
<Button type="button" variant="secondary" onClick={onCancel} fill="outline">
|
2020-06-04 06:44:48 -05:00
|
|
|
Cancel
|
|
|
|
</Button>
|
2021-04-27 08:36:48 -05:00
|
|
|
<Button type="submit">Update</Button>
|
2021-04-26 11:26:56 -05:00
|
|
|
</Modal.ButtonRow>
|
2020-06-04 06:44:48 -05:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|