mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* Update hook form * Update Form component * Update ChangePassword.tsx * Update custom types * Update SaveDashboardForm * Update form story * Update FieldArray.story.tsx * Bump hook form version * Update typescript to v4.2.4 * Update ForgottenPassword.tsx * Update LoginForm.tsx * Update SignupPage.tsx * Update VerifyEmail.tsx * Update AdminEditOrgPage.tsx * Update UserCreatePage.tsx * Update BasicSettings.tsx * Update NotificationChannelForm.tsx * Update NotificationChannelOptions.tsx * Update NotificationSettings.tsx * Update OptionElement.tsx * Update AlertRuleForm.tsx * Update AlertTypeStep.tsx * Update AnnotationsField.tsx * Update ConditionField.tsx * Update ConditionsStep.tsx * Update GroupAndNamespaceFields.tsx * Update LabelsField.tsx * Update QueryStep.tsx * Update RowOptionsForm.tsx * Update SaveDashboardAsForm.tsx * Update NewDashboardsFolder.tsx * Update ImportDashboardForm.tsx * Update DashboardImportPage.tsx * Update NewOrgPage.tsx * Update OrgProfile.tsx * Update UserInviteForm.tsx * Update PlaylistForm.tsx * Update ChangePasswordForm.tsx * Update UserProfileEditForm.tsx * Update TeamSettings.tsx * Update SignupInvited.tsx * Expose setValue from the Form * Update typescript to v4.2.4 * Remove ref from field props * Fix tests * Revert TS update * Use exact version * Update latest batch of changes * Reduce the number of strict TS errors * Fix defaults * more type error fixes * Update CreateTeam * fix folder picker in rule form * fixes for hook form 7 * Update docs Co-authored-by: Domas <domasx2@gmail.com>
78 lines
2.7 KiB
TypeScript
78 lines
2.7 KiB
TypeScript
import React, { FC } from 'react';
|
|
import { SelectableValue } from '@grafana/data';
|
|
import { Button, Checkbox, Field, FormAPI, Input } from '@grafana/ui';
|
|
import { OptionElement } from './OptionElement';
|
|
import { NotificationChannelDTO, NotificationChannelOption, NotificationChannelSecureFields } from '../../../types';
|
|
|
|
interface Props extends Omit<FormAPI<NotificationChannelDTO>, 'formState' | 'getValues' | 'watch' | 'setValue'> {
|
|
selectedChannelOptions: NotificationChannelOption[];
|
|
currentFormValues: NotificationChannelDTO;
|
|
secureFields: NotificationChannelSecureFields;
|
|
|
|
onResetSecureField: (key: string) => void;
|
|
}
|
|
|
|
export const NotificationChannelOptions: FC<Props> = ({
|
|
control,
|
|
currentFormValues,
|
|
errors,
|
|
selectedChannelOptions,
|
|
register,
|
|
onResetSecureField,
|
|
secureFields,
|
|
}) => {
|
|
return (
|
|
<>
|
|
{selectedChannelOptions.map((option: NotificationChannelOption, index: number) => {
|
|
const key = `${option.label}-${index}`;
|
|
// Some options can be dependent on other options, this determines what is selected in the dependency options
|
|
// I think this needs more thought.
|
|
const selectedOptionValue =
|
|
currentFormValues[`settings.${option.showWhen.field}`] &&
|
|
(currentFormValues[`settings.${option.showWhen.field}`] as SelectableValue<string>).value;
|
|
|
|
if (option.showWhen.field && selectedOptionValue !== option.showWhen.is) {
|
|
return null;
|
|
}
|
|
|
|
if (option.element === 'checkbox') {
|
|
return (
|
|
<Field key={key}>
|
|
<Checkbox
|
|
{...register(
|
|
option.secure ? `secureSettings.${option.propertyName}` : `settings.${option.propertyName}`
|
|
)}
|
|
label={option.label}
|
|
description={option.description}
|
|
/>
|
|
</Field>
|
|
);
|
|
}
|
|
return (
|
|
<Field
|
|
key={key}
|
|
label={option.label}
|
|
description={option.description}
|
|
invalid={errors.settings && !!errors.settings[option.propertyName]}
|
|
error={errors.settings && errors.settings[option.propertyName]?.message}
|
|
>
|
|
{secureFields && secureFields[option.propertyName] ? (
|
|
<Input
|
|
readOnly={true}
|
|
value="Configured"
|
|
suffix={
|
|
<Button onClick={() => onResetSecureField(option.propertyName)} fill="text" type="button" size="sm">
|
|
Clear
|
|
</Button>
|
|
}
|
|
/>
|
|
) : (
|
|
<OptionElement option={option} register={register} control={control} />
|
|
)}
|
|
</Field>
|
|
);
|
|
})}
|
|
</>
|
|
);
|
|
};
|