mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Add types to react hook form usage register method (#91566)
This commit is contained in:
parent
0c4e02ba14
commit
b4a23e097a
@ -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…
Reference in New Issue
Block a user