Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Debounce annotation validation #71884

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, { Component, Fragment, FC, ReactNode } from 'react';
import useObservable from 'react-use/lib/useObservable';
import * as Rx from 'rxjs';
import { cloneDeep } from 'lodash';

import { debounce } from 'lodash';
import {
EuiButton,
EuiButtonEmpty,
Expand Down Expand Up @@ -177,6 +177,8 @@ class AnnotationFlyoutUI extends Component<CommonProps & Props> {
return errors;
};

public debouncedValidateAnnotationText = debounce(this.validateAnnotationText, 300);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless this is called by something externally, it should probably be private


public saveOrUpdateAnnotation = () => {
const { annotation: originalAnnotation, chartDetails, detectorIndex } = this.props;
if (originalAnnotation === null) {
Expand Down Expand Up @@ -273,8 +275,8 @@ class AnnotationFlyoutUI extends Component<CommonProps & Props> {

// Check the length of the text is within the max length limit,
// and warn if the length is approaching the limit.
const validationErrors = this.validateAnnotationText();
const isInvalid = validationErrors.length > 0;
const validationErrors = this.debouncedValidateAnnotationText();
const isInvalid = (validationErrors && validationErrors.length > 0) || false;
const lengthRatioToShowWarning = 0.95;
let helpText = null;
if (
Expand Down