mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboard scenes: debounce name validation when saving dashboards (#83580)
* Dashboard scenes: debounce name validation when saving dashboards * add newline
This commit is contained in:
parent
e930b49db3
commit
c9ac6dd3e7
@ -1,3 +1,4 @@
|
|||||||
|
import debounce from 'debounce-promise';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { UseFormSetValue, useForm } from 'react-hook-form';
|
import { UseFormSetValue, useForm } from 'react-hook-form';
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ export interface Props {
|
|||||||
export function SaveDashboardAsForm({ dashboard, drawer, changeInfo }: Props) {
|
export function SaveDashboardAsForm({ dashboard, drawer, changeInfo }: Props) {
|
||||||
const { changedSaveModel } = changeInfo;
|
const { changedSaveModel } = changeInfo;
|
||||||
|
|
||||||
const { register, handleSubmit, setValue, formState, getValues, watch } = useForm<SaveDashboardAsFormDTO>({
|
const { register, handleSubmit, setValue, formState, getValues, watch, trigger } = useForm<SaveDashboardAsFormDTO>({
|
||||||
mode: 'onBlur',
|
mode: 'onBlur',
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
title: changeInfo.isNew ? changedSaveModel.title! : `${changedSaveModel.title} Copy`,
|
title: changeInfo.isNew ? changedSaveModel.title! : `${changedSaveModel.title} Copy`,
|
||||||
@ -98,6 +99,9 @@ export function SaveDashboardAsForm({ dashboard, drawer, changeInfo }: Props) {
|
|||||||
<Input
|
<Input
|
||||||
{...register('title', { required: 'Required', validate: validateDashboardName })}
|
{...register('title', { required: 'Required', validate: validateDashboardName })}
|
||||||
aria-label="Save dashboard title field"
|
aria-label="Save dashboard title field"
|
||||||
|
onChange={debounce(async () => {
|
||||||
|
trigger('title');
|
||||||
|
}, 400)}
|
||||||
autoFocus
|
autoFocus
|
||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
|
Loading…
Reference in New Issue
Block a user