Alerting: Add types to react hook form usage register method (#91566)

pull/91482/head
Tom Ratcliffe 10 months ago committed by GitHub
parent 0c4e02ba14
commit b4a23e097a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      public/app/features/alerting/unified/components/rule-editor/FolderAndGroup.tsx
  2. 4
      public/app/features/alerting/unified/components/rule-editor/GrafanaEvaluationBehavior.tsx
  3. 4
      public/app/features/alerting/unified/components/rules/EditRuleGroupModal.tsx

@ -431,7 +431,10 @@ function EvaluationGroupCreationModal({
className={styles.formInput}
id={evaluateEveryId}
placeholder={DEFAULT_GROUP_EVALUATION_INTERVAL}
{...register('evaluateEvery', evaluateEveryValidationOptions(groupRules))}
{...register(
'evaluateEvery',
evaluateEveryValidationOptions<{ group: string; evaluateEvery: string }>(groupRules)
)}
/>
<Stack direction="row" alignItems="flex-end">
<EvaluationGroupQuickPick currentInterval={evaluationInterval} onSelect={setEvaluationInterval} />

@ -25,12 +25,12 @@ import { RuleEditorSection } from './RuleEditorSection';
export const MIN_TIME_RANGE_STEP_S = 10; // 10 seconds
const forValidationOptions = (evaluateEvery: string): RegisterOptions => ({
const forValidationOptions = (evaluateEvery: string): RegisterOptions<{ evaluateFor: string }> => ({
required: {
value: true,
message: 'Required.',
},
validate: (value: string) => {
validate: (value) => {
// parsePrometheusDuration does not allow 0 but does allow 0s
if (value === '0') {
return true;

@ -1,7 +1,7 @@
import { css } from '@emotion/css';
import { compact } from 'lodash';
import { useMemo } from 'react';
import { FormProvider, RegisterOptions, useForm, useFormContext } from 'react-hook-form';
import { FieldValues, FormProvider, RegisterOptions, useForm, useFormContext } from 'react-hook-form';
import { GrafanaTheme2 } from '@grafana/data';
import { Alert, Badge, Button, Field, Input, Label, LinkButton, Modal, Stack, useStyles2 } from '@grafana/ui';
@ -135,7 +135,7 @@ interface FormValues {
groupInterval: string;
}
export const evaluateEveryValidationOptions = (rules: RulerRuleDTO[]): RegisterOptions => ({
export const evaluateEveryValidationOptions = <T extends FieldValues>(rules: RulerRuleDTO[]): RegisterOptions<T> => ({
required: {
value: true,
message: 'Required.',

Loading…
Cancel
Save