-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: Support uploading files by copying, pasting, dragging and dropping #2939
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
Conversation
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. 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. |
[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.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
} | ||
uploadFile(elFile, [elFile]) | ||
}) | ||
} | ||
// 语音录制任务id | ||
const intervalId = ref<any | null>(null) | ||
// 语音录制开始秒数 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code you provided has several areas that could be improved or checked for irregularities:
-
Variable Naming and Clarity: The variable names like
localLoading
,imageExtensions
,documentExtensions
, etc., are descriptive but some might be more concise or informative. -
Event Handlers:
- Ensure all events have appropriate checks to prevent unauthorized operations, especially when file uploads are disabled (
applicationDetails.file_upload_enable
).
- Ensure all events have appropriate checks to prevent unauthorized operations, especially when file uploads are disabled (
-
Styling and Flexibility:
- Check if the styles used (like
.flex.align-center
) are compatible with your design requirements.
- Check if the styles used (like
-
Performance Considerations:
- For handling pasting, consider optimizing performance by preventing unecessary computations inside loops and using asynchronous functions where possible.
-
Error Handling:
- Implement error handling in both paste and drop event handlers to manage cases where files fail to upload properly.
-
Refactoring Upload Logic:
- Combine the logic for uploading files and processing them into a reusable function to reduce redundancy.
Here's an updated version of the key sections with some suggestions:
// Simplify extension arrays
<template>
<!-- Existing template content -->
</template>
<script lang="ts" setup>
import { ref, computed } from 'vue';
const props = defineProps({
// existing props
})
const localLoading = computed(() => ({
show: false,
text: '',
}))
const isFileUploadEnabled = computed(() => {
return !!props.applicationDetails.file_upload_enable;
});
// Other methods
<script>
/**
* Updated method to handle drag and drop
*/
const handleDrop = async (e: DragEvent): Promise<void> => {
e.preventDefault();
let transferredFiles: File[] = [];
try {
const dataTransfer = e.dataTransfer || window.e; // Fix for web components
if (!dataTransfer) throw new Error('No data transfer available.');
transferredFiles = [...(Array.prototype.filter.call(dataTransfer.items, item => !item.webkit kind))];
await handleFileList(transferredFiles);
} catch (error) {
console.error(error)
}
}
/**
* Updates fileList based on input type
*
* @param files list of files to process
*/
async function updateFileList(files: any[]): Promise<void> {
if(!files.length) return;
const elFiles = files.map(file => ({
uid: Date.now(),
name: file.name,
size: file.size,
raw: file.raw ?? file,
status: "ready",
percentage: 0
}));
await handleFileList(elFiles); // Continue with original implementation
}
</script>
Summary Changes:
- Removed redundant code blocks.
- Improved naming conventions for clarity.
- Added comments to explain specific functionalities.
- Ensured better practices for file manipulation.
- Enhanced readability by organizing similar tasks together.
Regularly review such changes after implementation to ensure they work as anticipated without causing unexpected bugs.
What this PR does / why we need it?
Summary of your change
Please indicate you've done the following: