BasicSettings.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import React, { FC } from 'react';
  2. import { SelectableValue } from '@grafana/data';
  3. import { Field, Input, InputControl, Select } from '@grafana/ui';
  4. import { NotificationChannelSecureFields, NotificationChannelType } from '../../../types';
  5. import { NotificationSettingsProps } from './NotificationChannelForm';
  6. import { NotificationChannelOptions } from './NotificationChannelOptions';
  7. interface Props extends NotificationSettingsProps {
  8. selectedChannel: NotificationChannelType;
  9. channels: Array<SelectableValue<string>>;
  10. secureFields: NotificationChannelSecureFields;
  11. resetSecureField: (key: string) => void;
  12. }
  13. export const BasicSettings: FC<Props> = ({
  14. control,
  15. currentFormValues,
  16. errors,
  17. secureFields,
  18. selectedChannel,
  19. channels,
  20. register,
  21. resetSecureField,
  22. }) => {
  23. return (
  24. <>
  25. <Field label="Name" invalid={!!errors.name} error={errors.name && errors.name.message}>
  26. <Input {...register('name', { required: 'Name is required' })} />
  27. </Field>
  28. <Field label="Type">
  29. <InputControl
  30. name="type"
  31. render={({ field: { ref, ...field } }) => <Select {...field} options={channels} />}
  32. control={control}
  33. rules={{ required: true }}
  34. />
  35. </Field>
  36. <NotificationChannelOptions
  37. selectedChannelOptions={selectedChannel.options.filter((o) => o.required)}
  38. currentFormValues={currentFormValues}
  39. secureFields={secureFields}
  40. onResetSecureField={resetSecureField}
  41. register={register}
  42. errors={errors}
  43. control={control}
  44. />
  45. </>
  46. );
  47. };