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}
|
className={styles.formInput}
|
||||||
id={evaluateEveryId}
|
id={evaluateEveryId}
|
||||||
placeholder={DEFAULT_GROUP_EVALUATION_INTERVAL}
|
placeholder={DEFAULT_GROUP_EVALUATION_INTERVAL}
|
||||||
{...register('evaluateEvery', evaluateEveryValidationOptions(groupRules))}
|
{...register(
|
||||||
|
'evaluateEvery',
|
||||||
|
evaluateEveryValidationOptions<{ group: string; evaluateEvery: string }>(groupRules)
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
<Stack direction="row" alignItems="flex-end">
|
<Stack direction="row" alignItems="flex-end">
|
||||||
<EvaluationGroupQuickPick currentInterval={evaluationInterval} onSelect={setEvaluationInterval} />
|
<EvaluationGroupQuickPick currentInterval={evaluationInterval} onSelect={setEvaluationInterval} />
|
||||||
|
@ -25,12 +25,12 @@ import { RuleEditorSection } from './RuleEditorSection';
|
|||||||
|
|
||||||
export const MIN_TIME_RANGE_STEP_S = 10; // 10 seconds
|
export const MIN_TIME_RANGE_STEP_S = 10; // 10 seconds
|
||||||
|
|
||||||
const forValidationOptions = (evaluateEvery: string): RegisterOptions => ({
|
const forValidationOptions = (evaluateEvery: string): RegisterOptions<{ evaluateFor: string }> => ({
|
||||||
required: {
|
required: {
|
||||||
value: true,
|
value: true,
|
||||||
message: 'Required.',
|
message: 'Required.',
|
||||||
},
|
},
|
||||||
validate: (value: string) => {
|
validate: (value) => {
|
||||||
// parsePrometheusDuration does not allow 0 but does allow 0s
|
// parsePrometheusDuration does not allow 0 but does allow 0s
|
||||||
if (value === '0') {
|
if (value === '0') {
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import { compact } from 'lodash';
|
import { compact } from 'lodash';
|
||||||
import { useMemo } from 'react';
|
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 { GrafanaTheme2 } from '@grafana/data';
|
||||||
import { Alert, Badge, Button, Field, Input, Label, LinkButton, Modal, Stack, useStyles2 } from '@grafana/ui';
|
import { Alert, Badge, Button, Field, Input, Label, LinkButton, Modal, Stack, useStyles2 } from '@grafana/ui';
|
||||||
@ -135,7 +135,7 @@ interface FormValues {
|
|||||||
groupInterval: string;
|
groupInterval: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const evaluateEveryValidationOptions = (rules: RulerRuleDTO[]): RegisterOptions => ({
|
export const evaluateEveryValidationOptions = <T extends FieldValues>(rules: RulerRuleDTO[]): RegisterOptions<T> => ({
|
||||||
required: {
|
required: {
|
||||||
value: true,
|
value: true,
|
||||||
message: 'Required.',
|
message: 'Required.',
|
||||||
|
Loading…
Reference in New Issue
Block a user