From 92fd57d002ba6b89ac202ffeae23b60dddddbc3f Mon Sep 17 00:00:00 2001 From: Nath Tumlin Date: Fri, 28 Feb 2025 12:20:59 -0300 Subject: [PATCH] Disable create and clone buttons while waiting for network response. (#423) I've accidentally created a backfill multiple times thinking I didn't click the create button and pressing it multiple times as a result. This disables the button while the request is sending preventing that. --- .../app/src/containers/CloneFormContainer.tsx | 60 +++++++------- .../src/containers/CreateFormContainer.tsx | 79 +++++++++++-------- 2 files changed, 77 insertions(+), 62 deletions(-) diff --git a/service/web/tabs/app/src/containers/CloneFormContainer.tsx b/service/web/tabs/app/src/containers/CloneFormContainer.tsx index 1ee5ae7ac..c6ea31df9 100644 --- a/service/web/tabs/app/src/containers/CloneFormContainer.tsx +++ b/service/web/tabs/app/src/containers/CloneFormContainer.tsx @@ -33,6 +33,7 @@ import { LayoutContainer } from "../containers" interface CloneFormState { loading: boolean errorText?: string + cloneButtonDisabled: boolean statusResponse: any @@ -61,6 +62,7 @@ class CloneFormContainer extends React.Component< this.setState({ loading: false, errorText: null, + cloneButtonDisabled: false, statusResponse: null, @@ -131,6 +133,35 @@ class CloneFormContainer extends React.Component< }) } + async handleClick() { + this.setState({ cloneButtonDisabled: true }) + try { + const response = await Axios.post(`/backfills/${this.id}/clone`, { + dry_run: this.state.dry_run, + scan_size: this.state.scan_size, + batch_size: this.state.batch_size, + num_threads: this.state.num_threads, + range_clone_type: this.state.range_clone_type, + pkey_range_start: this.nullIfEmpty(this.state.pkey_range_start), + pkey_range_end: this.nullIfEmpty(this.state.pkey_range_end), + backoff_schedule: this.nullIfEmpty(this.state.backoff_schedule), + extra_sleep_ms: this.state.extra_sleep_ms, + parameter_map: this.state.parameters + }) + let id = response.data.id + let history = (this.props as any).history + history.push(`/app/backfills/${id}`) + } catch (error) { + console.log(error) + this.setState({ + loading: false, + errorText: error.response.data + }) + } finally { + this.setState({ cloneButtonDisabled: false }) + } + } + render() { if (!this.state || !this.state.backfills) { return ( @@ -320,34 +351,7 @@ class CloneFormContainer extends React.Component< )}