fix: Defects that can be saved multiple times#2704
Conversation
--bug=1054039 --user=王孝刚 【飞书知识库】-导入文档时,快速点击开始导入按钮,会触发多次import请求,并且会跳离文档列表页 https://www.tapd.cn/57709429/s/1677588
|
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. DetailsInstructions 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. |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| }) | ||
| loading.value = false | ||
| } | ||
|
|
There was a problem hiding this comment.
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:
-
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.
-
Error Handling in finally Block: The
finallyblock should also resetloadingeven 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 likeselectedNodes.length > 0. disabledis set only whencanSubmit()returns false, ensuring that users cannot trigger the import button unless the necessary data is selected.- Both
disabledandloadinghave been correctly managed throughout thesubmitfunction, including in the finally block.
fix: Defects that can be saved multiple times --bug=1054039 --user=王孝刚 【飞书知识库】-导入文档时,快速点击开始导入按钮,会触发多次import请求,并且会跳离文档列表页 https://www.tapd.cn/57709429/s/1677588