Repository navigation
feat: url upload - #7928
feat: url upload#7928
Conversation
| </el-button> | ||
| </div> | ||
| </el-popover> | ||
| </template> |
There was a problem hiding this comment.
Overall the component is structurally fine, but there are a few important risks and some minor improvements:
1. Pinia store destructuring can break reactivity
If useMessageInputStore() is a Pinia store, direct destructuring of state/getters loses reactivity:
const { canUpload, uploadEnabled, urlUploading, urlUploadTypes, disabled, streamLoading } =
useMessageInputStore()This is especially suspicious because the code later uses urlUploadTypes.value, disabled.value, etc. Use storeToRefs for state/getters and keep actions from the store itself:
import { storeToRefs } from 'pinia'
const store = useMessageInputStore()
const {
canUpload,
uploadEnabled,
urlUploading,
urlUploadTypes,
disabled,
streamLoading,
} = storeToRefs(store)
const { addUrls } = storeIf this is not a Pinia store but a custom composable returning refs, then ignore this point.
2. confirm() depends on addUrls return semantics
if (urls.value.length && (await addUrls(urls.value, selectedType.value))) visible.value = falseIf addUrls returns void/undefined on success, the popover will never close. Also, if addUrls rejects, the error is unhandled. Make the success contract explicit:
async function confirm() {
if (!urls.value.length || urlUploading.value) return
try {
const success = await addUrls(urls.value, selectedType.value)
if (success) visible.value = false
} catch (error) {
// Keep the popover open; show/handle the error via store/message
}
}If addUrls does not return a boolean, close the popover after a successful await instead.
3. Close the popover when canUpload becomes false
Currently only disabled and streamLoading close the popover:
watch([disabled, streamLoading], () => {
if (disabled.value || streamLoading.value) visible.value = false
})If canUpload becomes false while the popover is open, it can remain open. Include it:
watch(
[canUpload, disabled, streamLoading],
([can, isDisabled, loading]) => {
if (!can || isDisabled || loading) visible.value = false
},
{ immediate: true },
)4. Hard-coded selectedType may be invalid
const selectedType = ref<...>('document_list')If 'document_list' is not present in urlUploadTypes, this can cause a type/value mismatch. Prefer initializing from the first available option, or make selectedType possibly undefined and disable submit until it is set. Also, when urlUploadTypes becomes empty, the old selected value remains. The submit button is disabled, but the select may show a stale value.
5. Consider deduplicating and validating URLs
urls currently allows duplicate addresses. You may want:
const urls = computed(() =>
[...new Set(
addresses.value
.split(/\r?\n|\r/)
.map((address) => address.trim())
.filter(Boolean),
)],
)Also consider basic client-side URL validation for better UX, but do not rely on it for security. If the backend fetches these URLs, enforce server-side URL validation and SSRF protection.
6. cancel is still enabled during urlUploading
The cancel button can close the popover while an upload is in progress. If that is not desired, disable it while urlUploading is true, or clearly allow the upload to continue in the background.
7. Icon-only button is missing an accessible label
<el-button text :disabled="!canUpload">
<MkIcon name="icon_attachment_outlined" :size="18" ... />
</el-button>Add aria-label and/or a tooltip:
<el-button text :disabled="!canUpload" aria-label="Open URL/local upload">8. Verify custom Tailwind classes
flex-between, w-15!, text-N900!, and my-4! look like custom utilities or Tailwind-version-specific important syntax. In default Tailwind, w-15 is not a standard spacing class. Verify these classes are defined/configured. Otherwise use standard utilities such as flex items-center justify-between, w-[15rem], etc.
9. Possible double padding in the popover
Element Plus popover content may already have default padding in some versions. The inner <div class="p-4"> can cause extra spacing. Verify visually; if so, remove p-4 or customize the popover padding.
10. localUpload button safety
The local upload button is disabled by urlUploading || !canUpload, but not explicitly by disabled or streamLoading. If canUpload does not already include those states, add them:
:disabled="urlUploading || !canUpload || disabled || streamLoading"11. Minor: @after-leave only resets addresses
If you want a full reset, also reset selectedType to the first available type. If preserving the last selected type is intentional, this is fine.
12. Verify MkIcon registration
Ensure MkIcon is globally registered or imported. Otherwise the template will fail at runtime.
feat: url upload
feat: url upload