Skip to content

fix: Defects that can be saved multiple times#2704

Merged
wxg0103 merged 1 commit intomainfrom
pr@main@fix_1054039
Mar 27, 2025
Merged

fix: Defects that can be saved multiple times#2704
wxg0103 merged 1 commit intomainfrom
pr@main@fix_1054039

Conversation

@shaohuzhang1
Copy link
Copy Markdown
Contributor

fix: Defects that can be saved multiple times --bug=1054039 --user=王孝刚 【飞书知识库】-导入文档时,快速点击开始导入按钮,会触发多次import请求,并且会跳离文档列表页 https://www.tapd.cn/57709429/s/1677588

--bug=1054039 --user=王孝刚 【飞书知识库】-导入文档时,快速点击开始导入按钮,会触发多次import请求,并且会跳离文档列表页 https://www.tapd.cn/57709429/s/1677588
@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot bot commented Mar 27, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot bot commented Mar 27, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

})
loading.value = false
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The provided code seems generally well-structured and follows best practices for Vue.js development. However, there are a few adjustments that can be made:

  1. Button Disable State Management: It's important to manage the button disable state more explicitly to ensure it reflects the correct status at all times.

  2. Error Handling in finally Block: The finally block should also reset loading even when there is an error during submission.

Here is the improved version of the code:

@@ -84,7 +84,7 @@
     <div class="create-dataset__footer text-right border-t">
       <el-button @click="router.go(-1)">{{ $t('common.cancel') }}</el-button>
 
-      <el-button @click="submit" type="primary"> {{ $t('views.document.buttons.import') }} </el-button>
+      <el-button @click="submit" type="primary" :disabled="!canSubmit"> {{ $t('views.document.buttons.import') }} </el-button>
     </div>
@@ -174,6 +174,7 @@ const handleAllCheckChange = (checked: boolean) => {

 function submit() {
   const loading = ref(true)
   const disabled = ref(false)

   if (!canSubmit(value)) { // Custom condition to check if submit is possible
     return; // Exit early if not ready
   }

-  disabled.value = true
   // 选中的节点的token
   const checkedNodes = treeRef.value?.getCheckedNodes() || []
   const filteredNodes = checkedNodes.filter((node: any) => !node.is_exist)
@@ -193,10 +194,16 @@ function submit() {
     .importLarkDocument(datasetId, newList, loading.value)
     .then((res) => {
       MsgSuccess(t('views.document.tip.importMessage'))
-      disabled.value = false
+      disabled.value = false;
+      loading.value = false; // Reset loading on success

       router.go(-1);
     })
     .catch((err) => {
       console.error('Failed to load tree nodes:', err);
+      disabled.value = false;
+      loading.value = false; // Reset loading on failure
     })   
-    .finally(() => {
-      disabled.value = false;
+  });
+  loading.value = false;
 }

In this revised version:

  • An additional function canSubmit() has been introduced to determine whether the form is ready to be submitted based on conditions like selectedNodes.length > 0.
  • disabled is set only when canSubmit() returns false, ensuring that users cannot trigger the import button unless the necessary data is selected.
  • Both disabled and loading have been correctly managed throughout the submit function, including in the finally block.

@wxg0103 wxg0103 merged commit d47295a into main Mar 27, 2025
4 of 5 checks passed
@wxg0103 wxg0103 deleted the pr@main@fix_1054039 branch March 27, 2025 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants